xref: /netbsd-src/external/mit/lua/dist/src/llex.h (revision f0dad708b37bd6f5048a66ff2d48c1453845f039)
1 /*	$NetBSD: llex.h,v 1.9 2023/04/16 20:46:17 nikita Exp $	*/
2 
3 /*
4 ** Id: llex.h
5 ** Lexical Analyzer
6 ** See Copyright Notice in lua.h
7 */
8 
9 #ifndef llex_h
10 #define llex_h
11 
12 #ifndef _KERNEL
13 #include <limits.h>
14 #endif /* _KERNEL */
15 
16 #include "lobject.h"
17 #include "lzio.h"
18 
19 
20 /*
21 ** Single-char tokens (terminal symbols) are represented by their own
22 ** numeric code. Other tokens start at the following value.
23 */
24 #define FIRST_RESERVED	(UCHAR_MAX + 1)
25 
26 
27 #if !defined(LUA_ENV)
28 #define LUA_ENV		"_ENV"
29 #endif
30 
31 
32 /*
33 * WARNING: if you change the order of this enumeration,
34 * grep "ORDER RESERVED"
35 */
36 enum RESERVED {
37   /* terminal symbols denoted by reserved words */
38   TK_AND = FIRST_RESERVED, TK_BREAK,
39   TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,
40   TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
41   TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
42   /* other terminal symbols */
43   TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE,
44   TK_SHL, TK_SHR,
45   TK_DBCOLON, TK_EOS,
46 #ifndef _KERNEL
47   TK_FLT, TK_INT, TK_NAME, TK_STRING
48 #else /* _KERNEL */
49   TK_INT, TK_NAME, TK_STRING
50 #endif /* _KERNEL */
51 };
52 
53 /* number of reserved words */
54 #define NUM_RESERVED	(cast_int(TK_WHILE-FIRST_RESERVED + 1))
55 
56 
57 typedef union {
58   lua_Number r;
59   lua_Integer i;
60   TString *ts;
61 } SemInfo;  /* semantics information */
62 
63 
64 typedef struct Token {
65   int token;
66   SemInfo seminfo;
67 } Token;
68 
69 
70 /* state of the lexer plus state of the parser when shared by all
71    functions */
72 typedef struct LexState {
73   int current;  /* current character (charint) */
74   int linenumber;  /* input line counter */
75   int lastline;  /* line of last token 'consumed' */
76   Token t;  /* current token */
77   Token lookahead;  /* look ahead token */
78   struct FuncState *fs;  /* current function (parser) */
79   struct lua_State *L;
80   ZIO *z;  /* input stream */
81   Mbuffer *buff;  /* buffer for tokens */
82   Table *h;  /* to avoid collection/reuse strings */
83   struct Dyndata *dyd;  /* dynamic structures used by the parser */
84   TString *source;  /* current source name */
85   TString *envn;  /* environment variable name */
86 } LexState;
87 
88 
89 LUAI_FUNC void luaX_init (lua_State *L);
90 LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z,
91                               TString *source, int firstchar);
92 LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l);
93 LUAI_FUNC void luaX_next (LexState *ls);
94 LUAI_FUNC int luaX_lookahead (LexState *ls);
95 LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s);
96 LUAI_FUNC const char *luaX_token2str (LexState *ls, int token);
97 
98 
99 #endif
100