llex.h 1.6 KB

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