开发者

LR Parsing for arithmetic expressions

I have got LR grammar and LR table for expressions like (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
                        };

I try to check expression like 1+1 or 1+(1*a)+1 but parser says that this expression is incorrect.

What can I do with my grammar to fix it?


You don't have a production rule for numbers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜