算术表达式的LR分析
本文关键字:LR 分析 表达式 | 更新日期: 2023-09-27 17:58:04
我有LR语法和LR表,用于表达式(1+1)、1+(a+1)
0:E'->E
1:E->E+T
2:E->T
3:T->T*F
4:T->F
5:F->(E)
6:F->id
string[,] ActionTable =
//+ * ( ) id end E T F
{
{"" ,"" ,"S4" ,"" ,"S5" ,"" ,"1" ,"2" ,"3"}, // 0
{"S6" ,"" ,"" ,"" ,"" ,"AC" ,"" ,"" ,"" }, // 1
{"R2" ,"S7" ,"" ,"R2" ,"" ,"R2" ,"" ,"" ,""},//2
{"R4" ,"R4" ,"" ,"R4" ,"" ,"R4" ,"" ,"" ,""}, // 3
{"" ,"" ,"S4" ,"" ,"S5" ,"" ,"8" ,"2" ,"3"}, // 4
{"R6" ,"R6" ,"" ,"R6" ,"" ,"R6" ,"" ,"" ,""}, // 5
{"" ,"" ,"S4" ,"" ,"S5" ,"" ,"" ,"9" ,"3"}, // 6
{"" ,"" ,"S4" ,"" ,"S5" ,"" ,"" ,"" ,"10"},// 7
{"S6" ,"" ,"" ,"S11" ,"" ,"" ,"" ,"" ,""}, // 8
{"R1" ,"S7" ,"" ,"R1" ,"R1" ,"" ,"" ,"" ,""}, // 9
{"R3" ,"R3" ,"" ,"R3" ,"R3" ,"" ,"" ,"" ,""}, //10
{"R5" ,"R5" ,"" ,"R5" ,"R5" ,"" ,"" ,"" ,""} //11
};
我试图检查像1+1或1+(1*a)+1这样的表达式,但解析器说这个表达式不正确。
我能用我的语法做些什么来修正它?
您没有数字的产生式规则。