llex.h 2.3 KB

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