llex.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. ** $Id: llex.h,v 1.45 2002/10/08 18:46:08 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. /* 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. /* terminal symbols denoted by reserved words */
  19. TK_AND = FIRST_RESERVED, TK_BREAK,
  20. TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,
  21. TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
  22. TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
  23. /* other terminal symbols */
  24. TK_NAME, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER,
  25. TK_STRING, TK_EOS
  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. TString *ts;
  32. } SemInfo; /* semantics information */
  33. typedef struct Token {
  34. int token;
  35. SemInfo seminfo;
  36. } Token;
  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; /* `FuncState' is private to the parser */
  44. struct lua_State *L;
  45. ZIO *z; /* input stream */
  46. Mbuffer *buff; /* buffer for tokens */
  47. TString *source; /* current source name */
  48. int nestlevel; /* level of nested non-terminals */
  49. } LexState;
  50. void luaX_init (lua_State *L);
  51. void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source);
  52. int luaX_lex (LexState *LS, SemInfo *seminfo);
  53. void luaX_checklimit (LexState *ls, int val, int limit, const char *msg);
  54. void luaX_syntaxerror (LexState *ls, const char *s);
  55. const char *luaX_token2str (LexState *ls, int token);
  56. #endif