llex.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. ** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 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. /* maximum length of a reserved word */
  12. #define TOKEN_LEN (sizeof("function")/sizeof(char))
  13. /*
  14. * WARNING: if you change the order of this enumeration,
  15. * grep "ORDER RESERVED"
  16. */
  17. enum RESERVED
  18. {
  19. /* terminal symbols denoted by reserved words */
  20. TK_AND = FIRST_RESERVED, TK_BREAK,
  21. TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,
  22. TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
  23. TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
  24. /* other terminal symbols */
  25. TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER,
  26. TK_NAME, TK_STRING, TK_EOS
  27. };
  28. /* number of reserved words */
  29. #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1))
  30. /* array with token `names' */
  31. LUAI_DATA const char *const luaX_tokens [];
  32. typedef union
  33. {
  34. lua_Number r;
  35. TString *ts;
  36. } SemInfo; /* semantics information */
  37. typedef struct Token
  38. {
  39. int token;
  40. SemInfo seminfo;
  41. } Token;
  42. typedef struct LexState
  43. {
  44. int current; /* current character (charint) */
  45. int linenumber; /* input line counter */
  46. int lastline; /* line of last token `consumed' */
  47. Token t; /* current token */
  48. Token lookahead; /* look ahead token */
  49. struct FuncState *fs; /* `FuncState' is private to the parser */
  50. struct lua_State *L;
  51. ZIO *z; /* input stream */
  52. Mbuffer *buff; /* buffer for tokens */
  53. TString *source; /* current source 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);
  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 void luaX_lookahead(LexState *ls);
  62. LUAI_FUNC void luaX_lexerror(LexState *ls, const char *msg, int token);
  63. LUAI_FUNC void luaX_syntaxerror(LexState *ls, const char *s);
  64. LUAI_FUNC const char *luaX_token2str(LexState *ls, int token);
  65. #endif