9
3

llex.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
  28. 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 lexer 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. } LexState;
  63. LUAI_FUNC void luaX_init (lua_State *L);
  64. LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z,
  65. TString *source, int firstchar);
  66. LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l);
  67. LUAI_FUNC void luaX_next (LexState *ls);
  68. LUAI_FUNC int luaX_lookahead (LexState *ls);
  69. LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s);
  70. LUAI_FUNC const char *luaX_token2str (LexState *ls, int token);
  71. #endif