On 4 Mar 2007, at 21:34, Abdelmalek Halawani wrote:
I would like to create a parser that reads the following input:
a = 1; b = 2; c = 3; d = 0;
y = a + b * c + d;
And outputs:
temp1 = b * c;
temp1 = 6;
temp2 = temp1 + d;
y = a + temp2;
y = 7;
I am not sure exactly what you want, but an operator expression can
be computed by using two stacks, one for values and one for
operators. Add an end-marker to the expression. When a value comes
by, put it onto the values stack, when an operators comes by, check
it against the operator on the stack, and compute if the precedence
is higher, otherwise stack it on the operator stack. When the end-of
the expression comes by, compute the rest. With this technique in
hand, it is easy to convert to say RPN, if that is what you want.
Your temporary registers will be the value stack.
Hans Aberg
_______________________________________________
help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison