]> mj.ucw.cz Git - umpf.git/commitdiff
NUM token is dead
authorAnicka Bernathova <anicka@anicka.net>
Thu, 10 Jul 2008 09:12:46 +0000 (11:12 +0200)
committerAnicka Bernathova <anicka@anicka.net>
Thu, 10 Jul 2008 09:12:46 +0000 (11:12 +0200)
Makefile
brum.c
brum.h
cond.y
int.c
lex.c

index 1ae92919d5daa9dd84192d0b23c69a60a9da3913..08c3177ff6df6a53fc3229db1b389bea420fcaf3 100644 (file)
--- 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 06216b6b90406b95ca2ba10afd4b106a1f917e58..2a67c196f33aa8386de06ebf4bc64731e5de60bf 100644 (file)
--- 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 639bb59676cd8822023830c4bb1e3aa623b09966..59c43289c297466f4fc69107d7ad5f6f00523629 100644 (file)
--- 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 a9d28d728719c9e3d8fdd52c196a462dba633deb..7355a429a88bb4b9f4ef9c112fee39f165ab1d8b 100644 (file)
--- 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 0661c4114d1e1928dd1c71f8b6d18c17e1a2ec67..5f0a9366362a74ac1ed0cd75ce973b8792f92282 100644 (file)
--- 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 ae541d95701ad6d67ea7e56c1a5dd0ea26487ee3..8710763bd9417da6dbd4907b84a7ad335707d273 100644 (file)
--- 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 == '$'){