aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>1994-09-22 09:44:00 -0300
committerLuiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>1994-09-22 09:44:00 -0300
commit24c962de431934dc827cac2e98442fa6c1b09ce9 (patch)
tree77bf7c34cd6932906028197b7f9aa743ff623ad8
parent98d95096762b363e3efa501996c896675059b6d1 (diff)
downloadlua-24c962de431934dc827cac2e98442fa6c1b09ce9.tar.gz
lua-24c962de431934dc827cac2e98442fa6c1b09ce9.tar.bz2
lua-24c962de431934dc827cac2e98442fa6c1b09ce9.zip
added support for ugly tokens
-rw-r--r--lex.c83
1 files changed, 65 insertions, 18 deletions
diff --git a/lex.c b/lex.c
index 072bb241..080b488c 100644
--- a/lex.c
+++ b/lex.c
@@ -1,5 +1,8 @@
1char *rcs_lex = "$Id: lex.c,v 2.3 1994/08/17 17:41:50 celes Exp celes $"; 1char *rcs_lex = "$Id: lex.c,v 2.4 1994/09/05 19:14:40 celes Exp lhf $";
2/*$Log: lex.c,v $ 2/*$Log: lex.c,v $
3 * Revision 2.4 1994/09/05 19:14:40 celes
4 * escapes \' e \" em strings; correcao do escape \\
5 *
3 * Revision 2.3 1994/08/17 17:41:50 celes 6 * Revision 2.3 1994/08/17 17:41:50 celes
4 * Implementacao da macro 'lua_strcmp' 7 * Implementacao da macro 'lua_strcmp'
5 * 8 *
@@ -33,7 +36,7 @@ char *rcs_lex = "$Id: lex.c,v 2.3 1994/08/17 17:41:50 celes Exp celes $";
33#include "table.h" 36#include "table.h"
34#include "y.tab.h" 37#include "y.tab.h"
35 38
36#define lua_strcmp(a,b) (a[0]<b[0]?(-1):(a[0]>b[0]?(1):strcmp(a,b))) 39#define lua_strcmp(a,b) (a[0]<b[0]?(-1):(a[0]>b[0]?(1):strcmp(a,b)))
37 40
38#define next() { current = input(); } 41#define next() { current = input(); }
39#define save(x) { *yytextLast++ = (x); } 42#define save(x) { *yytextLast++ = (x); }
@@ -60,7 +63,7 @@ char *lua_lasttext (void)
60 63
61 64
62/* The reserved words must be listed in lexicographic order */ 65/* The reserved words must be listed in lexicographic order */
63static struct 66static struct
64 { 67 {
65 char *name; 68 char *name;
66 int token; 69 int token;
@@ -82,6 +85,30 @@ static struct
82 {"until", UNTIL}, 85 {"until", UNTIL},
83 {"while", WHILE} }; 86 {"while", WHILE} };
84 87
88enum
89{
90 U_and=128,
91 U_do,
92 U_else,
93 U_elseif,
94 U_end,
95 U_function,
96 U_if,
97 U_local,
98 U_nil,
99 U_not,
100 U_or,
101 U_repeat,
102 U_return,
103 U_then,
104 U_until,
105 U_while,
106 U_le = '<'+128,
107 U_ge = '>'+128,
108 U_ne = '~'+128,
109 U_sc = '.'+128
110};
111
85#define RESERVEDSIZE (sizeof(reserved)/sizeof(reserved[0])) 112#define RESERVEDSIZE (sizeof(reserved)/sizeof(reserved[0]))
86 113
87 114
@@ -134,23 +161,23 @@ int yylex ()
134 return DEBUG; 161 return DEBUG;
135 } 162 }
136 return WRONGTOKEN; 163 return WRONGTOKEN;
137 164
138 case '-': 165 case '-':
139 save_and_next(); 166 save_and_next();
140 if (current != '-') return '-'; 167 if (current != '-') return '-';
141 do { next(); } while (current != '\n' && current != 0); 168 do { next(); } while (current != '\n' && current != 0);
142 continue; 169 continue;
143 170
144 case '<': 171 case '<':
145 save_and_next(); 172 save_and_next();
146 if (current != '=') return '<'; 173 if (current != '=') return '<';
147 else { save_and_next(); return LE; } 174 else { save_and_next(); return LE; }
148 175
149 case '>': 176 case '>':
150 save_and_next(); 177 save_and_next();
151 if (current != '=') return '>'; 178 if (current != '=') return '>';
152 else { save_and_next(); return GE; } 179 else { save_and_next(); return GE; }
153 180
154 case '~': 181 case '~':
155 save_and_next(); 182 save_and_next();
156 if (current != '=') return '~'; 183 if (current != '=') return '~';
@@ -161,12 +188,12 @@ int yylex ()
161 { 188 {
162 int del = current; 189 int del = current;
163 next(); /* skip the delimiter */ 190 next(); /* skip the delimiter */
164 while (current != del) 191 while (current != del)
165 { 192 {
166 switch (current) 193 switch (current)
167 { 194 {
168 case 0: 195 case 0:
169 case '\n': 196 case '\n':
170 return WRONGTOKEN; 197 return WRONGTOKEN;
171 case '\\': 198 case '\\':
172 next(); /* do not save the '\' */ 199 next(); /* do not save the '\' */
@@ -180,7 +207,7 @@ int yylex ()
180 default : save(current); next(); break; 207 default : save(current); next(); break;
181 } 208 }
182 break; 209 break;
183 default: 210 default:
184 save_and_next(); 211 save_and_next();
185 } 212 }
186 } 213 }
@@ -212,12 +239,12 @@ int yylex ()
212 yylval.pChar = yytext[currentText]; 239 yylval.pChar = yytext[currentText];
213 return NAME; 240 return NAME;
214 } 241 }
215 242
216 case '.': 243 case '.':
217 save_and_next(); 244 save_and_next();
218 if (current == '.') 245 if (current == '.')
219 { 246 {
220 save_and_next(); 247 save_and_next();
221 return CONC; 248 return CONC;
222 } 249 }
223 else if (!isdigit(current)) return '.'; 250 else if (!isdigit(current)) return '.';
@@ -226,7 +253,7 @@ int yylex ()
226 253
227 case '0': case '1': case '2': case '3': case '4': 254 case '0': case '1': case '2': case '3': case '4':
228 case '5': case '6': case '7': case '8': case '9': 255 case '5': case '6': case '7': case '8': case '9':
229 256
230 do { save_and_next(); } while (isdigit(current)); 257 do { save_and_next(); } while (isdigit(current));
231 if (current == '.') save_and_next(); 258 if (current == '.') save_and_next();
232fraction: while (isdigit(current)) save_and_next(); 259fraction: while (isdigit(current)) save_and_next();
@@ -241,12 +268,32 @@ fraction: while (isdigit(current)) save_and_next();
241 yylval.vFloat = atof(yytext[currentText]); 268 yylval.vFloat = atof(yytext[currentText]);
242 return NUMBER; 269 return NUMBER;
243 270
271 case U_and: return AND;
272 case U_do: return DO;
273 case U_else: return ELSE;
274 case U_elseif: return ELSEIF;
275 case U_end: return END;
276 case U_function: return FUNCTION;
277 case U_if: return IF;
278 case U_local: return LOCAL;
279 case U_nil: return NIL;
280 case U_not: return NOT;
281 case U_or: return OR;
282 case U_repeat: return REPEAT;
283 case U_return: return RETURN;
284 case U_then: return THEN;
285 case U_until: return UNTIL;
286 case U_while: return WHILE;
287 case U_le: return LE;
288 case U_ge: return GE;
289 case U_ne: return NE;
290 case U_sc: return CONC;
291
244 default: /* also end of file */ 292 default: /* also end of file */
245 { 293 {
246 save_and_next(); 294 save_and_next();
247 return yytext[currentText][0]; 295 return yytext[currentText][0];
248 } 296 }
249 } 297 }
250 } 298 }
251} 299}
252