-
Notifications
You must be signed in to change notification settings - Fork 0
/
yun_lex.h
66 lines (52 loc) · 1.42 KB
/
yun_lex.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* @file: yun_lex.h
* @brief: lexical analysis
* @date: Oct 2, 2011
* @author: pozen
*/
#ifndef __YUN_LEX_H_
#define __YUN_LEX_H_
#include <stddef.h>
#include <limits.h>
#define MAX_VALUE_LEN 2048
/* token types table */
enum RESERVED
{
TK_ERROR = 256, TK_AND, TK_BREAK, TK_CONTINUE, TK_DO,\
TK_ELIF, TK_ELSE, TK_FALSE, TK_FOR, TK_FUNCTION,\
TK_IF, TK_IN, TK_NIL, TK_NOT, TK_OR, TK_OD,\
TK_RETURN, TK_TRUE, TK_WHILE, Tk_CONST,\
/*TK_INT, TK_LONG, TK_LONGLONG, TK_UINT, TK_ULONG, TK_ULONGLONG, TK_SHORT, TK_USHORT,\
TK_FLOAT, TK_DOUBLE,*/TK_NUMBER, TK_CHAR, TK_STRING, \
TK_EQ, TK_GE, TK_LE, TK_NE, TK_ID, TK_EOF, TK_CONST_VALUE
};
typedef double yl_number;
typedef char yl_char;
#define reserved_value_type_test( tk ) ( tk >= TK_NUMBER && tk <= TK_STRING )
typedef void(*lex_error)( size_t lineno, const char* msg, ... );
typedef void(*lex_warning)( size_t lineno, const char* msg, ... );
typedef struct Token
{
int type;
int sub_type;
char* value;
}Token;
typedef struct LexToken
{
size_t line_num;
/*size_t current;*/
struct Token token;
struct LexToken* next;
struct LexToken* pre;
/*char* source;
//lex_error error;
//lex_warning warning;*/
}LexToken;
/* ORDER RESERVED */
//const Token key_tokens[21];
/* get token list */
LexToken* lex_get_token( const char* source );
/* destroy token list */
void lex_destroy_token( LexToken* tk );
yl_number str2number( const char* str );
#endif /* __YUN_LEX_H_ */