You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

79 regels
2.1 KiB

  1. /*
  2. ** $Id: llex.h,v 1.72 2011/11/30 12:43:51 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. /*
  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_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_DBCOLON, TK_EOS,
  23. TK_NUMBER, TK_NAME, TK_STRING
  24. };
  25. /* number of reserved words */
  26. #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1))
  27. typedef union {
  28. lua_Number r;
  29. TString *ts;
  30. } SemInfo; /* semantics information */
  31. typedef struct Token {
  32. int token;
  33. SemInfo seminfo;
  34. } Token;
  35. /* state of the lexer plus state of the parser when shared by all
  36. functions */
  37. typedef struct LexState {
  38. int current; /* current character (charint) */
  39. int linenumber; /* input line counter */
  40. int lastline; /* line of last token `consumed' */
  41. Token t; /* current token */
  42. Token lookahead; /* look ahead token */
  43. struct FuncState *fs; /* current function (parser) */
  44. struct lua_State *L;
  45. ZIO *z; /* input stream */
  46. Mbuffer *buff; /* buffer for tokens */
  47. struct Dyndata *dyd; /* dynamic structures used by the parser */
  48. TString *source; /* current source name */
  49. TString *envn; /* environment variable name */
  50. char decpoint; /* locale decimal point */
  51. } LexState;
  52. LUAI_FUNC void luaX_init (lua_State *L);
  53. LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z,
  54. TString *source, int firstchar);
  55. LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l);
  56. LUAI_FUNC void luaX_next (LexState *ls);
  57. LUAI_FUNC int luaX_lookahead (LexState *ls);
  58. LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s);
  59. LUAI_FUNC const char *luaX_token2str (LexState *ls, int token);
  60. #endif