Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-07 10:37:56

0001 /*
0002 ** $Id: llex.h $
0003 ** Lexical Analyzer
0004 ** See Copyright Notice in lua.h
0005 */
0006 
0007 #ifndef llex_h
0008 #define llex_h
0009 
0010 #include <limits.h>
0011 
0012 #include "lobject.h"
0013 #include "lzio.h"
0014 
0015 
0016 /*
0017 ** Single-char tokens (terminal symbols) are represented by their own
0018 ** numeric code. Other tokens start at the following value.
0019 */
0020 #define FIRST_RESERVED  (UCHAR_MAX + 1)
0021 
0022 
0023 #if !defined(LUA_ENV)
0024 #define LUA_ENV     "_ENV"
0025 #endif
0026 
0027 
0028 /*
0029 * WARNING: if you change the order of this enumeration,
0030 * grep "ORDER RESERVED"
0031 */
0032 enum RESERVED {
0033   /* terminal symbols denoted by reserved words */
0034   TK_AND = FIRST_RESERVED, TK_BREAK,
0035   TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,
0036   TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
0037   TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
0038   /* other terminal symbols */
0039   TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE,
0040   TK_SHL, TK_SHR,
0041   TK_DBCOLON, TK_EOS,
0042   TK_FLT, TK_INT, TK_NAME, TK_STRING
0043 };
0044 
0045 /* number of reserved words */
0046 #define NUM_RESERVED    (cast_int(TK_WHILE-FIRST_RESERVED + 1))
0047 
0048 
0049 typedef union {
0050   lua_Number r;
0051   lua_Integer i;
0052   TString *ts;
0053 } SemInfo;  /* semantics information */
0054 
0055 
0056 typedef struct Token {
0057   int token;
0058   SemInfo seminfo;
0059 } Token;
0060 
0061 
0062 /* state of the lexer plus state of the parser when shared by all
0063    functions */
0064 typedef struct LexState {
0065   int current;  /* current character (charint) */
0066   int linenumber;  /* input line counter */
0067   int lastline;  /* line of last token 'consumed' */
0068   Token t;  /* current token */
0069   Token lookahead;  /* look ahead token */
0070   struct FuncState *fs;  /* current function (parser) */
0071   struct lua_State *L;
0072   ZIO *z;  /* input stream */
0073   Mbuffer *buff;  /* buffer for tokens */
0074   Table *h;  /* to avoid collection/reuse strings */
0075   struct Dyndata *dyd;  /* dynamic structures used by the parser */
0076   TString *source;  /* current source name */
0077   TString *envn;  /* environment variable name */
0078 } LexState;
0079 
0080 
0081 LUAI_FUNC void luaX_init (lua_State *L);
0082 LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z,
0083                               TString *source, int firstchar);
0084 LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l);
0085 LUAI_FUNC void luaX_next (LexState *ls);
0086 LUAI_FUNC int luaX_lookahead (LexState *ls);
0087 LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s);
0088 LUAI_FUNC const char *luaX_token2str (LexState *ls, int token);
0089 
0090 
0091 #endif