rlm@1: /* rlm@1: ** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $ rlm@1: ** Lexical Analyzer rlm@1: ** See Copyright Notice in lua.h rlm@1: */ rlm@1: rlm@1: #ifndef llex_h rlm@1: #define llex_h rlm@1: rlm@1: #include "lobject.h" rlm@1: #include "lzio.h" rlm@1: rlm@1: rlm@1: #define FIRST_RESERVED 257 rlm@1: rlm@1: /* maximum length of a reserved word */ rlm@1: #define TOKEN_LEN (sizeof("function")/sizeof(char)) rlm@1: rlm@1: rlm@1: /* rlm@1: * WARNING: if you change the order of this enumeration, rlm@1: * grep "ORDER RESERVED" rlm@1: */ rlm@1: enum RESERVED { rlm@1: /* terminal symbols denoted by reserved words */ rlm@1: TK_AND = FIRST_RESERVED, TK_BREAK, rlm@1: TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, rlm@1: TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, rlm@1: TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, rlm@1: /* other terminal symbols */ rlm@1: TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER, rlm@1: TK_NAME, TK_STRING, TK_EOS rlm@1: }; rlm@1: rlm@1: /* number of reserved words */ rlm@1: #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) rlm@1: rlm@1: rlm@1: /* array with token `names' */ rlm@1: LUAI_DATA const char *const luaX_tokens []; rlm@1: rlm@1: rlm@1: typedef union { rlm@1: lua_Number r; rlm@1: TString *ts; rlm@1: } SemInfo; /* semantics information */ rlm@1: rlm@1: rlm@1: typedef struct Token { rlm@1: int token; rlm@1: SemInfo seminfo; rlm@1: } Token; rlm@1: rlm@1: rlm@1: typedef struct LexState { rlm@1: int current; /* current character (charint) */ rlm@1: int linenumber; /* input line counter */ rlm@1: int lastline; /* line of last token `consumed' */ rlm@1: Token t; /* current token */ rlm@1: Token lookahead; /* look ahead token */ rlm@1: struct FuncState *fs; /* `FuncState' is private to the parser */ rlm@1: struct lua_State *L; rlm@1: ZIO *z; /* input stream */ rlm@1: Mbuffer *buff; /* buffer for tokens */ rlm@1: TString *source; /* current source name */ rlm@1: char decpoint; /* locale decimal point */ rlm@1: } LexState; rlm@1: rlm@1: rlm@1: LUAI_FUNC void luaX_init (lua_State *L); rlm@1: LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, rlm@1: TString *source); rlm@1: LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); rlm@1: LUAI_FUNC void luaX_next (LexState *ls); rlm@1: LUAI_FUNC void luaX_lookahead (LexState *ls); rlm@1: LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token); rlm@1: LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s); rlm@1: LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); rlm@1: rlm@1: rlm@1: #endif