ref: 2630b2abf0a6fb9c78352f7bea6d19f4bcfaa57c
parent: 8b6cc849d8e198cfa639b4de3ad84a22f2d36e07
author: Roberto E. Vargas Caballero <[email protected]>
date: Sun Jun 10 16:15:08 EDT 2012
Install symbols for integer constant This patch install a symbol for each constant that there is in the code. This symbol will be used later in the parser like attribute of the node into the parser tree.
--- a/lex.c
+++ b/lex.c
@@ -24,6 +24,7 @@
{
register char *bp;
register char ch;
+ register struct symbol *sym;
for (bp = yytext; bp < yytext + TOKSIZ_MAX; *bp++ = ch) {
if (!isdigit(ch = getc(yyin)))
@@ -33,6 +34,9 @@
error("identifier too long %s", yytext);
*bp = '\0';
ungetc(ch, yyin);
+ yyval.sym = sym = install(NULL, 0);
+ sym->val = atoi(yytext);
+ sym->type = T_INT;
return CONSTANT;
}
--- a/symbol.c
+++ b/symbol.c
@@ -58,8 +58,8 @@
if (s) {
sym->str = xstrdup(s);
-
- head = &iden_hash.buf[key], next = head->h_next;
+ head = &iden_hash.buf[key & NR_SYM_HASH-1];
+ next = head->h_next;
sym->h_next = next;
sym->h_prev = next->h_prev;
head->h_next = sym;
@@ -75,8 +75,8 @@
{
register struct symbol *bp, *head;
- head = &iden_hash.buf[key];
- for (bp = head->h_next; bp != head; bp = bp->next) {
+ head = &iden_hash.buf[key & NR_SYM_HASH-1];
+ for (bp = head->h_next; bp != head; bp = bp->h_next) {
if (!strcmp(bp->str, s))
return bp;
}
--- a/symbol.h
+++ b/symbol.h
@@ -13,6 +13,7 @@
unsigned char level;
};
unsigned char tok; /* used in keywords */
+ short val;
};
struct symbol *next;
struct symbol *h_next, *h_prev;
@@ -22,7 +23,6 @@
struct symbol *iden;
struct symctx *next;
};
-
extern void new_ctx(struct symctx *ctx);
extern void del_ctx(void);