开发者

Can't figure out what is causing a shift/reduce errors in yacc

开发者 https://www.devze.com 2023-02-09 07:10 出处:网络
I\'m working on a project in yacc and am getting a shift/reduce error but I can\'t figure out why I\'m getting it. I\'ve been looking through the开发者_StackOverflow社区 y.output file but am not quite

I'm working on a project in yacc and am getting a shift/reduce error but I can't figure out why I'm getting it. I've been looking through the开发者_StackOverflow社区 y.output file but am not quite sure how to read it. My y.output file exceeds the character limit on SO so I threw it on pastebin: http://pastebin.com/AQ2UtAip. Any ideas on how to fix this?


I'm not entirely sure, but I think the problem is that upon seeing a T_Identifier at the beginning of a StmtBlock, the parser cannot determine whether it is seeing a VariableDecl or an Expr with only one token of lookahead. If you can change the language spec, one easy fix would be to require a keyword like var before a variable declaration.


I'm not entirely sure, but I think the problem is here: VariableDeclList: VariableDeclList VariableDecl When spotting something that might be a VariableDeclList, it may recursively follow the VariableDeclList until running out of stack. Try swapping the order of VariableDeclList with VariableDecl?


Try fixing or using Epsilon in a different way. I suspect that VariableDeclList gets reduced and now it doesnt know if it needs to reduce StmtList first before doing Stmt or to not reduce it and use VariableDecl. I know VariableDeclList is not the problem because you do it in both rules, however now StmtList could be reduce before knowing which rule to follow which is the problem (because not all rules reduce it at the same place/order).

state 74

   38 StmtBlock: '{' VariableDeclList . StmtList '}'
   39 VariableDeclList: VariableDeclList . VariableDecl


StmtList: StmtList Stmt
        | Epsilon
0

精彩评论

暂无评论...
验证码 换一张
取 消