Alex_Gaynor wrote:
> I've been having some difficulty with a shift/reduce conflict. The
> parser I'm woking on has a syntax that is basically the templates
> sytnax from C++. Therefore I have the following rules, which result
> in a shift/reduce conflict:
>
> expression : expression LESS expression %prec COMPARISON
> expression : template
> template : NAME
> | NAME LESS templates GREATER
> templates : template
> | templates COMMA template
The yacc algorithm needs to have clarity about the direction to go at the end
of a production. Thus
after "NAME" there has to be clarity whether to reduce to 'template' and
'expression', or to
continue with the 'NAME LESS ...' alternative.
Based on LESS (the next token), it cannot make this decision.
A trick that often works is to rewrite the grammar such that the parser can
make a few more steps
before it has to make a decision. For example:
expression : expression LESS expression %prec COMPARISON
| NAME
| NAME LESS templates GREATER
template : NAME
| NAME LESS templates GREATER
templates : template
| templates COMMA template
Whether that actually works here, I don't know, I'd need a complete example and
do some experimenting.
Albert
--
You received this message because you are subscribed to the Google Groups
"ply-hack" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/ply-hack?hl=en.