Mudancas para tornar lex.c um modulo independente dos outros

modulos de Lua
This commit is contained in:
Waldemar Celes 1994-09-26 13:21:52 -03:00
parent 24c962de43
commit 7cfb5ff41f
1 changed files with 34 additions and 24 deletions

58
lex.c
View File

@ -1,5 +1,8 @@
char *rcs_lex = "$Id: lex.c,v 2.4 1994/09/05 19:14:40 celes Exp lhf $"; char *rcs_lex = "$Id: lex.c,v 2.5 1994/09/22 12:44:00 lhf Exp celes $";
/*$Log: lex.c,v $ /*$Log: lex.c,v $
* Revision 2.5 1994/09/22 12:44:00 lhf
* added support for ugly tokens
*
* Revision 2.4 1994/09/05 19:14:40 celes * Revision 2.4 1994/09/05 19:14:40 celes
* escapes \' e \" em strings; correcao do escape \\ * escapes \' e \" em strings; correcao do escape \\
* *
@ -27,13 +30,12 @@ char *rcs_lex = "$Id: lex.c,v 2.4 1994/09/05 19:14:40 celes Exp lhf $";
#include <ctype.h> #include <ctype.h>
#include <math.h> #include <math.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "opcode.h" #include "opcode.h"
#include "hash.h"
#include "inout.h" #include "inout.h"
#include "table.h"
#include "y.tab.h" #include "y.tab.h"
#define lua_strcmp(a,b) (a[0]<b[0]?(-1):(a[0]>b[0]?(1):strcmp(a,b))) #define lua_strcmp(a,b) (a[0]<b[0]?(-1):(a[0]>b[0]?(1):strcmp(a,b)))
@ -137,6 +139,9 @@ int yylex ()
while (1) while (1)
{ {
yytextLast = yytext[currentText]; yytextLast = yytext[currentText];
#if 0
fprintf(stderr,"'%c' %d\n",current,current);
#endif
switch (current) switch (current)
{ {
case '\n': lua_linenumber++; case '\n': lua_linenumber++;
@ -168,6 +173,11 @@ int yylex ()
do { next(); } while (current != '\n' && current != 0); do { next(); } while (current != '\n' && current != 0);
continue; continue;
case '=':
save_and_next();
if (current != '=') return '=';
else { save_and_next(); return EQ; }
case '<': case '<':
save_and_next(); save_and_next();
if (current != '=') return '<'; if (current != '=') return '<';
@ -213,7 +223,7 @@ int yylex ()
} }
next(); /* skip the delimiter */ next(); /* skip the delimiter */
*yytextLast = 0; *yytextLast = 0;
yylval.vWord = lua_findconstant (yytext[currentText]); yylval.pChar = yytext[currentText];
return STRING; return STRING;
} }
@ -268,26 +278,26 @@ fraction: while (isdigit(current)) save_and_next();
yylval.vFloat = atof(yytext[currentText]); yylval.vFloat = atof(yytext[currentText]);
return NUMBER; return NUMBER;
case U_and: return AND; case U_and: next(); return AND;
case U_do: return DO; case U_do: next(); return DO;
case U_else: return ELSE; case U_else: next(); return ELSE;
case U_elseif: return ELSEIF; case U_elseif: next(); return ELSEIF;
case U_end: return END; case U_end: next(); return END;
case U_function: return FUNCTION; case U_function: next(); return FUNCTION;
case U_if: return IF; case U_if: next(); return IF;
case U_local: return LOCAL; case U_local: next(); return LOCAL;
case U_nil: return NIL; case U_nil: next(); return NIL;
case U_not: return NOT; case U_not: next(); return NOT;
case U_or: return OR; case U_or: next(); return OR;
case U_repeat: return REPEAT; case U_repeat: next(); return REPEAT;
case U_return: return RETURN; case U_return: next(); return RETURN;
case U_then: return THEN; case U_then: next(); return THEN;
case U_until: return UNTIL; case U_until: next(); return UNTIL;
case U_while: return WHILE; case U_while: next(); return WHILE;
case U_le: return LE; case U_le: next(); return LE;
case U_ge: return GE; case U_ge: next(); return GE;
case U_ne: return NE; case U_ne: next(); return NE;
case U_sc: return CONC; case U_sc: next(); return CONC;
default: /* also end of file */ default: /* also end of file */
{ {