llex.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. ** $Id: llex.h,v 1.18 2000/02/08 16:34:31 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. AND = FIRST_RESERVED,
  20. DO, ELSE, ELSEIF, END, FUNCTION, IF, LOCAL, NIL, NOT, OR,
  21. REPEAT, RETURN, THEN, UNTIL, WHILE,
  22. /* other terminal symbols */
  23. NAME, CONC, DOTS, EQ, GE, LE, NE, NUMBER, STRING, EOS
  24. };
  25. /* number of reserved words */
  26. #define NUM_RESERVED ((int)(WHILE-FIRST_RESERVED+1))
  27. #ifndef MAX_IFS
  28. #define MAX_IFS 5 /* arbitrary limit */
  29. #endif
  30. /* `ifState' keeps the state of each nested $if the lexical is dealing with. */
  31. struct ifState {
  32. int elsepart; /* true if it's in the $else part */
  33. int condition; /* true if $if condition is true */
  34. int skip; /* true if part must be skipped */
  35. };
  36. typedef struct LexState {
  37. int current; /* look ahead character */
  38. int token; /* look ahead token */
  39. struct FuncState *fs; /* `FuncState' is private to the parser */
  40. struct lua_State *L;
  41. union {
  42. real r;
  43. TaggedString *ts;
  44. } seminfo; /* semantics information */
  45. struct zio *z; /* input stream */
  46. int linenumber; /* input line counter */
  47. int iflevel; /* level of nested $if's (for lexical analysis) */
  48. struct ifState ifstate[MAX_IFS];
  49. } LexState;
  50. void luaX_init (lua_State *L);
  51. void luaX_setinput (lua_State *L, LexState *LS, ZIO *z);
  52. int luaX_lex (LexState *LS);
  53. void luaX_syntaxerror (LexState *ls, const char *s, const char *token);
  54. void luaX_error (LexState *ls, const char *s, int token);
  55. void luaX_token2str (int token, char *s);
  56. #endif