如何解决yacc中的转移/减少冲突

时间:2016-09-30 11:25:41

标签: parsing yacc shift-reduce-conflict

我的项目中遇到问题(制作迷你C编译器)。

没有错误,我可以扫描和解析迷你C源代码文件。

但在* .output文件中我找到了

State 17 conflicts: 2 shift/reduce
State 19 conflicts: 2 shift/reduce
State 57 conflicts: 8 shift/reduce
State 60 conflicts: 8 shift/reduce
State 61 conflicts: 8 shift/reduce
State 62 conflicts: 8 shift/reduce
State 63 conflicts: 8 shift/reduce
State 96 conflicts: 8 shift/reduce
State 103 conflicts: 10 shift/reduce
State 126 conflicts: 8 shift/reduce
State 130 conflicts: 10 shift/reduce
State 131 conflicts: 10 shift/reduce
State 132 conflicts: 10 shift/reduce
State 133 conflicts: 10 shift/reduce
State 134 conflicts: 10 shift/reduce
State 135 conflicts: 10 shift/reduce
State 136 conflicts: 10 shift/reduce
State 137 conflicts: 10 shift/reduce
State 138 conflicts: 10 shift/reduce
State 139 conflicts: 10 shift/reduce

州154冲突:1班/减少

和州17

4 DECLARATION: INT IDENTIFIER ';' . DECLARATION
6            | INT IDENTIFIER ';' .

INT    shift, and go to state 29
FLOAT  shift, and go to state 30

INT       [reduce using rule 6 (DECLARATION)]
FLOAT     [reduce using rule 6 (DECLARATION)]
$default  reduce using rule 6 (DECLARATION)

DECLARATION  go to state 31

这是我的宣言

的yacc文件
DECLARATION : 
INT IDENTIFIER ';' DECLARATION %prec p10 {
    struct DECLARATION *decl = (struct DECLARATION *) malloc (sizeof (struct DECLARATION));
    decl->t = eInt;
    decl->id = $2;
    decl->prev = $4;
    $$ = decl;
}
|
FLOAT IDENTIFIER ';' DECLARATION {
    struct DECLARATION *decl = (struct DECLARATION *) malloc (sizeof (struct DECLARATION));
    decl->t = eFloat;
    decl->id = $2;
    decl->prev = $4;
    $$ = decl;
}
|
INT IDENTIFIER ';' {
    struct DECLARATION *decl = (struct DECLARATION *) malloc (sizeof (struct DECLARATION));
    decl->t = eInt;
    decl->id = $2;
    decl->prev = NULL;
    $$ = decl;
}
|
FLOAT IDENTIFIER ';' {
    struct DECLARATION *decl = (struct DECLARATION *) malloc (sizeof (struct DECLARATION));
    decl->t = eFloat;
    decl->id = $2;
    decl->prev = NULL;
    $$ = decl;
}
;

0 个答案:

没有答案