llex.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. ** $Id: llex.h,v 1.29 2000/06/19 18:05:14 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 struct Token {
  29. int token;
  30. union {
  31. Number r;
  32. TString *ts;
  33. } seminfo; /* semantics information */
  34. } Token;
  35. typedef struct LexState {
  36. int current; /* current character */
  37. Token t; /* current token */
  38. Token lookahead; /* look ahead token */
  39. struct FuncState *fs; /* `FuncState' is private to the parser */
  40. struct lua_State *L;
  41. struct zio *z; /* input stream */
  42. int linenumber; /* input line counter */
  43. int lastline; /* line of last token `consumed' */
  44. TString *source; /* current source name */
  45. } LexState;
  46. void luaX_init (lua_State *L);
  47. void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source);
  48. int luaX_lex (LexState *LS);
  49. void luaX_checklimit (LexState *ls, int val, int limit, const char *msg);
  50. void luaX_syntaxerror (LexState *ls, const char *s, const char *token);
  51. void luaX_error (LexState *ls, const char *s, int token);
  52. void luaX_token2str (int token, char *s);
  53. #endif