llex.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. ** $Id: llex.h,v 1.13 1999/07/22 19:29:42 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. union {
  38. real r;
  39. TaggedString *ts;
  40. } seminfo; /* semantics information */
  41. struct zio *lex_z; /* input stream */
  42. int linenumber; /* input line counter */
  43. int iflevel; /* level of nested $if's (for lexical analysis) */
  44. struct ifState ifstate[MAX_IFS];
  45. } LexState;
  46. void luaX_init (void);
  47. void luaX_setinput (LexState *LS, ZIO *z);
  48. int luaX_lex (LexState *LS);
  49. void luaX_syntaxerror (LexState *ls, const char *s, const char *token);
  50. void luaX_error (LexState *ls, const char *s);
  51. void luaX_token2str (int token, char *s);
  52. #endif