Bison 野牛转移减少冲突

Bison 野牛转移减少冲突,bison,Bison,我正在使用野牛和我的CFG有一个移位减少冲突,这是搞砸了我的优先权 这是我的代码: Decl : vartype T_Identifier T_Semicolon { // replace it with your implementation Identifier *id = new Identifier

我正在使用野牛和我的CFG有一个移位减少冲突,这是搞砸了我的优先权

这是我的代码:

Decl      :  vartype T_Identifier T_Semicolon {
                                             // replace it with your implementation
                                             Identifier *id = new Identifier(@2, $2);
                                             $$ = new VarDecl(id, $1);
                                          }
      |  vartype T_Identifier T_Equal primaryExpr T_Semicolon {
                                                    Identifier *id = new Identifier(@2, $2);
                                                    $$ = new VarDecl(id, $1, $4);
                            }

      |  function_prototype T_Semicolon {$$ = $1;}
      ; 
对于这一特殊规则,我有一个减少冲突的方法。我希望最后一行(function_prototype…)具有最高优先级,但冲突会转移并将我发送到另一个状态。仅供参考,“function_prototype”是一个非终结符,其规则为“vartype T_Identifier T_LeftParenth”。这是bison的输出文件:

State 28 conflicts: 1 shift/reduce
...
state 28

    4 Decl: vartype . T_Identifier T_Semicolon
    5     | vartype . T_Identifier T_Equal primaryExpr T_Semicolon
   11 fully_specified_type: vartype .

    T_Identifier  shift, and go to state 34

    T_Identifier  [reduce using rule 11 (fully_specified_type)]
...
state 34

    4 Decl: vartype T_Identifier . T_Semicolon
    5     | vartype T_Identifier . T_Equal primaryExpr T_Semicolon

    T_Equal      shift, and go to state 36
    T_Semicolon  shift, and go to state 37 

状态34跳过我的“函数原型”规则!如何解决此冲突和优先级问题?

冲突发生在
Decl:vartype
之间。。。规则和
完全指定的\u类型:vartype
规则——在看到
vartype
后,当前瞻是
T\u标识符
时,它不知道这是否是
完全指定的类型
。因此它会移动(默认分辨率),将其视为
Decl
的简单
vartype

一般来说,这类事情通常是一个问题,需要多个token lookahead才能知道如何解析事情,但是由于您没有显示与
完全指定的类型规则相关的任何内容,因此很难说如何修复它。最有可能的是有一种方法可以重构你的语法(也许只是去掉
完全限定的类型
,直接使用
vartype