scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit de55e87b768afada683c7203c451ff9f2975d085
parent efb9d623ed24a601a5e82ba5ccf117251a94d974
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun,  6 Oct 2013 11:42:00 +0200

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.

Diffstat:
lex.c | 6+-----
symbol.c | 7+++++++
2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/lex.c b/lex.c @@ -58,11 +58,7 @@ end: if (bp == yytext + IDENTSIZ) 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; diff --git a/symbol.c b/symbol.c @@ -68,6 +68,13 @@ lookup(register const char *s, signed char ns) 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))