aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWaldemar Celes <celes@tecgraf.puc-rio.br>1994-10-17 17:01:53 -0200
committerWaldemar Celes <celes@tecgraf.puc-rio.br>1994-10-17 17:01:53 -0200
commitd1c5f4294365e9c5dbcd7f57bd0e3d55b548329c (patch)
tree7734e6b61075906db385d320ee1841aa341d01a3
parentad07c0f6380f527a8983039c4ae72ad40dd0443b (diff)
downloadlua-d1c5f4294365e9c5dbcd7f57bd0e3d55b548329c.tar.gz
lua-d1c5f4294365e9c5dbcd7f57bd0e3d55b548329c.tar.bz2
lua-d1c5f4294365e9c5dbcd7f57bd0e3d55b548329c.zip
new algorithm for reading floats.
files end with EOF, instead of 0.
-rw-r--r--lex.c49
1 files changed, 35 insertions, 14 deletions
diff --git a/lex.c b/lex.c
index ee64d1c9..060fa302 100644
--- a/lex.c
+++ b/lex.c
@@ -1,5 +1,9 @@
1char *rcs_lex = "$Id: lex.c,v 2.5 1994/09/22 12:44:00 lhf Exp celes $"; 1char *rcs_lex = "$Id: lex.c,v 2.6 1994/09/26 16:21:52 celes Exp celes $";
2/*$Log: lex.c,v $ 2/*$Log: lex.c,v $
3 * Revision 2.6 1994/09/26 16:21:52 celes
4 * Mudancas para tornar lex.c um modulo independente dos outros
5 * modulos de Lua
6 *
3 * Revision 2.5 1994/09/22 12:44:00 lhf 7 * Revision 2.5 1994/09/22 12:44:00 lhf
4 * added support for ugly tokens 8 * added support for ugly tokens
5 * 9 *
@@ -135,6 +139,7 @@ static int findReserved (char *name)
135 139
136int yylex () 140int yylex ()
137{ 141{
142 float a;
138 currentText = !currentText; 143 currentText = !currentText;
139 while (1) 144 while (1)
140 { 145 {
@@ -144,6 +149,9 @@ int yylex ()
144#endif 149#endif
145 switch (current) 150 switch (current)
146 { 151 {
152 case EOF:
153 case 0:
154 return 0;
147 case '\n': lua_linenumber++; 155 case '\n': lua_linenumber++;
148 case ' ': 156 case ' ':
149 case '\t': 157 case '\t':
@@ -202,6 +210,7 @@ int yylex ()
202 { 210 {
203 switch (current) 211 switch (current)
204 { 212 {
213 case EOF:
205 case 0: 214 case 0:
206 case '\n': 215 case '\n':
207 return WRONGTOKEN; 216 return WRONGTOKEN;
@@ -259,25 +268,37 @@ int yylex ()
259 } 268 }
260 else if (!isdigit(current)) return '.'; 269 else if (!isdigit(current)) return '.';
261 /* current is a digit: goes through to number */ 270 /* current is a digit: goes through to number */
271 a=0.0;
262 goto fraction; 272 goto fraction;
263 273
264 case '0': case '1': case '2': case '3': case '4': 274 case '0': case '1': case '2': case '3': case '4':
265 case '5': case '6': case '7': case '8': case '9': 275 case '5': case '6': case '7': case '8': case '9':
266 276 a=0.0;
267 do { save_and_next(); } while (isdigit(current)); 277 do { a=10*a+current-'0'; save_and_next(); } while (isdigit(current));
268 if (current == '.') save_and_next(); 278 if (current == '.') save_and_next();
269fraction: while (isdigit(current)) save_and_next(); 279fraction:
270 if (current == 'e' || current == 'E') 280 { float da=0.1;
271 { 281 while (isdigit(current))
272 save_and_next(); 282 {a+=(current-'0')*da; da/=10.0; save_and_next()};
273 if (current == '+' || current == '-') save_and_next(); 283 if (current == 'e' || current == 'E')
274 if (!isdigit(current)) return WRONGTOKEN; 284 {
275 do { save_and_next(); } while (isdigit(current)); 285 int e=0;
286 int neg;
287 float ea;
288 save_and_next();
289 neg=(current=='-');
290 if (current == '+' || current == '-') save_and_next();
291 if (!isdigit(current)) return WRONGTOKEN;
292 do { e=10*e+current-'0'; save_and_next(); } while (isdigit(current));
293 for (ea=neg?0.1:10.0; e>0; e>>=1)
294 {
295 if (e & 1) a*=ea;
296 ea*=ea;
297 }
298 }
299 yylval.vFloat = a;
300 return NUMBER;
276 } 301 }
277 *yytextLast = 0;
278 yylval.vFloat = atof(yytext[currentText]);
279 return NUMBER;
280
281 case U_and: next(); return AND; 302 case U_and: next(); return AND;
282 case U_do: next(); return DO; 303 case U_do: next(); return DO;
283 case U_else: next(); return ELSE; 304 case U_else: next(); return ELSE;