2
0

llex.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. ** $Id: llex.h,v 1.30 2000/06/21 18:13:56 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 (+1 for final 0) */
  12. #define TOKEN_LEN 15
  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_FOR, TK_FUNCTION, TK_IF, TK_LOCAL,
  21. TK_NIL, TK_NOT, TK_OR, TK_REPEAT, TK_RETURN, TK_THEN, TK_UNTIL, TK_WHILE,
  22. /* other terminal symbols */
  23. TK_NAME, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER,
  24. TK_STRING, TK_EOS
  25. };
  26. /* number of reserved words */
  27. #define NUM_RESERVED ((int)(TK_WHILE-FIRST_RESERVED+1))
  28. typedef union {
  29. Number r;
  30. TString *ts;
  31. } SemInfo; /* semantics information */
  32. typedef struct Token {
  33. int token;
  34. SemInfo seminfo;
  35. } Token;
  36. typedef struct LexState {
  37. int current; /* current character */
  38. Token t; /* current token */
  39. Token lookahead; /* look ahead token */
  40. struct FuncState *fs; /* `FuncState' is private to the parser */
  41. struct lua_State *L;
  42. struct zio *z; /* input stream */
  43. int linenumber; /* input line counter */
  44. int lastline; /* line of last token `consumed' */
  45. TString *source; /* current source name */
  46. } LexState;
  47. void luaX_init (lua_State *L);
  48. void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source);
  49. int luaX_lex (LexState *LS, SemInfo *seminfo);
  50. void luaX_checklimit (LexState *ls, int val, int limit, const char *msg);
  51. void luaX_syntaxerror (LexState *ls, const char *s, const char *token);
  52. void luaX_error (LexState *ls, const char *s, int token);
  53. void luaX_token2str (int token, char *s);
  54. #endif