aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWaldemar Celes <celes@tecgraf.puc-rio.br>1994-09-26 13:21:52 -0300
committerWaldemar Celes <celes@tecgraf.puc-rio.br>1994-09-26 13:21:52 -0300
commit7cfb5ff41f993c0f7e248f6830e86055bddcd3ab (patch)
tree792fae7aaea7494f550422512e52cd7235154c83
parent24c962de431934dc827cac2e98442fa6c1b09ce9 (diff)
downloadlua-7cfb5ff41f993c0f7e248f6830e86055bddcd3ab.tar.gz
lua-7cfb5ff41f993c0f7e248f6830e86055bddcd3ab.tar.bz2
lua-7cfb5ff41f993c0f7e248f6830e86055bddcd3ab.zip
Mudancas para tornar lex.c um modulo independente dos outros
modulos de Lua
-rw-r--r--lex.c58
1 files changed, 34 insertions, 24 deletions
diff --git a/lex.c b/lex.c
index 080b488c..ee64d1c9 100644
--- a/lex.c
+++ b/lex.c
@@ -1,5 +1,8 @@
1char *rcs_lex = "$Id: lex.c,v 2.4 1994/09/05 19:14:40 celes Exp lhf $"; 1char *rcs_lex = "$Id: lex.c,v 2.5 1994/09/22 12:44:00 lhf Exp celes $";
2/*$Log: lex.c,v $ 2/*$Log: lex.c,v $
3 * Revision 2.5 1994/09/22 12:44:00 lhf
4 * added support for ugly tokens
5 *
3 * Revision 2.4 1994/09/05 19:14:40 celes 6 * Revision 2.4 1994/09/05 19:14:40 celes
4 * escapes \' e \" em strings; correcao do escape \\ 7 * escapes \' e \" em strings; correcao do escape \\
5 * 8 *
@@ -27,13 +30,12 @@ char *rcs_lex = "$Id: lex.c,v 2.4 1994/09/05 19:14:40 celes Exp lhf $";
27 30
28#include <ctype.h> 31#include <ctype.h>
29#include <math.h> 32#include <math.h>
33#include <stdio.h>
30#include <stdlib.h> 34#include <stdlib.h>
31#include <string.h> 35#include <string.h>
32 36
33#include "opcode.h" 37#include "opcode.h"
34#include "hash.h"
35#include "inout.h" 38#include "inout.h"
36#include "table.h"
37#include "y.tab.h" 39#include "y.tab.h"
38 40
39#define lua_strcmp(a,b) (a[0]<b[0]?(-1):(a[0]>b[0]?(1):strcmp(a,b))) 41#define lua_strcmp(a,b) (a[0]<b[0]?(-1):(a[0]>b[0]?(1):strcmp(a,b)))
@@ -137,6 +139,9 @@ int yylex ()
137 while (1) 139 while (1)
138 { 140 {
139 yytextLast = yytext[currentText]; 141 yytextLast = yytext[currentText];
142#if 0
143 fprintf(stderr,"'%c' %d\n",current,current);
144#endif
140 switch (current) 145 switch (current)
141 { 146 {
142 case '\n': lua_linenumber++; 147 case '\n': lua_linenumber++;
@@ -168,6 +173,11 @@ int yylex ()
168 do { next(); } while (current != '\n' && current != 0); 173 do { next(); } while (current != '\n' && current != 0);
169 continue; 174 continue;
170 175
176 case '=':
177 save_and_next();
178 if (current != '=') return '=';
179 else { save_and_next(); return EQ; }
180
171 case '<': 181 case '<':
172 save_and_next(); 182 save_and_next();
173 if (current != '=') return '<'; 183 if (current != '=') return '<';
@@ -213,7 +223,7 @@ int yylex ()
213 } 223 }
214 next(); /* skip the delimiter */ 224 next(); /* skip the delimiter */
215 *yytextLast = 0; 225 *yytextLast = 0;
216 yylval.vWord = lua_findconstant (yytext[currentText]); 226 yylval.pChar = yytext[currentText];
217 return STRING; 227 return STRING;
218 } 228 }
219 229
@@ -268,26 +278,26 @@ fraction: while (isdigit(current)) save_and_next();
268 yylval.vFloat = atof(yytext[currentText]); 278 yylval.vFloat = atof(yytext[currentText]);
269 return NUMBER; 279 return NUMBER;
270 280
271 case U_and: return AND; 281 case U_and: next(); return AND;
272 case U_do: return DO; 282 case U_do: next(); return DO;
273 case U_else: return ELSE; 283 case U_else: next(); return ELSE;
274 case U_elseif: return ELSEIF; 284 case U_elseif: next(); return ELSEIF;
275 case U_end: return END; 285 case U_end: next(); return END;
276 case U_function: return FUNCTION; 286 case U_function: next(); return FUNCTION;
277 case U_if: return IF; 287 case U_if: next(); return IF;
278 case U_local: return LOCAL; 288 case U_local: next(); return LOCAL;
279 case U_nil: return NIL; 289 case U_nil: next(); return NIL;
280 case U_not: return NOT; 290 case U_not: next(); return NOT;
281 case U_or: return OR; 291 case U_or: next(); return OR;
282 case U_repeat: return REPEAT; 292 case U_repeat: next(); return REPEAT;
283 case U_return: return RETURN; 293 case U_return: next(); return RETURN;
284 case U_then: return THEN; 294 case U_then: next(); return THEN;
285 case U_until: return UNTIL; 295 case U_until: next(); return UNTIL;
286 case U_while: return WHILE; 296 case U_while: next(); return WHILE;
287 case U_le: return LE; 297 case U_le: next(); return LE;
288 case U_ge: return GE; 298 case U_ge: next(); return GE;
289 case U_ne: return NE; 299 case U_ne: next(); return NE;
290 case U_sc: return CONC; 300 case U_sc: next(); return CONC;
291 301
292 default: /* also end of file */ 302 default: /* also end of file */
293 { 303 {