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
print_tree(input_tree,0);
+ var_hash = new_var_hash();
interp(input_tree);
return 0;
enum {
L_VAR,
L_CONST,
- L_NUM
} type;
- union {
- char* s;
- int n;
- } value;
+ char* value;
} leaf;
struct {
/* 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;
$$->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;
}
;
return res;
}
-int
+static int
get_bucket_number(char* name)
{
unsigned int n = 0;
}
/* value NULL for finding without modyfiing */
-struct variable*
+static struct variable*
find_var(char* name, char* value, struct variable** hash)
{
int n;
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;
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;
}
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 == '$'){