Imported from ../lua-4.0.tar.gz.
[lua.git] / src / llex.h
blob3b379960865d7380a6c9f47720694ec9345c3434
1 /*
2 ** $Id: llex.h,v 1.31 2000/09/27 17:41:58 roberto Exp $
3 ** Lexical Analyzer
4 ** See Copyright Notice in lua.h
5 */
7 #ifndef llex_h
8 #define llex_h
10 #include "lobject.h"
11 #include "lzio.h"
14 #define FIRST_RESERVED 257
16 /* maximum length of a reserved word (+1 for final 0) */
17 #define TOKEN_LEN 15
21 * WARNING: if you change the order of this enumeration,
22 * grep "ORDER RESERVED"
24 enum RESERVED {
25 /* terminal symbols denoted by reserved words */
26 TK_AND = FIRST_RESERVED, TK_BREAK,
27 TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FOR, TK_FUNCTION, TK_IF, TK_LOCAL,
28 TK_NIL, TK_NOT, TK_OR, TK_REPEAT, TK_RETURN, TK_THEN, TK_UNTIL, TK_WHILE,
29 /* other terminal symbols */
30 TK_NAME, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER,
31 TK_STRING, TK_EOS
34 /* number of reserved words */
35 #define NUM_RESERVED ((int)(TK_WHILE-FIRST_RESERVED+1))
38 typedef union {
39 Number r;
40 TString *ts;
41 } SemInfo; /* semantics information */
44 typedef struct Token {
45 int token;
46 SemInfo seminfo;
47 } Token;
50 typedef struct LexState {
51 int current; /* current character */
52 Token t; /* current token */
53 Token lookahead; /* look ahead token */
54 struct FuncState *fs; /* `FuncState' is private to the parser */
55 struct lua_State *L;
56 struct zio *z; /* input stream */
57 int linenumber; /* input line counter */
58 int lastline; /* line of last token `consumed' */
59 TString *source; /* current source name */
60 } LexState;
63 void luaX_init (lua_State *L);
64 void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source);
65 int luaX_lex (LexState *LS, SemInfo *seminfo);
66 void luaX_checklimit (LexState *ls, int val, int limit, const char *msg);
67 void luaX_syntaxerror (LexState *ls, const char *s, const char *token);
68 void luaX_error (LexState *ls, const char *s, int token);
69 void luaX_token2str (int token, char *s);
72 #endif