Grammar: http://pastebin.com/ef2jt8Rg
y.output: http://pastebin.com/AEKXrrRG
I don’t know where is those conflicts, someone can help me with this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The y.output file tells you exactly where the conflicts are. The first one is in state 4, so if you go down to look at state 4, you see:
This is telling you that in this state (parsing a
compound_statement, having seen a{), and looking at the next token beingIDENTIFIER, there are 3 possible things it could do — shift the token (which would be the beginning of astatement_list), reduce thethreat_as_refempty production, or reduce thefunc_call_startempty production.The brackets tell you that it has decided to never do those actions — the default “prefer shift over reduce” conflict resolution means that it will always do the shift.
The problem with your grammar is these empty rules
threat_as_refandfunc_call_start— they need to be reduced BEFORE shifting the IDENTIFIER, but in order to know if they’re valid, the parser would need to see the tokens AFTER the identifer.func_call_startshould only be reduced if this is the beginning of the function call (which depends on there being a(after the IDENTIFIER.) So the parser needs more lookahead to deal with your gramar. In your specific case, you grammar is LALR(2) (2 token lookahead would suffice), but not LALR(1), so bison can’t deal with it.Now you could fix it by just getting rid of those empty rules —
func_call_starthas no action at all, and the action forthreat_as_refcould be moved into the action forvariable, but if you want those rules in the future that may be a problem.