|
@ -1,5 +1,5 @@ |
|
|
/*
|
|
|
/*
|
|
|
** $Id: llex.c,v 1.24 1998/07/24 18:02:38 roberto Exp roberto $ |
|
|
** $Id: llex.c,v 1.25 1998/12/03 15:45:15 roberto Exp $ |
|
|
** Lexical Analizer |
|
|
** Lexical Analizer |
|
|
** See Copyright Notice in lua.h |
|
|
** See Copyright Notice in lua.h |
|
|
*/ |
|
|
*/ |
|
@ -46,7 +46,7 @@ void luaX_init (void) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void luaX_syntaxerror (LexState *ls, char *s, char *token) { |
|
|
void luaX_syntaxerror (LexState *ls, char *s, char *token) { |
|
|
if (token[0] == 0) |
|
|
if (token[0] == '\0') |
|
|
token = "<eof>"; |
|
|
token = "<eof>"; |
|
|
luaL_verror("%.100s;\n last token read: `%.50s' at line %d in chunk `%.50s'", |
|
|
luaL_verror("%.100s;\n last token read: `%.50s' at line %d in chunk `%.50s'", |
|
|
s, token, ls->linenumber, zname(ls->lex_z)); |
|
|
s, token, ls->linenumber, zname(ls->lex_z)); |
|
@ -54,7 +54,7 @@ void luaX_syntaxerror (LexState *ls, char *s, char *token) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void luaX_error (LexState *ls, char *s) { |
|
|
void luaX_error (LexState *ls, char *s) { |
|
|
save(0); |
|
|
save('\0'); |
|
|
luaX_syntaxerror(ls, s, luaL_buffer()); |
|
|
luaX_syntaxerror(ls, s, luaL_buffer()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -62,7 +62,7 @@ void luaX_error (LexState *ls, char *s) { |
|
|
void luaX_token2str (int token, char *s) { |
|
|
void luaX_token2str (int token, char *s) { |
|
|
if (token < 255) { |
|
|
if (token < 255) { |
|
|
s[0] = token; |
|
|
s[0] = token; |
|
|
s[1] = 0; |
|
|
s[1] = '\0'; |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
strcpy(s, reserved[token-FIRST_RESERVED]); |
|
|
strcpy(s, reserved[token-FIRST_RESERVED]); |
|
@ -221,6 +221,7 @@ static void inclinenumber (LexState *LS) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
** ======================================================= |
|
|
** ======================================================= |
|
|
** LEXICAL ANALIZER |
|
|
** LEXICAL ANALIZER |
|
@ -229,10 +230,7 @@ static void inclinenumber (LexState *LS) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int read_long_string (LexState *LS) { |
|
|
|
|
|
|
|
|
static int read_long_string (LexState *LS) |
|
|
|
|
|
{ |
|
|
|
|
|
int cont = 0; |
|
|
int cont = 0; |
|
|
for (;;) { |
|
|
for (;;) { |
|
|
switch (LS->current) { |
|
|
switch (LS->current) { |
|
@ -262,7 +260,7 @@ static int read_long_string (LexState *LS) |
|
|
save_and_next(LS); |
|
|
save_and_next(LS); |
|
|
} |
|
|
} |
|
|
} endloop: |
|
|
} endloop: |
|
|
save_and_next(LS); /* pass the second ']' */ |
|
|
save_and_next(LS); /* skip the second ']' */ |
|
|
LS->seminfo.ts = luaS_newlstr(L->Mbuffbase+2, |
|
|
LS->seminfo.ts = luaS_newlstr(L->Mbuffbase+2, |
|
|
L->Mbuffnext-(L->Mbuffbase-L->Mbuffer)-4); |
|
|
L->Mbuffnext-(L->Mbuffbase-L->Mbuffer)-4); |
|
|
return STRING; |
|
|
return STRING; |
|
@ -270,7 +268,6 @@ static int read_long_string (LexState *LS) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int luaX_lex (LexState *LS) { |
|
|
int luaX_lex (LexState *LS) { |
|
|
double a; |
|
|
|
|
|
luaL_resetbuffer(); |
|
|
luaL_resetbuffer(); |
|
|
for (;;) { |
|
|
for (;;) { |
|
|
switch (LS->current) { |
|
|
switch (LS->current) { |
|
@ -347,7 +344,7 @@ int luaX_lex (LexState *LS) { |
|
|
c = 10*c + (LS->current-'0'); |
|
|
c = 10*c + (LS->current-'0'); |
|
|
next(LS); |
|
|
next(LS); |
|
|
} while (++i<3 && isdigit(LS->current)); |
|
|
} while (++i<3 && isdigit(LS->current)); |
|
|
if (c >= 256) |
|
|
if (c > (unsigned char)c) |
|
|
luaX_error(LS, "escape sequence too large"); |
|
|
luaX_error(LS, "escape sequence too large"); |
|
|
save(c); |
|
|
save(c); |
|
|
} |
|
|
} |
|
@ -382,15 +379,11 @@ int luaX_lex (LexState *LS) { |
|
|
else return CONC; /* .. */ |
|
|
else return CONC; /* .. */ |
|
|
} |
|
|
} |
|
|
else if (!isdigit(LS->current)) return '.'; |
|
|
else if (!isdigit(LS->current)) return '.'; |
|
|
/* LS->current is a digit: goes through to number */ |
|
|
goto fraction; /* LS->current is a digit: goes through to number */ |
|
|
a=0.0; |
|
|
|
|
|
goto fraction; |
|
|
|
|
|
|
|
|
|
|
|
case '0': case '1': case '2': case '3': case '4': |
|
|
case '0': case '1': case '2': case '3': case '4': |
|
|
case '5': case '6': case '7': case '8': case '9': |
|
|
case '5': case '6': case '7': case '8': case '9': |
|
|
a=0.0; |
|
|
|
|
|
do { |
|
|
do { |
|
|
a = 10.0*a + (LS->current-'0'); |
|
|
|
|
|
save_and_next(LS); |
|
|
save_and_next(LS); |
|
|
} while (isdigit(LS->current)); |
|
|
} while (isdigit(LS->current)); |
|
|
if (LS->current == '.') { |
|
|
if (LS->current == '.') { |
|
@ -402,35 +395,19 @@ int luaX_lex (LexState *LS) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
fraction: |
|
|
fraction: |
|
|
{ double da=0.1; |
|
|
while (isdigit(LS->current)) |
|
|
while (isdigit(LS->current)) |
|
|
save_and_next(LS); |
|
|
{ |
|
|
if (toupper(LS->current) == 'E') { |
|
|
a += (LS->current-'0')*da; |
|
|
save_and_next(LS); /* read 'E' */ |
|
|
da /= 10.0; |
|
|
save_and_next(LS); /* read '+', '-' or first digit */ |
|
|
save_and_next(LS); |
|
|
while (isdigit(LS->current)) |
|
|
} |
|
|
|
|
|
if (toupper(LS->current) == 'E') { |
|
|
|
|
|
int e = 0; |
|
|
|
|
|
int neg; |
|
|
|
|
|
double ea; |
|
|
|
|
|
save_and_next(LS); |
|
|
save_and_next(LS); |
|
|
neg = (LS->current=='-'); |
|
|
|
|
|
if (LS->current == '+' || LS->current == '-') save_and_next(LS); |
|
|
|
|
|
if (!isdigit(LS->current)) |
|
|
|
|
|
luaX_error(LS, "invalid numeral format"); |
|
|
|
|
|
do { |
|
|
|
|
|
e = 10*e + (LS->current-'0'); |
|
|
|
|
|
save_and_next(LS); |
|
|
|
|
|
} while (isdigit(LS->current)); |
|
|
|
|
|
for (ea=neg?0.1:10.0; e>0; e>>=1) |
|
|
|
|
|
{ |
|
|
|
|
|
if (e & 1) a *= ea; |
|
|
|
|
|
ea *= ea; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
LS->seminfo.r = a; |
|
|
|
|
|
return NUMBER; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
save('\0'); |
|
|
|
|
|
LS->seminfo.r = luaO_str2d(L->Mbuffbase); |
|
|
|
|
|
if (LS->seminfo.r < 0) |
|
|
|
|
|
luaX_error(LS, "invalid numeric format"); |
|
|
|
|
|
return NUMBER; |
|
|
|
|
|
|
|
|
case EOZ: |
|
|
case EOZ: |
|
|
if (LS->iflevel > 0) |
|
|
if (LS->iflevel > 0) |
|
@ -450,9 +427,9 @@ int luaX_lex (LexState *LS) { |
|
|
do { |
|
|
do { |
|
|
save_and_next(LS); |
|
|
save_and_next(LS); |
|
|
} while (isalnum(LS->current) || LS->current == '_'); |
|
|
} while (isalnum(LS->current) || LS->current == '_'); |
|
|
save(0); |
|
|
save('\0'); |
|
|
ts = luaS_new(L->Mbuffbase); |
|
|
ts = luaS_new(L->Mbuffbase); |
|
|
if (ts->head.marked >= 'A') |
|
|
if (ts->head.marked >= FIRST_RESERVED) |
|
|
return ts->head.marked; /* reserved word */ |
|
|
return ts->head.marked; /* reserved word */ |
|
|
LS->seminfo.ts = ts; |
|
|
LS->seminfo.ts = ts; |
|
|
return NAME; |
|
|
return NAME; |
|
|