llex.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. ** $Id: llex.h,v 1.17 2000/01/25 18:44:21 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 260
  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. #define NUM_RESERVED (WHILE-FIRST_RESERVED+1) /* number of reserved words */
  26. #ifndef MAX_IFS
  27. #define MAX_IFS 5 /* arbitrary limit */
  28. #endif
  29. /* `ifState' keeps the state of each nested $if the lexical is dealing with. */
  30. struct ifState {
  31. int elsepart; /* true if it's in the $else part */
  32. int condition; /* true if $if condition is true */
  33. int skip; /* true if part must be skipped */
  34. };
  35. typedef struct LexState {
  36. int current; /* look ahead character */
  37. int token; /* look ahead token */
  38. struct FuncState *fs; /* `FuncState' is private for the parser */
  39. struct lua_State *L;
  40. union {
  41. real r;
  42. TaggedString *ts;
  43. } seminfo; /* semantics information */
  44. struct zio *lex_z; /* input stream */
  45. int linenumber; /* input line counter */
  46. int iflevel; /* level of nested $if's (for lexical analysis) */
  47. struct ifState ifstate[MAX_IFS];
  48. } LexState;
  49. void luaX_init (lua_State *L);
  50. void luaX_setinput (lua_State *L, LexState *LS, ZIO *z);
  51. int luaX_lex (LexState *LS);
  52. void luaX_syntaxerror (LexState *ls, const char *s, const char *token);
  53. void luaX_error (LexState *ls, const char *s, int token);
  54. void luaX_token2str (int token, char *s);
  55. #endif