|problem with Bison firstname.lastname@example.org (Stephan Houben) (1999-05-16)|
|From:||Stephan Houben <email@example.com>|
|Date:||16 May 1999 15:23:29 -0400|
|Organization:||Eindhoven University of Technology, The Netherlands|
|Keywords:||parse, yacc, question|
I have a problem with the following Bison grammar.
void yyerror(char *msg)
| expression '\n'
'#' paramlist '=' expression
| '#' paramlist
application: expression expression
This is supposed to handle both "expressions", which have the
form "#\n", "##\n", "###\n", etc., and "definitions", which have
the form "#=##\n", "##=###\n", etc..
However, the resulting program gives a parse error on "##\n", i.e.
basically on any expression except for "#\n".
I suppose the problem is that Bison can't tell by looking at the
start of the input whether it is an expression or a definition.
The only solution I see is to have definitions start with some
other symbol, say'!', but I think that's ugly, so I'd rather avoid that.
Has anyone an idea to get Bison to do what I want?
Thanks in advance,
[Well, the two shift-reduce conflicts that yacc gets should give you a
starting place. The easiest fix is to flatten the grammar, that is, get
rid of the assignment rule:
'#' paramlist '=' expression '\n'
| expression '\n' ;
You also need to fix your application rule which is extremely ambiguous,
application: '#' expression ;
Return to the
Search the comp.compilers archives again.