问题描述
我已经为解析器设置了规则
%token DIGIT
%token ALPHA
%token IDENT
%token INTEGER
%token REAL
%token BOOLEAN
%token CLASS
%token DOUBLE
%token INT
%token IF
%token ELSE
%token WHILE
%token FOR
%token TRU
%token FALS
%token EXTENDS
%token INSTANCEOF
%token NEW
%token THIS
%token NULLVAL
%token PRIVATE
%token STATIC
%token VOID
%token RETURN
%token SHORT
%token LONG
%token SIGNED
%token UNSIGNED
%token OR
%token AND
%token EQUALS
%token UNEQUAL
%token GR
%token GRE
%token LESS
%token LESSE
%token PLUS
%token MINUS
%token MULTIPLY
%token DIV
%token MOD
%token EQUAL
%token INC
%token DEC
%token NEG
%nonassoc if_prec
%nonassoc ELSE
%right EQUAL INC DEC NEG
%left OR AND EQUALS UNEQUAL GR GRE LESS LESSE INSTANCEOF PLUS MINUS MULTIPLY DIV MOD
%%
File: Decl_Class
Decl_Class: CLASS IDENT '(' EXTENDS IDENT ')' '{' Field '}'
Field: Variable ';'
| Constructor
| Method
Variable: Modifier Expr_type Decl_variables
Decl_variables: Decl_variable | Decl_variable ',' Decl_variables
Decl_variable: IDENT | IDENT EQUAL Expr
Constructor: Modifier IDENT '(' Params ')' '{' Instruction '}'
Method: Modifier '(' Expr_type | VOID ')' IDENT '(' Params')' '{' Instruction '}'
Params: Expr_type IDENT | Expr_type IDENT ',' Params
Modifier: SHORT | LONG | SIGNED | UNSIGNED
Expr_type: BOOLEAN | INT | DOUBLE | IDENT
Expr: INTEGER | REAL | TRU | FALS
| THIS | NULLVAL
| '(' Expr ')'
| Access | Access EQUAL Expr | Access '(' L_Expr ')'
| NEW IDENT '(' L_Expr ')'
| INC Expr | DEC Expr | Expr INC | Expr DEC
| NEG Expr | MINUS Expr | PLUS Expr
| Expr Operator Expr
| '(' Expr_type ')' Expr
| Expr INSTANCEOF Expr_type
Operator: OR | AND | EQUALS | UNEQUAL | GR | GRE | LESS | LESSE | PLUS | MINUS | MULTIPLY | DIV | MOD
Access: IDENT | Expr '.' IDENT
L_Expr: Expr | Expr ',' L_Expr
Instruction: ';'
| Expr';'
| Expr_type Decl_variables';'
| IF '(' Expr ')' Instruction %prec if_prec
| IF '(' Expr ')' Instruction ELSE Instruction
| WHILE '(' Expr ')' Instruction
| FOR '(' L_Expr ';' Expr ';' L_Expr')' Instruction
| FOR '(' Expr_type ')' Decl_variables ';' Expr ';' L_Expr ')' Instruction '{' Instruction '}'
| RETURN Expr ';'
状态 66 冲突:1 次转变/减少 状态 67 冲突:1 次转变/减少 状态 68 冲突:1 次转变/减少 状态 69 冲突:1 次转变/减少 状态 70 冲突:1 次转变/减少 状态 71 冲突:1 减少/减少 状态 109 冲突:17 shift/reduce 状态 110 冲突:1 班/减少 状态 122 冲突:17 shift/reduce
以下是有冲突的状态:
state 66
37 Expr: Expr . INC
38 | Expr . DEC
41 | PLUS Expr .
42 | Expr . Operator Expr
44 | Expr . INSTANCEOF Expr_type
59 Access: Expr . '.' IDENT
'.' shift,and go to state 90
'.' [reduce using rule 41 (Expr)]
$default reduce using rule 41 (Expr)
Operator go to state 91
state 67
37 Expr: Expr . INC
38 | Expr . DEC
40 | MINUS Expr .
42 | Expr . Operator Expr
44 | Expr . INSTANCEOF Expr_type
59 Access: Expr . '.' IDENT
'.' shift,and go to state 90
'.' [reduce using rule 40 (Expr)]
$default reduce using rule 40 (Expr)
Operator go to state 91
state 68
35 Expr: INC Expr .
37 | Expr . INC
38 | Expr . DEC
42 | Expr . Operator Expr
44 | Expr . INSTANCEOF Expr_type
59 Access: Expr . '.' IDENT
INSTANCEOF shift,and go to state 74
OR shift,and go to state 75
AND shift,and go to state 76
EQUALS shift,and go to state 77
UNEQUAL shift,and go to state 78
GR shift,and go to state 79
GRE shift,and go to state 80
LESS shift,and go to state 81
LESSE shift,and go to state 82
PLUS shift,and go to state 83
MINUS shift,and go to state 84
MULTIPLY shift,and go to state 85
DIV shift,and go to state 86
MOD shift,and go to state 87
INC shift,and go to state 88
DEC shift,and go to state 89
'.' shift,and go to state 90
'.' [reduce using rule 35 (Expr)]
$default reduce using rule 35 (Expr)
Operator go to state 91
state 69
36 Expr: DEC Expr .
37 | Expr . INC
38 | Expr . DEC
42 | Expr . Operator Expr
44 | Expr . INSTANCEOF Expr_type
59 Access: Expr . '.' IDENT
INSTANCEOF shift,and go to state 90
'.' [reduce using rule 36 (Expr)]
$default reduce using rule 36 (Expr)
Operator go to state 91
state 109
37 Expr: Expr . INC
38 | Expr . DEC
42 | Expr . Operator Expr
42 | Expr Operator Expr .
44 | Expr . INSTANCEOF Expr_type
59 Access: Expr . '.' IDENT
INSTANCEOF shift,and go to state 90
INSTANCEOF [reduce using rule 42 (Expr)]
OR [reduce using rule 42 (Expr)]
AND [reduce using rule 42 (Expr)]
EQUALS [reduce using rule 42 (Expr)]
UNEQUAL [reduce using rule 42 (Expr)]
GR [reduce using rule 42 (Expr)]
GRE [reduce using rule 42 (Expr)]
LESS [reduce using rule 42 (Expr)]
LESSE [reduce using rule 42 (Expr)]
PLUS [reduce using rule 42 (Expr)]
MINUS [reduce using rule 42 (Expr)]
MULTIPLY [reduce using rule 42 (Expr)]
DIV [reduce using rule 42 (Expr)]
MOD [reduce using rule 42 (Expr)]
INC [reduce using rule 42 (Expr)]
DEC [reduce using rule 42 (Expr)]
'.' [reduce using rule 42 (Expr)]
$default reduce using rule 42 (Expr)
Operator go to state 91
state 110
32 Expr: Access EQUAL Expr .
37 | Expr . INC
38 | Expr . DEC
42 | Expr . Operator Expr
44 | Expr . INSTANCEOF Expr_type
59 Access: Expr . '.' IDENT
INSTANCEOF shift,and go to state 90
'.' [reduce using rule 32 (Expr)]
$default reduce using rule 32 (Expr)
Operator go to state 91
state 122
37 Expr: Expr . INC
38 | Expr . DEC
42 | Expr . Operator Expr
43 | '(' Expr_type ')' Expr .
44 | Expr . INSTANCEOF Expr_type
59 Access: Expr . '.' IDENT
INSTANCEOF shift,and go to state 90
INSTANCEOF [reduce using rule 43 (Expr)]
OR [reduce using rule 43 (Expr)]
AND [reduce using rule 43 (Expr)]
EQUALS [reduce using rule 43 (Expr)]
UNEQUAL [reduce using rule 43 (Expr)]
GR [reduce using rule 43 (Expr)]
GRE [reduce using rule 43 (Expr)]
LESS [reduce using rule 43 (Expr)]
LESSE [reduce using rule 43 (Expr)]
PLUS [reduce using rule 43 (Expr)]
MINUS [reduce using rule 43 (Expr)]
MULTIPLY [reduce using rule 43 (Expr)]
DIV [reduce using rule 43 (Expr)]
MOD [reduce using rule 43 (Expr)]
INC [reduce using rule 43 (Expr)]
DEC [reduce using rule 43 (Expr)]
'.' [reduce using rule 43 (Expr)]
$default reduce using rule 43 (Expr)
Operator go to state 91
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)