ref: de55e87b768afada683c7203c451ff9f2975d085
parent: efb9d623ed24a601a5e82ba5ccf117251a94d974
author: Roberto E. Vargas Caballero <[email protected]>
date: Sun Oct 6 07:42:00 EDT 2013
Insert constant in table symbol without string It is important don't store the string of the numerical constant in the symbol table, because different numbers using different bases can have the same textual representation. This change implies you are always to alloc symbols for numerical constant, but it is not a big penalty at all.
--- a/lex.c
+++ b/lex.c
@@ -58,11 +58,7 @@
error("identifier too long %s", yytext);
*bp = '\0';
ungetc(ch, yyin);
-
- /*
- * TODO: insert always. don't depend of the base and check size
- */
- yyval.sym = lookup(yytext, NS_ANY);
+ yyval.sym = lookup(NULL, NS_ANY);
yyval.sym->val = strtol(yytext, NULL, base);
return CONSTANT;
--- a/symbol.c
+++ b/symbol.c
@@ -68,6 +68,13 @@
register struct symbol *sym;
static unsigned char key, l, ins;
+
+ if (s == NULL) {
+ sym = xmalloc(sizeof(*sym));
+ sym->next = head;
+ return sym;
+ }
+
l = strlen(s);
key = hash(s);
if (!(ins = ns >= 0))