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

--
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 https://groups.google.com/groups/opt_out.


Reply via email to