Unable to figure out what causes shift / decrease errors in yacc

I am working on a project in yacc and getting a shift / reduce error, but I can’t understand why I get it. I was looking at the y.output file, but not quite sure how to read it. My y.output file exceeds the character limit on SO, so I dropped it on pastebin: http://pastebin.com/AQ2UtAip . Any ideas on how to fix this?

+4
source share
3 answers

I'm not quite sure, but I think the problem is that after seeing the T_Identifier at the beginning of StmtBlock , the parser cannot determine if it sees VariableDecl or Expr with only one sign of a look. If you can change the language specification, one simple fix will require a keyword like var before declaring the variable.

+2
source

I'm not quite sure, but I think the problem is here: VariableDeclList: VariableDeclList VariableDecl When you discover something that may be a VariableDeclList , it can recursively follow the VariableDeclList until the end of the stack. Try replacing the VariableDeclList order with VariableDecl ?

0
source

Try to fix or use Epsilon differently. I suspect that VariableDeclList is decreasing, and now he does not know whether StmtList needs to reduce StmtList first before executing Stmt or not decreasing it and using VariableDecl. I know that VariableDeclList is not a problem, because you do it in both rules, however now StmtList can be reduced before knowing which rule to follow, which is a problem (because not all rules reduce it in the same place / ok).

 state 74 38 StmtBlock: '{' VariableDeclList . StmtList '}' 39 VariableDeclList: VariableDeclList . VariableDecl StmtList: StmtList Stmt | Epsilon 
0
source

Source: https://habr.com/ru/post/1338593/


All Articles