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