From d4bc03c024891aadf8e963736be114d4d023987f Mon Sep 17 00:00:00 2001 From: Anicka Bernathova Date: Thu, 10 Jul 2008 11:12:46 +0200 Subject: [PATCH] NUM token is dead --- Makefile | 2 +- brum.c | 1 + brum.h | 9 ++++----- cond.y | 13 ++++--------- int.c | 11 ++++------- lex.c | 16 ++++++++++++++-- 6 files changed, 28 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 1ae9291..08c3177 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ all: brum CC=gcc -CFLAGS=-Wall -W -O2 -g +CFLAGS=-Wall -W -Wno-pointer-sign -O2 -g LDLIBS=-lpcre brum: brum.c cond.tab.o int.o lex.o diff --git a/brum.c b/brum.c index 06216b6..2a67c19 100644 --- a/brum.c +++ b/brum.c @@ -14,6 +14,7 @@ main(void) print_tree(input_tree,0); + var_hash = new_var_hash(); interp(input_tree); return 0; diff --git a/brum.h b/brum.h index 639bb59..59c4328 100644 --- a/brum.h +++ b/brum.h @@ -40,12 +40,8 @@ struct tree { enum { L_VAR, L_CONST, - L_NUM } type; - union { - char* s; - int n; - } value; + char* value; } leaf; struct { @@ -73,3 +69,6 @@ int line; /* int.c */ void print_tree(struct tree* t, int ind); void interp(struct tree* t); +struct variable** new_var_hash(void); + +struct variable** var_hash; diff --git a/cond.y b/cond.y index a9d28d7..7355a42 100644 --- a/cond.y +++ b/cond.y @@ -143,26 +143,21 @@ ass: $$->pt.ass.left = tree_malloc(ST_LEAF); $$->pt.ass.left->pt.leaf.type = L_VAR; - $$->pt.ass.left->pt.leaf.value.s = $1; + $$->pt.ass.left->pt.leaf.value = $1; $$->pt.ass.right = $3; } ; -leaves: NUM { - $$ = tree_malloc(ST_LEAF); - $$->pt.leaf.type = L_NUM; - $$->pt.leaf.value.n = $1; - } - | VAR { +leaves: | VAR { $$ = tree_malloc(ST_LEAF); $$->pt.leaf.type = L_VAR; - $$->pt.leaf.value.s = $1; + $$->pt.leaf.value = $1; } | CONST { $$ = tree_malloc(ST_LEAF); $$->pt.leaf.type = L_CONST; - $$->pt.leaf.value.s = $1; + $$->pt.leaf.value = $1; } ; diff --git a/int.c b/int.c index 0661c41..5f0a936 100644 --- a/int.c +++ b/int.c @@ -27,7 +27,7 @@ new_var_hash(void) return res; } -int +static int get_bucket_number(char* name) { unsigned int n = 0; @@ -42,7 +42,7 @@ get_bucket_number(char* name) } /* value NULL for finding without modyfiing */ -struct variable* +static struct variable* find_var(char* name, char* value, struct variable** hash) { int n; @@ -145,10 +145,7 @@ print_tree(struct tree* t, int ind) case L_VAR: putchar('$'); case L_CONST: - puts(t->pt.leaf.value.s); - break; - case L_NUM: - printf("%d\n",t->pt.leaf.value.n); + puts(t->pt.leaf.value); break; } break; @@ -191,7 +188,7 @@ interp(struct tree* t) interp(t->pt.block.tail); break; case ST_ASS: - + // find_name(t->pt.ass.left->pt.leaf.value.s, interp_ass_right(t->pt.ass.right), var_hash); break; } diff --git a/lex.c b/lex.c index ae541d9..8710763 100644 --- a/lex.c +++ b/lex.c @@ -164,8 +164,20 @@ yylex(void) if (c >= '0' && c <= '9'){ ungetc(c,stdin); - scanf("%d",&yylval.n); - return NUM; + int i = 0; + char buf[BUFSIZE]; + + while ((c = getchar())>= '0' && c<= '9'){ + buf[i] = c; + i++; + if (i >= BUFSIZE-1) + parse_err("Too long number"); + } + ungetc(c,stdin); + buf[i] = 0; + yylval.str = xstrdup(buf); + + return CONST; } if (c == '$'){ -- 2.39.2