return n;
}
-/* if not found, variable with value "" is created */
+/* return var struct or NULL if not found */
+struct variable*
+get_var_struct(char* name, enum var_type type, struct list* hash)
+{
+ int n;
+ struct variable *p;
+
+ n = get_bucket_number(name);
+ LIST_FOREACH(p, hash + n)
+ if (!strcasecmp(p->name, name) && p->type == type)
+ return p;
+
+ return NULL;
+}
+
int
-find_var(char* name, struct list* hash)
+find_var(char* name, enum var_type type, struct list* hash)
{
int n;
struct variable *p;
n = get_bucket_number(name);
- int nocase = isupper(*name);
LIST_FOREACH(p, hash + n)
- if (!(nocase ? strcasecmp : strcmp)(p->name,name))
+ if (!strcasecmp(p->name, name) && p->type == type)
return p->varcode;
p = xmalloc(sizeof(struct variable));
p->name = xstrdup(name);
p->varcode = current_varcode++;
+ p->type = type;
list_add_last(hash+n, &p->car);
return p->varcode;
{
if (t->st == ST_LEAF) {
return t->pt.leaf.n;
- } else if (t->st == ST_OP) {
- int left, right;
- left = evaluate(t->pt.op.left, -1, where);
- right = evaluate(t->pt.op.right, -1, where);
- switch (t->pt.op.op) {
- case '.':
- return new_3par_instr(OPC_CAT, left,
- right, pref_var, where);
- break;
- case '+':
- return new_3par_instr(OPC_PLUS, left,
- right, pref_var, where);
- break;
- case '-':
- return new_3par_instr(OPC_MINUS, left,
- right, pref_var, where);
- break;
- case '*':
- return new_3par_instr(OPC_MUL, left,
- right, pref_var, where);
- break;
- case '/':
- return new_3par_instr(OPC_DIV, left,
- right, pref_var, where);
- break;
- default:
- die("evaluate: got to default");
- }
- } else
- die("evaluate: I can evaluate only expressions but I got %d",
- t->st);
+ }
+ int left, right;
+ left = evaluate(t->pt.op.left, -1, where);
+ right = evaluate(t->pt.op.right, -1, where);
+ switch (t->pt.op.op) {
+ case '.':
+ return new_3par_instr(OPC_CAT, left,
+ right, pref_var, where);
+ break;
+ case '+':
+ return new_3par_instr(OPC_PLUS, left,
+ right, pref_var, where);
+ break;
+ case '-':
+ return new_3par_instr(OPC_MINUS, left,
+ right, pref_var, where);
+ break;
+ case '*':
+ return new_3par_instr(OPC_MUL, left,
+ right, pref_var, where);
+ break;
+ case '/':
+ return new_3par_instr(OPC_DIV, left,
+ right, pref_var, where);
+ break;
+ }
+ die("evaluate: Never can get here :)");
}
static void
case K_DISCARD:
ins.opcode = OPC_DISCARD;
break;
+ case K_FILTER:
+ ins.opcode = OPC_FILTER;
+ break;
default:
die("do_arrow: This cannot happen ;-)");
}
static void
reset_temp_var_count(void)
{
+ if (current_varcode > max_varcode)
+ max_varcode = current_varcode;
current_varcode = temp_varcode_start;
}
case OPC_PIPE:
printf("PIPE %d %d\n", p->u.arrow.what, p->u.arrow.copy);
break;
+ case OPC_FILTER:
+ printf("FILTER %d %d\n", p->u.arrow.what, p->u.arrow.copy);
+ break;
case OPC_DELIVER:
printf("DELIVER %d %d\n", p->u.arrow.what, p->u.arrow.copy);
break;