llex.h 2.2 KB

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