llex.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. ** $Id: llex.h,v 1.36 2001/06/20 21:07:57 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 */
  12. #define TOKEN_LEN (sizeof(l_s("function"))/sizeof(l_char))
  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. TK_AND = FIRST_RESERVED, TK_BREAK,
  20. TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FOR, TK_FUNCTION, TK_GLOBAL, TK_IF,
  21. TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, TK_RETURN, TK_THEN,
  22. TK_UNTIL, TK_WHILE,
  23. /* other terminal symbols */
  24. TK_NAME, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER,
  25. TK_STRING, TK_EOS
  26. };
  27. /* number of reserved words */
  28. #define NUM_RESERVED ((int)(TK_WHILE-FIRST_RESERVED+1))
  29. typedef union {
  30. lua_Number r;
  31. TString *ts;
  32. } SemInfo; /* semantics information */
  33. typedef struct Token {
  34. int token;
  35. SemInfo seminfo;
  36. } Token;
  37. typedef struct LexState {
  38. l_charint current; /* current character */
  39. Token t; /* current token */
  40. Token lookahead; /* look ahead token */
  41. struct FuncState *fs; /* `FuncState' is private to the parser */
  42. struct lua_State *L;
  43. struct zio *z; /* input stream */
  44. int linenumber; /* input line counter */
  45. int lastline; /* line of last token `consumed' */
  46. TString *source; /* current source name */
  47. } LexState;
  48. void luaX_init (lua_State *L);
  49. void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source);
  50. int luaX_lex (LexState *LS, SemInfo *seminfo);
  51. void luaX_checklimit (LexState *ls, int val, int limit, const l_char *msg);
  52. void luaX_syntaxerror (LexState *ls, const l_char *s, const l_char *token);
  53. void luaX_error (LexState *ls, const l_char *s, int token);
  54. void luaX_token2str (int token, l_char *s);
  55. #endif