A.T.Hofkamp
unread,Jul 31, 2012, 3:08:02 AM7/31/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ply-...@googlegroups.com
On 07/12/2012 06:19 PM, Joshua Boshi wrote:
> Below is my sucessfull approach without else-if part (I listed only relevant
> rules):
>
> block_if_statement: RULE_OPEN IF CONDITION RULE_CLOSE statements RULE_OPEN
> END RULE_CLOSE
>
> block_if_statement: RULE_OPEN IF CONDITION RULE_CLOSE statements
> block_else_statement
You didn't say where the conflict happens, bu my guess is here.
After "statements", the RULE_OPEN token decides whether or not it should start a
'block_else_staetment', but it cannot do that since the same token is also in the first rule.
The solution is probably not to make two if statements, but just one, with an 'if' part, optional
'elsif' parts, and finally an optional 'else' part.
BTW is making "(END)" a single token possible? It would make the grammar a lot simpler.
> I think that this is very common problem in parsing and I hope that somebody
> here have already solved it :-)
You have to be careful where to split grammar rules; at the end of a rule the algorithm needs to
make a decision how to continue which may not always be possible.
Otherwise, your problem is very simple in terms of LALR(1).
Albert