diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-02-14 10:35:51 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-02-14 10:35:51 -0300 |
| commit | d1608c597e2f45021d43c56050aff08e5d417699 (patch) | |
| tree | e6b0a07e68384cd9707e7dda6864dd8664e2ee99 /lex.c | |
| parent | 0f4903a5d79fb594115c5603072d0dce77b2b84e (diff) | |
| download | lua-d1608c597e2f45021d43c56050aff08e5d417699.tar.gz lua-d1608c597e2f45021d43c56050aff08e5d417699.tar.bz2 lua-d1608c597e2f45021d43c56050aff08e5d417699.zip | |
reserved words are stored in main string table; "marked" field is
used to indicate its type.
Table initializations centralized by "tree.c".
Diffstat (limited to 'lex.c')
| -rw-r--r-- | lex.c | 31 |
1 files changed, 12 insertions, 19 deletions
| @@ -1,4 +1,4 @@ | |||
| 1 | char *rcs_lex = "$Id: lex.c,v 2.25 1996/02/12 18:32:40 roberto Exp roberto $"; | 1 | char *rcs_lex = "$Id: lex.c,v 2.26 1996/02/13 17:30:39 roberto Exp roberto $"; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | #include <ctype.h> | 4 | #include <ctype.h> |
| @@ -47,7 +47,6 @@ char *lua_lasttext (void) | |||
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | 49 | ||
| 50 | /* The reserved words must be listed in lexicographic order */ | ||
| 51 | static struct | 50 | static struct |
| 52 | { | 51 | { |
| 53 | char *name; | 52 | char *name; |
| @@ -74,22 +73,14 @@ static struct | |||
| 74 | #define RESERVEDSIZE (sizeof(reserved)/sizeof(reserved[0])) | 73 | #define RESERVEDSIZE (sizeof(reserved)/sizeof(reserved[0])) |
| 75 | 74 | ||
| 76 | 75 | ||
| 77 | static int findReserved (char *name) | 76 | void luaI_addReserved (void) |
| 78 | { | 77 | { |
| 79 | int l = 0; | 78 | int i; |
| 80 | int h = RESERVEDSIZE - 1; | 79 | for (i=0; i<RESERVEDSIZE; i++) |
| 81 | while (l <= h) | ||
| 82 | { | 80 | { |
| 83 | int m = (l+h)/2; | 81 | TaggedString *ts = lua_createstring(reserved[i].name); |
| 84 | int comp = lua_strcmp(name, reserved[m].name); | 82 | ts->marked = reserved[i].token; /* reserved word (always > 255) */ |
| 85 | if (comp < 0) | ||
| 86 | h = m-1; | ||
| 87 | else if (comp == 0) | ||
| 88 | return reserved[m].token; | ||
| 89 | else | ||
| 90 | l = m+1; | ||
| 91 | } | 83 | } |
| 92 | return 0; | ||
| 93 | } | 84 | } |
| 94 | 85 | ||
| 95 | 86 | ||
| @@ -282,12 +273,14 @@ int luaY_lex (void) | |||
| 282 | case 'Z': | 273 | case 'Z': |
| 283 | case '_': | 274 | case '_': |
| 284 | { | 275 | { |
| 285 | Word res; | 276 | TaggedString *ts; |
| 286 | do { save_and_next(); } while (isalnum(current) || current == '_'); | 277 | do { save_and_next(); } while (isalnum(current) || current == '_'); |
| 287 | *yytextLast = 0; | 278 | *yytextLast = 0; |
| 288 | res = findReserved(yytext); | 279 | ts = lua_createstring(yytext); |
| 289 | if (res) return res; | 280 | if (ts->marked > 2) |
| 290 | luaY_lval.pTStr = luaI_createfixedstring(yytext); | 281 | return ts->marked; /* reserved word */ |
| 282 | luaY_lval.pTStr = ts; | ||
| 283 | ts->marked = 2; /* avoid GC */ | ||
| 291 | return NAME; | 284 | return NAME; |
| 292 | } | 285 | } |
| 293 | 286 | ||
