hi guys,

in the typical calculator example that allows statements like:
 a=2+3
it is fairly easy to parse and interpret code like
 b=a+1
but what if you could assign '+' to a variable:
 p=+
now that a variable could be an number or an operator, it's hard to parse
eg. how can i parse string "a p b" ?  what is the grammar?
is it something like this:
  expr:  variable variable variable
?
after a bit of thought, i wondered whether i could feedback type
information to the lexer
so, when i parse 'a=2+3', i tell the lexer that a is a number
then with input 'b=a+1", the lexer would produce:
 VARIABLE '=' VARIABLE NUMBER '+' LITERAL
(the token NUMBER indicate's the variable's type)
and with input "a p 1", the lexer would produce:
 VARIABLE NUMBER VARIABLE OPERATOR LITERAL

will lookahead make this scheme unworkable?

can i make use of multiple lexer/parsers?

any pointer in the right direction appreciated.


ta, jack


_______________________________________________
help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison

Reply via email to