1

我的项目(制作迷你 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;
}
;
4

0 回答 0