llex.h 2.5 KB

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