1 /*
2 ** $Id: llex.h,v 1.72.1.1 2013/04/12 18:48:47 roberto Exp $
3 ** Lexical Analyzer
4 ** See Copyright Notice in lua.h
5 */
6 
7 #ifndef llex_h
8 #define llex_h
9 
10 #include "lobject.h"
11 #include "lzio.h"
12 
13 #define FIRST_RESERVED 257
14 
15 /*
16 * WARNING: if you change the order of this enumeration,
17 * grep "ORDER RESERVED"
18 */
19 enum RESERVED
20 {
21 	/* terminal symbols denoted by reserved words */
22 	TK_AND = FIRST_RESERVED,
23 	TK_BREAK,
24 	TK_DO,
25 	TK_ELSE,
26 	TK_ELSEIF,
27 	TK_END,
28 	TK_FALSE,
29 	TK_FOR,
30 	TK_FUNCTION,
31 	TK_GOTO,
32 	TK_IF,
33 	TK_IN,
34 	TK_LOCAL,
35 	TK_NIL,
36 	TK_NOT,
37 	TK_OR,
38 	TK_REPEAT,
39 	TK_RETURN,
40 	TK_THEN,
41 	TK_TRUE,
42 	TK_UNTIL,
43 	TK_WHILE,
44 	/* other terminal symbols */
45 	TK_CONCAT,
46 	TK_DOTS,
47 	TK_EQ,
48 	TK_GE,
49 	TK_LE,
50 	TK_NE,
51 	TK_DBCOLON,
52 	TK_EOS,
53 	TK_NUMBER,
54 	TK_NAME,
55 	TK_STRING
56 };
57 
58 /* number of reserved words */
59 #define NUM_RESERVED (cast(int, TK_WHILE - FIRST_RESERVED + 1))
60 
61 typedef union {
62 	lua_Number r;
63 	TString *ts;
64 } SemInfo; /* semantics information */
65 
66 typedef struct Token
67 {
68 	int token;
69 	SemInfo seminfo;
70 } Token;
71 
72 /* state of the lexer plus state of the parser when shared by all
73    functions */
74 typedef struct LexState
75 {
76 	int current;          /* current character (charint) */
77 	int linenumber;       /* input line counter */
78 	int lastline;         /* line of last token `consumed' */
79 	Token t;              /* current token */
80 	Token lookahead;      /* look ahead token */
81 	struct FuncState *fs; /* current function (parser) */
82 	struct lua_State *L;
83 	ZIO *z;              /* input stream */
84 	Mbuffer *buff;       /* buffer for tokens */
85 	struct Dyndata *dyd; /* dynamic structures used by the parser */
86 	TString *source;     /* current source name */
87 	TString *envn;       /* environment variable name */
88 	char decpoint;       /* locale decimal point */
89 } LexState;
90 
91 LUAI_FUNC void luaX_init(lua_State *L);
92 LUAI_FUNC void luaX_setinput(lua_State *L, LexState *ls, ZIO *z,
93 							 TString *source, int firstchar);
94 LUAI_FUNC TString *luaX_newstring(LexState *ls, const char *str, size_t l);
95 LUAI_FUNC void luaX_next(LexState *ls);
96 LUAI_FUNC int luaX_lookahead(LexState *ls);
97 LUAI_FUNC l_noret luaX_syntaxerror(LexState *ls, const char *s);
98 LUAI_FUNC const char *luaX_token2str(LexState *ls, int token);
99 
100 #endif
101