llex.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. ** $Id: llex.h,v 1.23 2000/04/07 13:11:49 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. /* `ifState' keeps the state of each nested $if the lexical is dealing with. */
  29. struct ifState {
  30. int elsepart; /* true if it's in the $else part */
  31. int condition; /* true if $if condition is true */
  32. int skip; /* true if part must be skipped */
  33. };
  34. typedef struct LexState {
  35. int current; /* look ahead character */
  36. int token; /* look ahead token */
  37. struct FuncState *fs; /* `FuncState' is private to the parser */
  38. struct lua_State *L;
  39. union {
  40. Number r;
  41. TString *ts;
  42. } seminfo; /* semantics information */
  43. struct zio *z; /* input stream */
  44. int linenumber; /* input line counter */
  45. int iflevel; /* level of nested $if's (for lexical analysis) */
  46. struct ifState ifstate[MAX_IFS];
  47. } LexState;
  48. void luaX_init (lua_State *L);
  49. void luaX_setinput (lua_State *L, LexState *LS, ZIO *z);
  50. int luaX_lex (LexState *LS);
  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