1
0
mirror of https://github.com/lua/lua.git synced 2025-01-14 05:43:00 +08:00
lua/llex.h

75 lines
1.8 KiB
C
Raw Normal View History

1997-09-16 16:25:59 -03:00
/*
2000-03-03 11:58:26 -03:00
** $Id: llex.h,v 1.18 2000/02/08 16:34:31 roberto Exp roberto $
1999-02-25 18:07:26 -03:00
** Lexical Analyzer
1997-09-16 16:25:59 -03:00
** See Copyright Notice in lua.h
*/
#ifndef llex_h
#define llex_h
#include "lobject.h"
#include "lzio.h"
2000-03-03 11:58:26 -03:00
#define FIRST_RESERVED 257
1998-05-27 10:08:34 -03:00
1999-12-27 15:33:22 -02:00
/* maximum length of a reserved word (+1 for final 0) */
1998-05-27 10:08:34 -03:00
#define TOKEN_LEN 15
1999-07-22 16:29:42 -03:00
/*
* WARNING: if you change the order of this enumeration,
* grep "ORDER RESERVED"
*/
1998-05-27 10:08:34 -03:00
enum RESERVED {
/* terminal symbols denoted by reserved words */
AND = FIRST_RESERVED,
DO, ELSE, ELSEIF, END, FUNCTION, IF, LOCAL, NIL, NOT, OR,
REPEAT, RETURN, THEN, UNTIL, WHILE,
/* other terminal symbols */
2000-02-08 14:39:42 -02:00
NAME, CONC, DOTS, EQ, GE, LE, NE, NUMBER, STRING, EOS
};
2000-03-03 11:58:26 -03:00
/* number of reserved words */
#define NUM_RESERVED ((int)(WHILE-FIRST_RESERVED+1))
1998-05-27 10:08:34 -03:00
1999-06-17 14:04:03 -03:00
#ifndef MAX_IFS
#define MAX_IFS 5 /* arbitrary limit */
#endif
1999-12-27 15:33:22 -02:00
/* `ifState' keeps the state of each nested $if the lexical is dealing with. */
struct ifState {
1999-02-25 18:07:26 -03:00
int elsepart; /* true if it's in the $else part */
int condition; /* true if $if condition is true */
1998-06-19 13:14:09 -03:00
int skip; /* true if part must be skipped */
};
typedef struct LexState {
int current; /* look ahead character */
1998-05-27 10:08:34 -03:00
int token; /* look ahead token */
2000-03-03 11:58:26 -03:00
struct FuncState *fs; /* `FuncState' is private to the parser */
struct lua_State *L;
1998-05-27 10:08:34 -03:00
union {
real r;
TaggedString *ts;
} seminfo; /* semantics information */
2000-03-03 11:58:26 -03:00
struct zio *z; /* input stream */
1997-12-02 10:43:44 -02:00
int linenumber; /* input line counter */
int iflevel; /* level of nested $if's (for lexical analysis) */
1998-01-09 12:57:43 -02:00
struct ifState ifstate[MAX_IFS];
} LexState;
void luaX_init (lua_State *L);
void luaX_setinput (lua_State *L, LexState *LS, ZIO *z);
1998-05-27 10:08:34 -03:00
int luaX_lex (LexState *LS);
1999-08-16 17:52:00 -03:00
void luaX_syntaxerror (LexState *ls, const char *s, const char *token);
2000-01-25 16:44:21 -02:00
void luaX_error (LexState *ls, const char *s, int token);
void luaX_token2str (int token, char *s);
1997-09-16 16:25:59 -03:00
#endif