1 /* 2 ** $Id$ 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 14 #define FIRST_RESERVED 257 15 16 /* maximum length of a reserved word (+1 for final 0) */ 17 #define TOKEN_LEN 15 18 19 20 /* 21 * WARNING: if you change the order of this enumeration, 22 * grep "ORDER RESERVED" 23 */ 24 enum RESERVED { 25 /* terminal symbols denoted by reserved words */ 26 TK_AND = FIRST_RESERVED, TK_BREAK, 27 TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FOR, TK_FUNCTION, TK_IF, TK_LOCAL, 28 TK_NIL, TK_NOT, TK_OR, TK_REPEAT, TK_RETURN, TK_THEN, TK_UNTIL, TK_WHILE, 29 /* other terminal symbols */ 30 TK_NAME, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER, 31 TK_STRING, TK_EOS 32 }; 33 34 /* number of reserved words */ 35 #define NUM_RESERVED ((int)(TK_WHILE-FIRST_RESERVED+1)) 36 37 38 typedef union { 39 Number r; 40 TString *ts; 41 } SemInfo; /* semantics information */ 42 43 44 typedef struct Token { 45 int token; 46 SemInfo seminfo; 47 } Token; 48 49 50 typedef struct LexState { 51 int current; /* current character */ 52 Token t; /* current token */ 53 Token lookahead; /* look ahead token */ 54 struct FuncState *fs; /* `FuncState' is private to the parser */ 55 struct lua_State *L; 56 struct zio *z; /* input stream */ 57 int linenumber; /* input line counter */ 58 int lastline; /* line of last token `consumed' */ 59 TString *source; /* current source name */ 60 } LexState; 61 62 63 void luaX_init (lua_State *L); 64 void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source); 65 int luaX_lex (LexState *LS, SemInfo *seminfo); 66 void luaX_checklimit (LexState *ls, int val, int limit, const char *msg); 67 void luaX_syntaxerror (LexState *ls, const char *s, const char *token); 68 void luaX_error (LexState *ls, const char *s, int token); 69 void luaX_token2str (int token, char *s); 70 71 72 #endif 73