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