diff options
author | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1994-08-05 16:27:41 -0300 |
---|---|---|
committer | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1994-08-05 16:27:41 -0300 |
commit | be7aa3854be4c8d9203637955a064439f240951f (patch) | |
tree | 8853d5837c890359c2637afc1ec76aa8870ebbff /lex.c | |
parent | 088cc3f3802b98e613f1348b15679ecd187a435b (diff) | |
download | lua-be7aa3854be4c8d9203637955a064439f240951f.tar.gz lua-be7aa3854be4c8d9203637955a064439f240951f.tar.bz2 lua-be7aa3854be4c8d9203637955a064439f240951f.zip |
implementacao de dois buffer de 'yytext' para evitar bug
no look ahead do yacc
Diffstat (limited to 'lex.c')
-rw-r--r-- | lex.c | 32 |
1 files changed, 20 insertions, 12 deletions
@@ -1,5 +1,10 @@ | |||
1 | char *rcs_lex = "$Id: lex.c,v 1.3 1993/12/28 16:42:29 roberto Exp celes $"; | 1 | char *rcs_lex = "$Id: lex.c,v 2.1 1994/04/15 19:00:28 celes Exp celes $"; |
2 | /*$Log: lex.c,v $ | 2 | /*$Log: lex.c,v $ |
3 | * Revision 2.1 1994/04/15 19:00:28 celes | ||
4 | * Retirar chamada da funcao lua_findsymbol associada a cada | ||
5 | * token NAME. A decisao de chamar lua_findsymbol ou lua_findconstant | ||
6 | * fica a cargo do modulo "lua.stx". | ||
7 | * | ||
3 | * Revision 1.3 1993/12/28 16:42:29 roberto | 8 | * Revision 1.3 1993/12/28 16:42:29 roberto |
4 | * "include"s de string.h e stdlib.h para evitar warnings | 9 | * "include"s de string.h e stdlib.h para evitar warnings |
5 | * | 10 | * |
@@ -26,8 +31,9 @@ char *rcs_lex = "$Id: lex.c,v 1.3 1993/12/28 16:42:29 roberto Exp celes $"; | |||
26 | #define save_and_next() { save(current); next(); } | 31 | #define save_and_next() { save(current); next(); } |
27 | 32 | ||
28 | static int current; | 33 | static int current; |
29 | static char yytext[256]; | 34 | static char yytext[2][256]; |
30 | static char *yytextLast; | 35 | static char *yytextLast; |
36 | static int currentText = 0; | ||
31 | 37 | ||
32 | static Input input; | 38 | static Input input; |
33 | 39 | ||
@@ -40,10 +46,11 @@ void lua_setinput (Input fn) | |||
40 | char *lua_lasttext (void) | 46 | char *lua_lasttext (void) |
41 | { | 47 | { |
42 | *yytextLast = 0; | 48 | *yytextLast = 0; |
43 | return yytext; | 49 | return yytext[currentText]; |
44 | } | 50 | } |
45 | 51 | ||
46 | 52 | ||
53 | /* The reserved words must be listed in lexicographic order */ | ||
47 | static struct | 54 | static struct |
48 | { | 55 | { |
49 | char *name; | 56 | char *name; |
@@ -69,7 +76,7 @@ static struct | |||
69 | #define RESERVEDSIZE (sizeof(reserved)/sizeof(reserved[0])) | 76 | #define RESERVEDSIZE (sizeof(reserved)/sizeof(reserved[0])) |
70 | 77 | ||
71 | 78 | ||
72 | int findReserved (char *name) | 79 | static int findReserved (char *name) |
73 | { | 80 | { |
74 | int l = 0; | 81 | int l = 0; |
75 | int h = RESERVEDSIZE - 1; | 82 | int h = RESERVEDSIZE - 1; |
@@ -90,9 +97,10 @@ int findReserved (char *name) | |||
90 | 97 | ||
91 | int yylex () | 98 | int yylex () |
92 | { | 99 | { |
100 | currentText = !currentText; | ||
93 | while (1) | 101 | while (1) |
94 | { | 102 | { |
95 | yytextLast = yytext; | 103 | yytextLast = yytext[currentText]; |
96 | switch (current) | 104 | switch (current) |
97 | { | 105 | { |
98 | case '\n': lua_linenumber++; | 106 | case '\n': lua_linenumber++; |
@@ -106,12 +114,12 @@ int yylex () | |||
106 | while (isalnum(current) || current == '_') | 114 | while (isalnum(current) || current == '_') |
107 | save_and_next(); | 115 | save_and_next(); |
108 | *yytextLast = 0; | 116 | *yytextLast = 0; |
109 | if (strcmp(yytext, "debug") == 0) | 117 | if (strcmp(yytext[currentText], "debug") == 0) |
110 | { | 118 | { |
111 | yylval.vInt = 1; | 119 | yylval.vInt = 1; |
112 | return DEBUG; | 120 | return DEBUG; |
113 | } | 121 | } |
114 | else if (strcmp(yytext, "nodebug") == 0) | 122 | else if (strcmp(yytext[currentText], "nodebug") == 0) |
115 | { | 123 | { |
116 | yylval.vInt = 0; | 124 | yylval.vInt = 0; |
117 | return DEBUG; | 125 | return DEBUG; |
@@ -167,7 +175,7 @@ int yylex () | |||
167 | } | 175 | } |
168 | next(); /* skip the delimiter */ | 176 | next(); /* skip the delimiter */ |
169 | *yytextLast = 0; | 177 | *yytextLast = 0; |
170 | yylval.vWord = lua_findconstant (yytext); | 178 | yylval.vWord = lua_findconstant (yytext[currentText]); |
171 | return STRING; | 179 | return STRING; |
172 | } | 180 | } |
173 | 181 | ||
@@ -188,9 +196,9 @@ int yylex () | |||
188 | int res; | 196 | int res; |
189 | do { save_and_next(); } while (isalnum(current) || current == '_'); | 197 | do { save_and_next(); } while (isalnum(current) || current == '_'); |
190 | *yytextLast = 0; | 198 | *yytextLast = 0; |
191 | res = findReserved(yytext); | 199 | res = findReserved(yytext[currentText]); |
192 | if (res) return res; | 200 | if (res) return res; |
193 | yylval.pChar = yytext; | 201 | yylval.pChar = yytext[currentText]; |
194 | return NAME; | 202 | return NAME; |
195 | } | 203 | } |
196 | 204 | ||
@@ -219,13 +227,13 @@ fraction: while (isdigit(current)) save_and_next(); | |||
219 | do { save_and_next(); } while (isdigit(current)); | 227 | do { save_and_next(); } while (isdigit(current)); |
220 | } | 228 | } |
221 | *yytextLast = 0; | 229 | *yytextLast = 0; |
222 | yylval.vFloat = atof(yytext); | 230 | yylval.vFloat = atof(yytext[currentText]); |
223 | return NUMBER; | 231 | return NUMBER; |
224 | 232 | ||
225 | default: /* also end of file */ | 233 | default: /* also end of file */ |
226 | { | 234 | { |
227 | save_and_next(); | 235 | save_and_next(); |
228 | return *yytext; | 236 | return yytext[currentText][0]; |
229 | } | 237 | } |
230 | } | 238 | } |
231 | } | 239 | } |