llex.h 1.7 KB

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