diff --git a/Project-02/Source.gv.png b/Project-02/Source.gv.png index a3eb0b2..1154714 100644 Binary files a/Project-02/Source.gv.png and b/Project-02/Source.gv.png differ diff --git a/Project-02/parser.out b/Project-02/parser.out index 2bbd535..c9549bd 100644 --- a/Project-02/parser.out +++ b/Project-02/parser.out @@ -11,8 +11,8 @@ Rule 5 E -> LPAREN E RPAREN Rule 6 E -> CONST Rule 7 E -> ID ASSIGN E Rule 8 E -> E SEMICOLON E -Rule 9 E -> IF LPAREN B RPAREN THEN E ELSE E -Rule 10 E -> WHILE LPAREN B RPAREN DO LBRACE E RBRACE +Rule 9 E -> IF B THEN E ELSE E +Rule 10 E -> WHILE B DO LBRACE E RBRACE Rule 11 A -> E Rule 12 A -> A COMMA E Rule 13 D -> ID LPAREN V RPAREN LBRACE E RBRACE @@ -44,9 +44,9 @@ IN : 1 LBRACE : 10 13 LET : 1 LOP : 20 -LPAREN : 3 5 9 10 13 23 +LPAREN : 3 5 13 23 RBRACE : 10 13 -RPAREN : 3 5 9 10 13 23 +RPAREN : 3 5 13 23 SEMICOLON : 8 THEN : 9 TRUE : 21 @@ -74,8 +74,8 @@ state 0 (6) E -> . CONST (7) E -> . ID ASSIGN E (8) E -> . E SEMICOLON E - (9) E -> . IF LPAREN B RPAREN THEN E ELSE E - (10) E -> . WHILE LPAREN B RPAREN DO LBRACE E RBRACE + (9) E -> . IF B THEN E ELSE E + (10) E -> . WHILE B DO LBRACE E RBRACE LET shift and go to state 2 ID shift and go to state 3 @@ -116,11 +116,13 @@ state 3 SEMICOLON reduce using rule 2 (E -> ID .) $end reduce using rule 2 (E -> ID .) RPAREN reduce using rule 2 (E -> ID .) - COMMA reduce using rule 2 (E -> ID .) EQOP reduce using rule 2 (E -> ID .) COMP reduce using rule 2 (E -> ID .) - LOP reduce using rule 2 (E -> ID .) + COMMA reduce using rule 2 (E -> ID .) ELSE reduce using rule 2 (E -> ID .) + THEN reduce using rule 2 (E -> ID .) + LOP reduce using rule 2 (E -> ID .) + DO reduce using rule 2 (E -> ID .) RBRACE reduce using rule 2 (E -> ID .) LPAREN shift and go to state 12 ASSIGN shift and go to state 13 @@ -137,8 +139,8 @@ state 4 (6) E -> . CONST (7) E -> . ID ASSIGN E (8) E -> . E SEMICOLON E - (9) E -> . IF LPAREN B RPAREN THEN E ELSE E - (10) E -> . WHILE LPAREN B RPAREN DO LBRACE E RBRACE + (9) E -> . IF B THEN E ELSE E + (10) E -> . WHILE B DO LBRACE E RBRACE LET shift and go to state 2 ID shift and go to state 3 @@ -157,27 +159,81 @@ state 5 SEMICOLON reduce using rule 6 (E -> CONST .) $end reduce using rule 6 (E -> CONST .) RPAREN reduce using rule 6 (E -> CONST .) - COMMA reduce using rule 6 (E -> CONST .) EQOP reduce using rule 6 (E -> CONST .) COMP reduce using rule 6 (E -> CONST .) - LOP reduce using rule 6 (E -> CONST .) + COMMA reduce using rule 6 (E -> CONST .) ELSE reduce using rule 6 (E -> CONST .) + THEN reduce using rule 6 (E -> CONST .) + LOP reduce using rule 6 (E -> CONST .) + DO reduce using rule 6 (E -> CONST .) RBRACE reduce using rule 6 (E -> CONST .) state 6 - (9) E -> IF . LPAREN B RPAREN THEN E ELSE E + (9) E -> IF . B THEN E ELSE E + (17) B -> . E EQOP E + (18) B -> . E COMP E + (19) B -> . B EQOP B + (20) B -> . B LOP B + (21) B -> . TRUE + (22) B -> . FALSE + (23) B -> . LPAREN B RPAREN + (1) E -> . LET D IN E + (2) E -> . ID + (3) E -> . ID LPAREN A RPAREN + (4) E -> . E AOP E + (5) E -> . LPAREN E RPAREN + (6) E -> . CONST + (7) E -> . ID ASSIGN E + (8) E -> . E SEMICOLON E + (9) E -> . IF B THEN E ELSE E + (10) E -> . WHILE B DO LBRACE E RBRACE - LPAREN shift and go to state 15 + TRUE shift and go to state 17 + FALSE shift and go to state 18 + LPAREN shift and go to state 19 + LET shift and go to state 2 + ID shift and go to state 3 + CONST shift and go to state 5 + IF shift and go to state 6 + WHILE shift and go to state 7 + B shift and go to state 15 + E shift and go to state 16 state 7 - (10) E -> WHILE . LPAREN B RPAREN DO LBRACE E RBRACE + (10) E -> WHILE . B DO LBRACE E RBRACE + (17) B -> . E EQOP E + (18) B -> . E COMP E + (19) B -> . B EQOP B + (20) B -> . B LOP B + (21) B -> . TRUE + (22) B -> . FALSE + (23) B -> . LPAREN B RPAREN + (1) E -> . LET D IN E + (2) E -> . ID + (3) E -> . ID LPAREN A RPAREN + (4) E -> . E AOP E + (5) E -> . LPAREN E RPAREN + (6) E -> . CONST + (7) E -> . ID ASSIGN E + (8) E -> . E SEMICOLON E + (9) E -> . IF B THEN E ELSE E + (10) E -> . WHILE B DO LBRACE E RBRACE - LPAREN shift and go to state 16 + TRUE shift and go to state 17 + FALSE shift and go to state 18 + LPAREN shift and go to state 19 + LET shift and go to state 2 + ID shift and go to state 3 + CONST shift and go to state 5 + IF shift and go to state 6 + WHILE shift and go to state 7 + B shift and go to state 20 + E shift and go to state 16 state 8 @@ -190,8 +246,8 @@ state 8 (6) E -> . CONST (7) E -> . ID ASSIGN E (8) E -> . E SEMICOLON E - (9) E -> . IF LPAREN B RPAREN THEN E ELSE E - (10) E -> . WHILE LPAREN B RPAREN DO LBRACE E RBRACE + (9) E -> . IF B THEN E ELSE E + (10) E -> . WHILE B DO LBRACE E RBRACE LET shift and go to state 2 ID shift and go to state 3 @@ -200,7 +256,7 @@ state 8 IF shift and go to state 6 WHILE shift and go to state 7 - E shift and go to state 17 + E shift and go to state 21 state 9 @@ -213,8 +269,8 @@ state 9 (6) E -> . CONST (7) E -> . ID ASSIGN E (8) E -> . E SEMICOLON E - (9) E -> . IF LPAREN B RPAREN THEN E ELSE E - (10) E -> . WHILE LPAREN B RPAREN DO LBRACE E RBRACE + (9) E -> . IF B THEN E ELSE E + (10) E -> . WHILE B DO LBRACE E RBRACE LET shift and go to state 2 ID shift and go to state 3 @@ -223,7 +279,7 @@ state 9 IF shift and go to state 6 WHILE shift and go to state 7 - E shift and go to state 18 + E shift and go to state 22 state 10 @@ -232,16 +288,16 @@ state 10 (13) D -> . ID LPAREN V RPAREN LBRACE E RBRACE (14) D -> . D D - IN shift and go to state 20 + IN shift and go to state 24 ID shift and go to state 11 - D shift and go to state 19 + D shift and go to state 23 state 11 (13) D -> ID . LPAREN V RPAREN LBRACE E RBRACE - LPAREN shift and go to state 21 + LPAREN shift and go to state 25 state 12 @@ -257,8 +313,8 @@ state 12 (6) E -> . CONST (7) E -> . ID ASSIGN E (8) E -> . E SEMICOLON E - (9) E -> . IF LPAREN B RPAREN THEN E ELSE E - (10) E -> . WHILE LPAREN B RPAREN DO LBRACE E RBRACE + (9) E -> . IF B THEN E ELSE E + (10) E -> . WHILE B DO LBRACE E RBRACE LET shift and go to state 2 ID shift and go to state 3 @@ -267,8 +323,8 @@ state 12 IF shift and go to state 6 WHILE shift and go to state 7 - A shift and go to state 22 - E shift and go to state 23 + A shift and go to state 26 + E shift and go to state 27 state 13 @@ -281,8 +337,8 @@ state 13 (6) E -> . CONST (7) E -> . ID ASSIGN E (8) E -> . E SEMICOLON E - (9) E -> . IF LPAREN B RPAREN THEN E ELSE E - (10) E -> . WHILE LPAREN B RPAREN DO LBRACE E RBRACE + (9) E -> . IF B THEN E ELSE E + (10) E -> . WHILE B DO LBRACE E RBRACE LET shift and go to state 2 ID shift and go to state 3 @@ -291,7 +347,7 @@ state 13 IF shift and go to state 6 WHILE shift and go to state 7 - E shift and go to state 24 + E shift and go to state 28 state 14 @@ -299,231 +355,59 @@ state 14 (4) E -> E . AOP E (8) E -> E . SEMICOLON E - RPAREN shift and go to state 25 + RPAREN shift and go to state 29 AOP shift and go to state 8 SEMICOLON shift and go to state 9 state 15 - (9) E -> IF LPAREN . B RPAREN THEN E ELSE E - (17) B -> . E EQOP E - (18) B -> . E COMP E - (19) B -> . B EQOP B - (20) B -> . B LOP B - (21) B -> . TRUE - (22) B -> . FALSE - (23) B -> . LPAREN B RPAREN - (1) E -> . LET D IN E - (2) E -> . ID - (3) E -> . ID LPAREN A RPAREN - (4) E -> . E AOP E - (5) E -> . LPAREN E RPAREN - (6) E -> . CONST - (7) E -> . ID ASSIGN E - (8) E -> . E SEMICOLON E - (9) E -> . IF LPAREN B RPAREN THEN E ELSE E - (10) E -> . WHILE LPAREN B RPAREN DO LBRACE E RBRACE + (9) E -> IF B . THEN E ELSE E + (19) B -> B . EQOP B + (20) B -> B . LOP B - TRUE shift and go to state 29 - FALSE shift and go to state 30 - LPAREN shift and go to state 26 - LET shift and go to state 2 - ID shift and go to state 3 - CONST shift and go to state 5 - IF shift and go to state 6 - WHILE shift and go to state 7 + THEN shift and go to state 30 + EQOP shift and go to state 31 + LOP shift and go to state 32 - B shift and go to state 27 - E shift and go to state 28 state 16 - (10) E -> WHILE LPAREN . B RPAREN DO LBRACE E RBRACE - (17) B -> . E EQOP E - (18) B -> . E COMP E - (19) B -> . B EQOP B - (20) B -> . B LOP B - (21) B -> . TRUE - (22) B -> . FALSE - (23) B -> . LPAREN B RPAREN - (1) E -> . LET D IN E - (2) E -> . ID - (3) E -> . ID LPAREN A RPAREN - (4) E -> . E AOP E - (5) E -> . LPAREN E RPAREN - (6) E -> . CONST - (7) E -> . ID ASSIGN E - (8) E -> . E SEMICOLON E - (9) E -> . IF LPAREN B RPAREN THEN E ELSE E - (10) E -> . WHILE LPAREN B RPAREN DO LBRACE E RBRACE - - TRUE shift and go to state 29 - FALSE shift and go to state 30 - LPAREN shift and go to state 26 - LET shift and go to state 2 - ID shift and go to state 3 - CONST shift and go to state 5 - IF shift and go to state 6 - WHILE shift and go to state 7 - - B shift and go to state 31 - E shift and go to state 28 - -state 17 - - (4) E -> E AOP E . + (17) B -> E . EQOP E + (18) B -> E . COMP E (4) E -> E . AOP E (8) E -> E . SEMICOLON E - AOP reduce using rule 4 (E -> E AOP E .) - SEMICOLON reduce using rule 4 (E -> E AOP E .) - $end reduce using rule 4 (E -> E AOP E .) - RPAREN reduce using rule 4 (E -> E AOP E .) - COMMA reduce using rule 4 (E -> E AOP E .) - EQOP reduce using rule 4 (E -> E AOP E .) - COMP reduce using rule 4 (E -> E AOP E .) - LOP reduce using rule 4 (E -> E AOP E .) - ELSE reduce using rule 4 (E -> E AOP E .) - RBRACE reduce using rule 4 (E -> E AOP E .) + EQOP shift and go to state 33 + COMP shift and go to state 34 + AOP shift and go to state 8 + SEMICOLON shift and go to state 9 - ! AOP [ shift and go to state 8 ] - ! SEMICOLON [ shift and go to state 9 ] + +state 17 + + (21) B -> TRUE . + + THEN reduce using rule 21 (B -> TRUE .) + EQOP reduce using rule 21 (B -> TRUE .) + LOP reduce using rule 21 (B -> TRUE .) + DO reduce using rule 21 (B -> TRUE .) + RPAREN reduce using rule 21 (B -> TRUE .) state 18 - (8) E -> E SEMICOLON E . - (4) E -> E . AOP E - (8) E -> E . SEMICOLON E + (22) B -> FALSE . - ! shift/reduce conflict for AOP resolved as shift - ! shift/reduce conflict for SEMICOLON resolved as shift - $end reduce using rule 8 (E -> E SEMICOLON E .) - RPAREN reduce using rule 8 (E -> E SEMICOLON E .) - COMMA reduce using rule 8 (E -> E SEMICOLON E .) - EQOP reduce using rule 8 (E -> E SEMICOLON E .) - COMP reduce using rule 8 (E -> E SEMICOLON E .) - LOP reduce using rule 8 (E -> E SEMICOLON E .) - ELSE reduce using rule 8 (E -> E SEMICOLON E .) - RBRACE reduce using rule 8 (E -> E SEMICOLON E .) - AOP shift and go to state 8 - SEMICOLON shift and go to state 9 - - ! AOP [ reduce using rule 8 (E -> E SEMICOLON E .) ] - ! SEMICOLON [ reduce using rule 8 (E -> E SEMICOLON E .) ] + THEN reduce using rule 22 (B -> FALSE .) + EQOP reduce using rule 22 (B -> FALSE .) + LOP reduce using rule 22 (B -> FALSE .) + DO reduce using rule 22 (B -> FALSE .) + RPAREN reduce using rule 22 (B -> FALSE .) state 19 - (14) D -> D D . - (14) D -> D . D - (13) D -> . ID LPAREN V RPAREN LBRACE E RBRACE - (14) D -> . D D - - ! shift/reduce conflict for ID resolved as shift - IN reduce using rule 14 (D -> D D .) - ID shift and go to state 11 - - ! ID [ reduce using rule 14 (D -> D D .) ] - - D shift and go to state 19 - -state 20 - - (1) E -> LET D IN . E - (1) E -> . LET D IN E - (2) E -> . ID - (3) E -> . ID LPAREN A RPAREN - (4) E -> . E AOP E - (5) E -> . LPAREN E RPAREN - (6) E -> . CONST - (7) E -> . ID ASSIGN E - (8) E -> . E SEMICOLON E - (9) E -> . IF LPAREN B RPAREN THEN E ELSE E - (10) E -> . WHILE LPAREN B RPAREN DO LBRACE E RBRACE - - LET shift and go to state 2 - ID shift and go to state 3 - LPAREN shift and go to state 4 - CONST shift and go to state 5 - IF shift and go to state 6 - WHILE shift and go to state 7 - - E shift and go to state 32 - -state 21 - - (13) D -> ID LPAREN . V RPAREN LBRACE E RBRACE - (15) V -> . ID - (16) V -> . V COMMA ID - - ID shift and go to state 33 - - V shift and go to state 34 - -state 22 - - (3) E -> ID LPAREN A . RPAREN - (12) A -> A . COMMA E - - RPAREN shift and go to state 35 - COMMA shift and go to state 36 - - -state 23 - - (11) A -> E . - (4) E -> E . AOP E - (8) E -> E . SEMICOLON E - - RPAREN reduce using rule 11 (A -> E .) - COMMA reduce using rule 11 (A -> E .) - AOP shift and go to state 8 - SEMICOLON shift and go to state 9 - - -state 24 - - (7) E -> ID ASSIGN E . - (4) E -> E . AOP E - (8) E -> E . SEMICOLON E - - ! shift/reduce conflict for AOP resolved as shift - ! shift/reduce conflict for SEMICOLON resolved as shift - $end reduce using rule 7 (E -> ID ASSIGN E .) - RPAREN reduce using rule 7 (E -> ID ASSIGN E .) - COMMA reduce using rule 7 (E -> ID ASSIGN E .) - EQOP reduce using rule 7 (E -> ID ASSIGN E .) - COMP reduce using rule 7 (E -> ID ASSIGN E .) - LOP reduce using rule 7 (E -> ID ASSIGN E .) - ELSE reduce using rule 7 (E -> ID ASSIGN E .) - RBRACE reduce using rule 7 (E -> ID ASSIGN E .) - AOP shift and go to state 8 - SEMICOLON shift and go to state 9 - - ! AOP [ reduce using rule 7 (E -> ID ASSIGN E .) ] - ! SEMICOLON [ reduce using rule 7 (E -> ID ASSIGN E .) ] - - -state 25 - - (5) E -> LPAREN E RPAREN . - - AOP reduce using rule 5 (E -> LPAREN E RPAREN .) - SEMICOLON reduce using rule 5 (E -> LPAREN E RPAREN .) - $end reduce using rule 5 (E -> LPAREN E RPAREN .) - RPAREN reduce using rule 5 (E -> LPAREN E RPAREN .) - COMMA reduce using rule 5 (E -> LPAREN E RPAREN .) - EQOP reduce using rule 5 (E -> LPAREN E RPAREN .) - COMP reduce using rule 5 (E -> LPAREN E RPAREN .) - LOP reduce using rule 5 (E -> LPAREN E RPAREN .) - ELSE reduce using rule 5 (E -> LPAREN E RPAREN .) - RBRACE reduce using rule 5 (E -> LPAREN E RPAREN .) - - -state 26 - (23) B -> LPAREN . B RPAREN (5) E -> LPAREN . E RPAREN (17) B -> . E EQOP E @@ -541,133 +425,98 @@ state 26 (6) E -> . CONST (7) E -> . ID ASSIGN E (8) E -> . E SEMICOLON E - (9) E -> . IF LPAREN B RPAREN THEN E ELSE E - (10) E -> . WHILE LPAREN B RPAREN DO LBRACE E RBRACE + (9) E -> . IF B THEN E ELSE E + (10) E -> . WHILE B DO LBRACE E RBRACE - TRUE shift and go to state 29 - FALSE shift and go to state 30 - LPAREN shift and go to state 26 + TRUE shift and go to state 17 + FALSE shift and go to state 18 + LPAREN shift and go to state 19 LET shift and go to state 2 ID shift and go to state 3 CONST shift and go to state 5 IF shift and go to state 6 WHILE shift and go to state 7 - B shift and go to state 37 - E shift and go to state 38 + B shift and go to state 35 + E shift and go to state 36 -state 27 +state 20 - (9) E -> IF LPAREN B . RPAREN THEN E ELSE E + (10) E -> WHILE B . DO LBRACE E RBRACE (19) B -> B . EQOP B (20) B -> B . LOP B - RPAREN shift and go to state 39 - EQOP shift and go to state 40 - LOP shift and go to state 41 + DO shift and go to state 37 + EQOP shift and go to state 31 + LOP shift and go to state 32 -state 28 +state 21 - (17) B -> E . EQOP E - (18) B -> E . COMP E + (4) E -> E AOP E . (4) E -> E . AOP E (8) E -> E . SEMICOLON E - EQOP shift and go to state 42 - COMP shift and go to state 43 - AOP shift and go to state 8 - SEMICOLON shift and go to state 9 + AOP reduce using rule 4 (E -> E AOP E .) + SEMICOLON reduce using rule 4 (E -> E AOP E .) + $end reduce using rule 4 (E -> E AOP E .) + RPAREN reduce using rule 4 (E -> E AOP E .) + EQOP reduce using rule 4 (E -> E AOP E .) + COMP reduce using rule 4 (E -> E AOP E .) + COMMA reduce using rule 4 (E -> E AOP E .) + ELSE reduce using rule 4 (E -> E AOP E .) + THEN reduce using rule 4 (E -> E AOP E .) + LOP reduce using rule 4 (E -> E AOP E .) + DO reduce using rule 4 (E -> E AOP E .) + RBRACE reduce using rule 4 (E -> E AOP E .) + + ! AOP [ shift and go to state 8 ] + ! SEMICOLON [ shift and go to state 9 ] -state 29 +state 22 - (21) B -> TRUE . - - RPAREN reduce using rule 21 (B -> TRUE .) - EQOP reduce using rule 21 (B -> TRUE .) - LOP reduce using rule 21 (B -> TRUE .) - - -state 30 - - (22) B -> FALSE . - - RPAREN reduce using rule 22 (B -> FALSE .) - EQOP reduce using rule 22 (B -> FALSE .) - LOP reduce using rule 22 (B -> FALSE .) - - -state 31 - - (10) E -> WHILE LPAREN B . RPAREN DO LBRACE E RBRACE - (19) B -> B . EQOP B - (20) B -> B . LOP B - - RPAREN shift and go to state 44 - EQOP shift and go to state 40 - LOP shift and go to state 41 - - -state 32 - - (1) E -> LET D IN E . + (8) E -> E SEMICOLON E . (4) E -> E . AOP E (8) E -> E . SEMICOLON E ! shift/reduce conflict for AOP resolved as shift ! shift/reduce conflict for SEMICOLON resolved as shift - $end reduce using rule 1 (E -> LET D IN E .) - RPAREN reduce using rule 1 (E -> LET D IN E .) - COMMA reduce using rule 1 (E -> LET D IN E .) - EQOP reduce using rule 1 (E -> LET D IN E .) - COMP reduce using rule 1 (E -> LET D IN E .) - LOP reduce using rule 1 (E -> LET D IN E .) - ELSE reduce using rule 1 (E -> LET D IN E .) - RBRACE reduce using rule 1 (E -> LET D IN E .) + $end reduce using rule 8 (E -> E SEMICOLON E .) + RPAREN reduce using rule 8 (E -> E SEMICOLON E .) + EQOP reduce using rule 8 (E -> E SEMICOLON E .) + COMP reduce using rule 8 (E -> E SEMICOLON E .) + COMMA reduce using rule 8 (E -> E SEMICOLON E .) + ELSE reduce using rule 8 (E -> E SEMICOLON E .) + THEN reduce using rule 8 (E -> E SEMICOLON E .) + LOP reduce using rule 8 (E -> E SEMICOLON E .) + DO reduce using rule 8 (E -> E SEMICOLON E .) + RBRACE reduce using rule 8 (E -> E SEMICOLON E .) AOP shift and go to state 8 SEMICOLON shift and go to state 9 - ! AOP [ reduce using rule 1 (E -> LET D IN E .) ] - ! SEMICOLON [ reduce using rule 1 (E -> LET D IN E .) ] + ! AOP [ reduce using rule 8 (E -> E SEMICOLON E .) ] + ! SEMICOLON [ reduce using rule 8 (E -> E SEMICOLON E .) ] -state 33 +state 23 - (15) V -> ID . + (14) D -> D D . + (14) D -> D . D + (13) D -> . ID LPAREN V RPAREN LBRACE E RBRACE + (14) D -> . D D - RPAREN reduce using rule 15 (V -> ID .) - COMMA reduce using rule 15 (V -> ID .) + ! shift/reduce conflict for ID resolved as shift + IN reduce using rule 14 (D -> D D .) + ID shift and go to state 11 + ! ID [ reduce using rule 14 (D -> D D .) ] -state 34 + D shift and go to state 23 - (13) D -> ID LPAREN V . RPAREN LBRACE E RBRACE - (16) V -> V . COMMA ID +state 24 - RPAREN shift and go to state 45 - COMMA shift and go to state 46 - - -state 35 - - (3) E -> ID LPAREN A RPAREN . - - AOP reduce using rule 3 (E -> ID LPAREN A RPAREN .) - SEMICOLON reduce using rule 3 (E -> ID LPAREN A RPAREN .) - $end reduce using rule 3 (E -> ID LPAREN A RPAREN .) - RPAREN reduce using rule 3 (E -> ID LPAREN A RPAREN .) - COMMA reduce using rule 3 (E -> ID LPAREN A RPAREN .) - EQOP reduce using rule 3 (E -> ID LPAREN A RPAREN .) - COMP reduce using rule 3 (E -> ID LPAREN A RPAREN .) - LOP reduce using rule 3 (E -> ID LPAREN A RPAREN .) - ELSE reduce using rule 3 (E -> ID LPAREN A RPAREN .) - RBRACE reduce using rule 3 (E -> ID LPAREN A RPAREN .) - - -state 36 - - (12) A -> A COMMA . E + (1) E -> LET D IN . E (1) E -> . LET D IN E (2) E -> . ID (3) E -> . ID LPAREN A RPAREN @@ -676,8 +525,8 @@ state 36 (6) E -> . CONST (7) E -> . ID ASSIGN E (8) E -> . E SEMICOLON E - (9) E -> . IF LPAREN B RPAREN THEN E ELSE E - (10) E -> . WHILE LPAREN B RPAREN DO LBRACE E RBRACE + (9) E -> . IF B THEN E ELSE E + (10) E -> . WHILE B DO LBRACE E RBRACE LET shift and go to state 2 ID shift and go to state 3 @@ -686,42 +535,106 @@ state 36 IF shift and go to state 6 WHILE shift and go to state 7 - E shift and go to state 47 + E shift and go to state 38 -state 37 +state 25 - (23) B -> LPAREN B . RPAREN - (19) B -> B . EQOP B - (20) B -> B . LOP B + (13) D -> ID LPAREN . V RPAREN LBRACE E RBRACE + (15) V -> . ID + (16) V -> . V COMMA ID - RPAREN shift and go to state 48 - EQOP shift and go to state 40 - LOP shift and go to state 41 + ID shift and go to state 39 + + V shift and go to state 40 + +state 26 + + (3) E -> ID LPAREN A . RPAREN + (12) A -> A . COMMA E + + RPAREN shift and go to state 41 + COMMA shift and go to state 42 -state 38 +state 27 - (5) E -> LPAREN E . RPAREN - (17) B -> E . EQOP E - (18) B -> E . COMP E + (11) A -> E . (4) E -> E . AOP E (8) E -> E . SEMICOLON E - RPAREN shift and go to state 25 - EQOP shift and go to state 42 - COMP shift and go to state 43 + RPAREN reduce using rule 11 (A -> E .) + COMMA reduce using rule 11 (A -> E .) AOP shift and go to state 8 SEMICOLON shift and go to state 9 -state 39 +state 28 - (9) E -> IF LPAREN B RPAREN . THEN E ELSE E + (7) E -> ID ASSIGN E . + (4) E -> E . AOP E + (8) E -> E . SEMICOLON E - THEN shift and go to state 49 + ! shift/reduce conflict for AOP resolved as shift + ! shift/reduce conflict for SEMICOLON resolved as shift + $end reduce using rule 7 (E -> ID ASSIGN E .) + RPAREN reduce using rule 7 (E -> ID ASSIGN E .) + EQOP reduce using rule 7 (E -> ID ASSIGN E .) + COMP reduce using rule 7 (E -> ID ASSIGN E .) + COMMA reduce using rule 7 (E -> ID ASSIGN E .) + ELSE reduce using rule 7 (E -> ID ASSIGN E .) + THEN reduce using rule 7 (E -> ID ASSIGN E .) + LOP reduce using rule 7 (E -> ID ASSIGN E .) + DO reduce using rule 7 (E -> ID ASSIGN E .) + RBRACE reduce using rule 7 (E -> ID ASSIGN E .) + AOP shift and go to state 8 + SEMICOLON shift and go to state 9 + + ! AOP [ reduce using rule 7 (E -> ID ASSIGN E .) ] + ! SEMICOLON [ reduce using rule 7 (E -> ID ASSIGN E .) ] -state 40 +state 29 + + (5) E -> LPAREN E RPAREN . + + AOP reduce using rule 5 (E -> LPAREN E RPAREN .) + SEMICOLON reduce using rule 5 (E -> LPAREN E RPAREN .) + $end reduce using rule 5 (E -> LPAREN E RPAREN .) + RPAREN reduce using rule 5 (E -> LPAREN E RPAREN .) + EQOP reduce using rule 5 (E -> LPAREN E RPAREN .) + COMP reduce using rule 5 (E -> LPAREN E RPAREN .) + COMMA reduce using rule 5 (E -> LPAREN E RPAREN .) + ELSE reduce using rule 5 (E -> LPAREN E RPAREN .) + THEN reduce using rule 5 (E -> LPAREN E RPAREN .) + LOP reduce using rule 5 (E -> LPAREN E RPAREN .) + DO reduce using rule 5 (E -> LPAREN E RPAREN .) + RBRACE reduce using rule 5 (E -> LPAREN E RPAREN .) + + +state 30 + + (9) E -> IF B THEN . E ELSE E + (1) E -> . LET D IN E + (2) E -> . ID + (3) E -> . ID LPAREN A RPAREN + (4) E -> . E AOP E + (5) E -> . LPAREN E RPAREN + (6) E -> . CONST + (7) E -> . ID ASSIGN E + (8) E -> . E SEMICOLON E + (9) E -> . IF B THEN E ELSE E + (10) E -> . WHILE B DO LBRACE E RBRACE + + LET shift and go to state 2 + ID shift and go to state 3 + LPAREN shift and go to state 4 + CONST shift and go to state 5 + IF shift and go to state 6 + WHILE shift and go to state 7 + + E shift and go to state 43 + +state 31 (19) B -> B EQOP . B (17) B -> . E EQOP E @@ -739,22 +652,22 @@ state 40 (6) E -> . CONST (7) E -> . ID ASSIGN E (8) E -> . E SEMICOLON E - (9) E -> . IF LPAREN B RPAREN THEN E ELSE E - (10) E -> . WHILE LPAREN B RPAREN DO LBRACE E RBRACE + (9) E -> . IF B THEN E ELSE E + (10) E -> . WHILE B DO LBRACE E RBRACE - TRUE shift and go to state 29 - FALSE shift and go to state 30 - LPAREN shift and go to state 26 + TRUE shift and go to state 17 + FALSE shift and go to state 18 + LPAREN shift and go to state 19 LET shift and go to state 2 ID shift and go to state 3 CONST shift and go to state 5 IF shift and go to state 6 WHILE shift and go to state 7 - B shift and go to state 50 - E shift and go to state 28 + B shift and go to state 44 + E shift and go to state 16 -state 41 +state 32 (20) B -> B LOP . B (17) B -> . E EQOP E @@ -772,22 +685,22 @@ state 41 (6) E -> . CONST (7) E -> . ID ASSIGN E (8) E -> . E SEMICOLON E - (9) E -> . IF LPAREN B RPAREN THEN E ELSE E - (10) E -> . WHILE LPAREN B RPAREN DO LBRACE E RBRACE + (9) E -> . IF B THEN E ELSE E + (10) E -> . WHILE B DO LBRACE E RBRACE - TRUE shift and go to state 29 - FALSE shift and go to state 30 - LPAREN shift and go to state 26 + TRUE shift and go to state 17 + FALSE shift and go to state 18 + LPAREN shift and go to state 19 LET shift and go to state 2 ID shift and go to state 3 CONST shift and go to state 5 IF shift and go to state 6 WHILE shift and go to state 7 - B shift and go to state 51 - E shift and go to state 28 + B shift and go to state 45 + E shift and go to state 16 -state 42 +state 33 (17) B -> E EQOP . E (1) E -> . LET D IN E @@ -798,8 +711,147 @@ state 42 (6) E -> . CONST (7) E -> . ID ASSIGN E (8) E -> . E SEMICOLON E - (9) E -> . IF LPAREN B RPAREN THEN E ELSE E - (10) E -> . WHILE LPAREN B RPAREN DO LBRACE E RBRACE + (9) E -> . IF B THEN E ELSE E + (10) E -> . WHILE B DO LBRACE E RBRACE + + LET shift and go to state 2 + ID shift and go to state 3 + LPAREN shift and go to state 4 + CONST shift and go to state 5 + IF shift and go to state 6 + WHILE shift and go to state 7 + + E shift and go to state 46 + +state 34 + + (18) B -> E COMP . E + (1) E -> . LET D IN E + (2) E -> . ID + (3) E -> . ID LPAREN A RPAREN + (4) E -> . E AOP E + (5) E -> . LPAREN E RPAREN + (6) E -> . CONST + (7) E -> . ID ASSIGN E + (8) E -> . E SEMICOLON E + (9) E -> . IF B THEN E ELSE E + (10) E -> . WHILE B DO LBRACE E RBRACE + + LET shift and go to state 2 + ID shift and go to state 3 + LPAREN shift and go to state 4 + CONST shift and go to state 5 + IF shift and go to state 6 + WHILE shift and go to state 7 + + E shift and go to state 47 + +state 35 + + (23) B -> LPAREN B . RPAREN + (19) B -> B . EQOP B + (20) B -> B . LOP B + + RPAREN shift and go to state 48 + EQOP shift and go to state 31 + LOP shift and go to state 32 + + +state 36 + + (5) E -> LPAREN E . RPAREN + (17) B -> E . EQOP E + (18) B -> E . COMP E + (4) E -> E . AOP E + (8) E -> E . SEMICOLON E + + RPAREN shift and go to state 29 + EQOP shift and go to state 33 + COMP shift and go to state 34 + AOP shift and go to state 8 + SEMICOLON shift and go to state 9 + + +state 37 + + (10) E -> WHILE B DO . LBRACE E RBRACE + + LBRACE shift and go to state 49 + + +state 38 + + (1) E -> LET D IN E . + (4) E -> E . AOP E + (8) E -> E . SEMICOLON E + + ! shift/reduce conflict for AOP resolved as shift + ! shift/reduce conflict for SEMICOLON resolved as shift + $end reduce using rule 1 (E -> LET D IN E .) + RPAREN reduce using rule 1 (E -> LET D IN E .) + EQOP reduce using rule 1 (E -> LET D IN E .) + COMP reduce using rule 1 (E -> LET D IN E .) + COMMA reduce using rule 1 (E -> LET D IN E .) + ELSE reduce using rule 1 (E -> LET D IN E .) + THEN reduce using rule 1 (E -> LET D IN E .) + LOP reduce using rule 1 (E -> LET D IN E .) + DO reduce using rule 1 (E -> LET D IN E .) + RBRACE reduce using rule 1 (E -> LET D IN E .) + AOP shift and go to state 8 + SEMICOLON shift and go to state 9 + + ! AOP [ reduce using rule 1 (E -> LET D IN E .) ] + ! SEMICOLON [ reduce using rule 1 (E -> LET D IN E .) ] + + +state 39 + + (15) V -> ID . + + RPAREN reduce using rule 15 (V -> ID .) + COMMA reduce using rule 15 (V -> ID .) + + +state 40 + + (13) D -> ID LPAREN V . RPAREN LBRACE E RBRACE + (16) V -> V . COMMA ID + + RPAREN shift and go to state 50 + COMMA shift and go to state 51 + + +state 41 + + (3) E -> ID LPAREN A RPAREN . + + AOP reduce using rule 3 (E -> ID LPAREN A RPAREN .) + SEMICOLON reduce using rule 3 (E -> ID LPAREN A RPAREN .) + $end reduce using rule 3 (E -> ID LPAREN A RPAREN .) + RPAREN reduce using rule 3 (E -> ID LPAREN A RPAREN .) + EQOP reduce using rule 3 (E -> ID LPAREN A RPAREN .) + COMP reduce using rule 3 (E -> ID LPAREN A RPAREN .) + COMMA reduce using rule 3 (E -> ID LPAREN A RPAREN .) + ELSE reduce using rule 3 (E -> ID LPAREN A RPAREN .) + THEN reduce using rule 3 (E -> ID LPAREN A RPAREN .) + LOP reduce using rule 3 (E -> ID LPAREN A RPAREN .) + DO reduce using rule 3 (E -> ID LPAREN A RPAREN .) + RBRACE reduce using rule 3 (E -> ID LPAREN A RPAREN .) + + +state 42 + + (12) A -> A COMMA . E + (1) E -> . LET D IN E + (2) E -> . ID + (3) E -> . ID LPAREN A RPAREN + (4) E -> . E AOP E + (5) E -> . LPAREN E RPAREN + (6) E -> . CONST + (7) E -> . ID ASSIGN E + (8) E -> . E SEMICOLON E + (9) E -> . IF B THEN E ELSE E + (10) E -> . WHILE B DO LBRACE E RBRACE LET shift and go to state 2 ID shift and go to state 3 @@ -812,7 +864,93 @@ state 42 state 43 - (18) B -> E COMP . E + (9) E -> IF B THEN E . ELSE E + (4) E -> E . AOP E + (8) E -> E . SEMICOLON E + + ELSE shift and go to state 53 + AOP shift and go to state 8 + SEMICOLON shift and go to state 9 + + +state 44 + + (19) B -> B EQOP B . + (19) B -> B . EQOP B + (20) B -> B . LOP B + + THEN reduce using rule 19 (B -> B EQOP B .) + EQOP reduce using rule 19 (B -> B EQOP B .) + LOP reduce using rule 19 (B -> B EQOP B .) + DO reduce using rule 19 (B -> B EQOP B .) + RPAREN reduce using rule 19 (B -> B EQOP B .) + + ! EQOP [ shift and go to state 31 ] + ! LOP [ shift and go to state 32 ] + + +state 45 + + (20) B -> B LOP B . + (19) B -> B . EQOP B + (20) B -> B . LOP B + + ! shift/reduce conflict for EQOP resolved as shift + ! shift/reduce conflict for LOP resolved as shift + THEN reduce using rule 20 (B -> B LOP B .) + DO reduce using rule 20 (B -> B LOP B .) + RPAREN reduce using rule 20 (B -> B LOP B .) + EQOP shift and go to state 31 + LOP shift and go to state 32 + + ! EQOP [ reduce using rule 20 (B -> B LOP B .) ] + ! LOP [ reduce using rule 20 (B -> B LOP B .) ] + + +state 46 + + (17) B -> E EQOP E . + (4) E -> E . AOP E + (8) E -> E . SEMICOLON E + + THEN reduce using rule 17 (B -> E EQOP E .) + EQOP reduce using rule 17 (B -> E EQOP E .) + LOP reduce using rule 17 (B -> E EQOP E .) + DO reduce using rule 17 (B -> E EQOP E .) + RPAREN reduce using rule 17 (B -> E EQOP E .) + AOP shift and go to state 8 + SEMICOLON shift and go to state 9 + + +state 47 + + (18) B -> E COMP E . + (4) E -> E . AOP E + (8) E -> E . SEMICOLON E + + THEN reduce using rule 18 (B -> E COMP E .) + EQOP reduce using rule 18 (B -> E COMP E .) + LOP reduce using rule 18 (B -> E COMP E .) + DO reduce using rule 18 (B -> E COMP E .) + RPAREN reduce using rule 18 (B -> E COMP E .) + AOP shift and go to state 8 + SEMICOLON shift and go to state 9 + + +state 48 + + (23) B -> LPAREN B RPAREN . + + THEN reduce using rule 23 (B -> LPAREN B RPAREN .) + EQOP reduce using rule 23 (B -> LPAREN B RPAREN .) + LOP reduce using rule 23 (B -> LPAREN B RPAREN .) + DO reduce using rule 23 (B -> LPAREN B RPAREN .) + RPAREN reduce using rule 23 (B -> LPAREN B RPAREN .) + + +state 49 + + (10) E -> WHILE B DO LBRACE . E RBRACE (1) E -> . LET D IN E (2) E -> . ID (3) E -> . ID LPAREN A RPAREN @@ -821,8 +959,8 @@ state 43 (6) E -> . CONST (7) E -> . ID ASSIGN E (8) E -> . E SEMICOLON E - (9) E -> . IF LPAREN B RPAREN THEN E ELSE E - (10) E -> . WHILE LPAREN B RPAREN DO LBRACE E RBRACE + (9) E -> . IF B THEN E ELSE E + (10) E -> . WHILE B DO LBRACE E RBRACE LET shift and go to state 2 ID shift and go to state 3 @@ -831,30 +969,23 @@ state 43 IF shift and go to state 6 WHILE shift and go to state 7 - E shift and go to state 53 + E shift and go to state 54 -state 44 - - (10) E -> WHILE LPAREN B RPAREN . DO LBRACE E RBRACE - - DO shift and go to state 54 - - -state 45 +state 50 (13) D -> ID LPAREN V RPAREN . LBRACE E RBRACE LBRACE shift and go to state 55 -state 46 +state 51 (16) V -> V COMMA . ID ID shift and go to state 56 -state 47 +state 52 (12) A -> A COMMA E . (4) E -> E . AOP E @@ -866,18 +997,9 @@ state 47 SEMICOLON shift and go to state 9 -state 48 +state 53 - (23) B -> LPAREN B RPAREN . - - RPAREN reduce using rule 23 (B -> LPAREN B RPAREN .) - EQOP reduce using rule 23 (B -> LPAREN B RPAREN .) - LOP reduce using rule 23 (B -> LPAREN B RPAREN .) - - -state 49 - - (9) E -> IF LPAREN B RPAREN THEN . E ELSE E + (9) E -> IF B THEN E ELSE . E (1) E -> . LET D IN E (2) E -> . ID (3) E -> . ID LPAREN A RPAREN @@ -886,8 +1008,8 @@ state 49 (6) E -> . CONST (7) E -> . ID ASSIGN E (8) E -> . E SEMICOLON E - (9) E -> . IF LPAREN B RPAREN THEN E ELSE E - (10) E -> . WHILE LPAREN B RPAREN DO LBRACE E RBRACE + (9) E -> . IF B THEN E ELSE E + (10) E -> . WHILE B DO LBRACE E RBRACE LET shift and go to state 2 ID shift and go to state 3 @@ -898,67 +1020,15 @@ state 49 E shift and go to state 57 -state 50 - - (19) B -> B EQOP B . - (19) B -> B . EQOP B - (20) B -> B . LOP B - - RPAREN reduce using rule 19 (B -> B EQOP B .) - EQOP reduce using rule 19 (B -> B EQOP B .) - LOP reduce using rule 19 (B -> B EQOP B .) - - ! EQOP [ shift and go to state 40 ] - ! LOP [ shift and go to state 41 ] - - -state 51 - - (20) B -> B LOP B . - (19) B -> B . EQOP B - (20) B -> B . LOP B - - ! shift/reduce conflict for EQOP resolved as shift - ! shift/reduce conflict for LOP resolved as shift - RPAREN reduce using rule 20 (B -> B LOP B .) - EQOP shift and go to state 40 - LOP shift and go to state 41 - - ! EQOP [ reduce using rule 20 (B -> B LOP B .) ] - ! LOP [ reduce using rule 20 (B -> B LOP B .) ] - - -state 52 - - (17) B -> E EQOP E . - (4) E -> E . AOP E - (8) E -> E . SEMICOLON E - - RPAREN reduce using rule 17 (B -> E EQOP E .) - EQOP reduce using rule 17 (B -> E EQOP E .) - LOP reduce using rule 17 (B -> E EQOP E .) - AOP shift and go to state 8 - SEMICOLON shift and go to state 9 - - -state 53 - - (18) B -> E COMP E . - (4) E -> E . AOP E - (8) E -> E . SEMICOLON E - - RPAREN reduce using rule 18 (B -> E COMP E .) - EQOP reduce using rule 18 (B -> E COMP E .) - LOP reduce using rule 18 (B -> E COMP E .) - AOP shift and go to state 8 - SEMICOLON shift and go to state 9 - - state 54 - (10) E -> WHILE LPAREN B RPAREN DO . LBRACE E RBRACE + (10) E -> WHILE B DO LBRACE E . RBRACE + (4) E -> E . AOP E + (8) E -> E . SEMICOLON E - LBRACE shift and go to state 58 + RBRACE shift and go to state 58 + AOP shift and go to state 8 + SEMICOLON shift and go to state 9 state 55 @@ -972,8 +1042,8 @@ state 55 (6) E -> . CONST (7) E -> . ID ASSIGN E (8) E -> . E SEMICOLON E - (9) E -> . IF LPAREN B RPAREN THEN E ELSE E - (10) E -> . WHILE LPAREN B RPAREN DO LBRACE E RBRACE + (9) E -> . IF B THEN E ELSE E + (10) E -> . WHILE B DO LBRACE E RBRACE LET shift and go to state 2 ID shift and go to state 3 @@ -994,37 +1064,46 @@ state 56 state 57 - (9) E -> IF LPAREN B RPAREN THEN E . ELSE E + (9) E -> IF B THEN E ELSE E . (4) E -> E . AOP E (8) E -> E . SEMICOLON E - ELSE shift and go to state 60 + ! shift/reduce conflict for AOP resolved as shift + ! shift/reduce conflict for SEMICOLON resolved as shift + $end reduce using rule 9 (E -> IF B THEN E ELSE E .) + RPAREN reduce using rule 9 (E -> IF B THEN E ELSE E .) + EQOP reduce using rule 9 (E -> IF B THEN E ELSE E .) + COMP reduce using rule 9 (E -> IF B THEN E ELSE E .) + COMMA reduce using rule 9 (E -> IF B THEN E ELSE E .) + ELSE reduce using rule 9 (E -> IF B THEN E ELSE E .) + THEN reduce using rule 9 (E -> IF B THEN E ELSE E .) + LOP reduce using rule 9 (E -> IF B THEN E ELSE E .) + DO reduce using rule 9 (E -> IF B THEN E ELSE E .) + RBRACE reduce using rule 9 (E -> IF B THEN E ELSE E .) AOP shift and go to state 8 SEMICOLON shift and go to state 9 + ! AOP [ reduce using rule 9 (E -> IF B THEN E ELSE E .) ] + ! SEMICOLON [ reduce using rule 9 (E -> IF B THEN E ELSE E .) ] + state 58 - (10) E -> WHILE LPAREN B RPAREN DO LBRACE . E RBRACE - (1) E -> . LET D IN E - (2) E -> . ID - (3) E -> . ID LPAREN A RPAREN - (4) E -> . E AOP E - (5) E -> . LPAREN E RPAREN - (6) E -> . CONST - (7) E -> . ID ASSIGN E - (8) E -> . E SEMICOLON E - (9) E -> . IF LPAREN B RPAREN THEN E ELSE E - (10) E -> . WHILE LPAREN B RPAREN DO LBRACE E RBRACE + (10) E -> WHILE B DO LBRACE E RBRACE . - LET shift and go to state 2 - ID shift and go to state 3 - LPAREN shift and go to state 4 - CONST shift and go to state 5 - IF shift and go to state 6 - WHILE shift and go to state 7 + AOP reduce using rule 10 (E -> WHILE B DO LBRACE E RBRACE .) + SEMICOLON reduce using rule 10 (E -> WHILE B DO LBRACE E RBRACE .) + $end reduce using rule 10 (E -> WHILE B DO LBRACE E RBRACE .) + RPAREN reduce using rule 10 (E -> WHILE B DO LBRACE E RBRACE .) + EQOP reduce using rule 10 (E -> WHILE B DO LBRACE E RBRACE .) + COMP reduce using rule 10 (E -> WHILE B DO LBRACE E RBRACE .) + COMMA reduce using rule 10 (E -> WHILE B DO LBRACE E RBRACE .) + ELSE reduce using rule 10 (E -> WHILE B DO LBRACE E RBRACE .) + THEN reduce using rule 10 (E -> WHILE B DO LBRACE E RBRACE .) + LOP reduce using rule 10 (E -> WHILE B DO LBRACE E RBRACE .) + DO reduce using rule 10 (E -> WHILE B DO LBRACE E RBRACE .) + RBRACE reduce using rule 10 (E -> WHILE B DO LBRACE E RBRACE .) - E shift and go to state 61 state 59 @@ -1032,102 +1111,29 @@ state 59 (4) E -> E . AOP E (8) E -> E . SEMICOLON E - RBRACE shift and go to state 62 + RBRACE shift and go to state 60 AOP shift and go to state 8 SEMICOLON shift and go to state 9 state 60 - (9) E -> IF LPAREN B RPAREN THEN E ELSE . E - (1) E -> . LET D IN E - (2) E -> . ID - (3) E -> . ID LPAREN A RPAREN - (4) E -> . E AOP E - (5) E -> . LPAREN E RPAREN - (6) E -> . CONST - (7) E -> . ID ASSIGN E - (8) E -> . E SEMICOLON E - (9) E -> . IF LPAREN B RPAREN THEN E ELSE E - (10) E -> . WHILE LPAREN B RPAREN DO LBRACE E RBRACE - - LET shift and go to state 2 - ID shift and go to state 3 - LPAREN shift and go to state 4 - CONST shift and go to state 5 - IF shift and go to state 6 - WHILE shift and go to state 7 - - E shift and go to state 63 - -state 61 - - (10) E -> WHILE LPAREN B RPAREN DO LBRACE E . RBRACE - (4) E -> E . AOP E - (8) E -> E . SEMICOLON E - - RBRACE shift and go to state 64 - AOP shift and go to state 8 - SEMICOLON shift and go to state 9 - - -state 62 - (13) D -> ID LPAREN V RPAREN LBRACE E RBRACE . IN reduce using rule 13 (D -> ID LPAREN V RPAREN LBRACE E RBRACE .) ID reduce using rule 13 (D -> ID LPAREN V RPAREN LBRACE E RBRACE .) - -state 63 - - (9) E -> IF LPAREN B RPAREN THEN E ELSE E . - (4) E -> E . AOP E - (8) E -> E . SEMICOLON E - - ! shift/reduce conflict for AOP resolved as shift - ! shift/reduce conflict for SEMICOLON resolved as shift - $end reduce using rule 9 (E -> IF LPAREN B RPAREN THEN E ELSE E .) - RPAREN reduce using rule 9 (E -> IF LPAREN B RPAREN THEN E ELSE E .) - COMMA reduce using rule 9 (E -> IF LPAREN B RPAREN THEN E ELSE E .) - EQOP reduce using rule 9 (E -> IF LPAREN B RPAREN THEN E ELSE E .) - COMP reduce using rule 9 (E -> IF LPAREN B RPAREN THEN E ELSE E .) - LOP reduce using rule 9 (E -> IF LPAREN B RPAREN THEN E ELSE E .) - ELSE reduce using rule 9 (E -> IF LPAREN B RPAREN THEN E ELSE E .) - RBRACE reduce using rule 9 (E -> IF LPAREN B RPAREN THEN E ELSE E .) - AOP shift and go to state 8 - SEMICOLON shift and go to state 9 - - ! AOP [ reduce using rule 9 (E -> IF LPAREN B RPAREN THEN E ELSE E .) ] - ! SEMICOLON [ reduce using rule 9 (E -> IF LPAREN B RPAREN THEN E ELSE E .) ] - - -state 64 - - (10) E -> WHILE LPAREN B RPAREN DO LBRACE E RBRACE . - - AOP reduce using rule 10 (E -> WHILE LPAREN B RPAREN DO LBRACE E RBRACE .) - SEMICOLON reduce using rule 10 (E -> WHILE LPAREN B RPAREN DO LBRACE E RBRACE .) - $end reduce using rule 10 (E -> WHILE LPAREN B RPAREN DO LBRACE E RBRACE .) - RPAREN reduce using rule 10 (E -> WHILE LPAREN B RPAREN DO LBRACE E RBRACE .) - COMMA reduce using rule 10 (E -> WHILE LPAREN B RPAREN DO LBRACE E RBRACE .) - EQOP reduce using rule 10 (E -> WHILE LPAREN B RPAREN DO LBRACE E RBRACE .) - COMP reduce using rule 10 (E -> WHILE LPAREN B RPAREN DO LBRACE E RBRACE .) - LOP reduce using rule 10 (E -> WHILE LPAREN B RPAREN DO LBRACE E RBRACE .) - ELSE reduce using rule 10 (E -> WHILE LPAREN B RPAREN DO LBRACE E RBRACE .) - RBRACE reduce using rule 10 (E -> WHILE LPAREN B RPAREN DO LBRACE E RBRACE .) - WARNING: WARNING: Conflicts: WARNING: -WARNING: shift/reduce conflict for AOP in state 18 resolved as shift -WARNING: shift/reduce conflict for SEMICOLON in state 18 resolved as shift -WARNING: shift/reduce conflict for ID in state 19 resolved as shift -WARNING: shift/reduce conflict for AOP in state 24 resolved as shift -WARNING: shift/reduce conflict for SEMICOLON in state 24 resolved as shift -WARNING: shift/reduce conflict for AOP in state 32 resolved as shift -WARNING: shift/reduce conflict for SEMICOLON in state 32 resolved as shift -WARNING: shift/reduce conflict for EQOP in state 51 resolved as shift -WARNING: shift/reduce conflict for LOP in state 51 resolved as shift -WARNING: shift/reduce conflict for AOP in state 63 resolved as shift -WARNING: shift/reduce conflict for SEMICOLON in state 63 resolved as shift +WARNING: shift/reduce conflict for AOP in state 22 resolved as shift +WARNING: shift/reduce conflict for SEMICOLON in state 22 resolved as shift +WARNING: shift/reduce conflict for ID in state 23 resolved as shift +WARNING: shift/reduce conflict for AOP in state 28 resolved as shift +WARNING: shift/reduce conflict for SEMICOLON in state 28 resolved as shift +WARNING: shift/reduce conflict for AOP in state 38 resolved as shift +WARNING: shift/reduce conflict for SEMICOLON in state 38 resolved as shift +WARNING: shift/reduce conflict for EQOP in state 45 resolved as shift +WARNING: shift/reduce conflict for LOP in state 45 resolved as shift +WARNING: shift/reduce conflict for AOP in state 57 resolved as shift +WARNING: shift/reduce conflict for SEMICOLON in state 57 resolved as shift diff --git a/Project-02/parsetab.py b/Project-02/parsetab.py index 5bd8b35..e42ff9c 100644 --- a/Project-02/parsetab.py +++ b/Project-02/parsetab.py @@ -6,9 +6,9 @@ _tabversion = '3.10' _lr_method = 'LALR' -_lr_signature = 'EleftCOMPleftEQOPleftAOPAOP ASSIGN COMMA COMP CONST DO ELSE EQOP FALSE ID IF IN LBRACE LET LOP LPAREN RBRACE RPAREN SEMICOLON THEN TRUE WHILEE : LET D IN EE : IDE : ID LPAREN A RPARENE : E AOP EE : LPAREN E RPARENE : CONSTE : ID ASSIGN EE : E SEMICOLON EE : IF LPAREN B RPAREN THEN E ELSE EE : WHILE LPAREN B RPAREN DO LBRACE E RBRACEA : EA : A COMMA ED : ID LPAREN V RPAREN LBRACE E RBRACED : D DV : IDV : V COMMA IDB : E EQOP EB : E COMP EB : B EQOP BB : B LOP BB : TRUEB : FALSEB : LPAREN B RPAREN' +_lr_signature = 'EleftCOMPleftEQOPleftAOPAOP ASSIGN COMMA COMP CONST DO ELSE EQOP FALSE ID IF IN LBRACE LET LOP LPAREN RBRACE RPAREN SEMICOLON THEN TRUE WHILEE : LET D IN EE : IDE : ID LPAREN A RPARENE : E AOP EE : LPAREN E RPARENE : CONSTE : ID ASSIGN EE : E SEMICOLON EE : IF B THEN E ELSE EE : WHILE B DO LBRACE E RBRACEA : EA : A COMMA ED : ID LPAREN V RPAREN LBRACE E RBRACED : D DV : IDV : V COMMA IDB : E EQOP EB : E COMP EB : B EQOP BB : B LOP BB : TRUEB : FALSEB : LPAREN B RPAREN' -_lr_action_items = {'LET':([0,4,8,9,12,13,15,16,20,26,36,40,41,42,43,49,55,58,60,],[2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,]),'ID':([0,2,4,8,9,10,12,13,15,16,19,20,21,26,36,40,41,42,43,46,49,55,58,60,62,],[3,11,3,3,3,11,3,3,3,3,11,3,33,3,3,3,3,3,3,56,3,3,3,3,-13,]),'LPAREN':([0,3,4,6,7,8,9,11,12,13,15,16,20,26,36,40,41,42,43,49,55,58,60,],[4,12,4,15,16,4,4,21,4,4,26,26,4,26,4,26,26,4,4,4,4,4,4,]),'CONST':([0,4,8,9,12,13,15,16,20,26,36,40,41,42,43,49,55,58,60,],[5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,]),'IF':([0,4,8,9,12,13,15,16,20,26,36,40,41,42,43,49,55,58,60,],[6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,]),'WHILE':([0,4,8,9,12,13,15,16,20,26,36,40,41,42,43,49,55,58,60,],[7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,]),'$end':([1,3,5,17,18,24,25,32,35,63,64,],[0,-2,-6,-4,-8,-7,-5,-1,-3,-9,-10,]),'AOP':([1,3,5,14,17,18,23,24,25,28,32,35,38,47,52,53,57,59,61,63,64,],[8,-2,-6,8,-4,8,8,8,-5,8,8,-3,8,8,8,8,8,8,8,8,-10,]),'SEMICOLON':([1,3,5,14,17,18,23,24,25,28,32,35,38,47,52,53,57,59,61,63,64,],[9,-2,-6,9,-4,9,9,9,-5,9,9,-3,9,9,9,9,9,9,9,9,-10,]),'RPAREN':([3,5,14,17,18,22,23,24,25,27,29,30,31,32,33,34,35,37,38,47,48,50,51,52,53,56,63,64,],[-2,-6,25,-4,-8,35,-11,-7,-5,39,-21,-22,44,-1,-15,45,-3,48,25,-12,-23,-19,-20,-17,-18,-16,-9,-10,]),'COMMA':([3,5,17,18,22,23,24,25,32,33,34,35,47,56,63,64,],[-2,-6,-4,-8,36,-11,-7,-5,-1,-15,46,-3,-12,-16,-9,-10,]),'EQOP':([3,5,17,18,24,25,27,28,29,30,31,32,35,37,38,48,50,51,52,53,63,64,],[-2,-6,-4,-8,-7,-5,40,42,-21,-22,40,-1,-3,40,42,-23,-19,40,-17,-18,-9,-10,]),'COMP':([3,5,17,18,24,25,28,32,35,38,63,64,],[-2,-6,-4,-8,-7,-5,43,-1,-3,43,-9,-10,]),'LOP':([3,5,17,18,24,25,27,29,30,31,32,35,37,48,50,51,52,53,63,64,],[-2,-6,-4,-8,-7,-5,41,-21,-22,41,-1,-3,41,-23,-19,41,-17,-18,-9,-10,]),'ELSE':([3,5,17,18,24,25,32,35,57,63,64,],[-2,-6,-4,-8,-7,-5,-1,-3,60,-9,-10,]),'RBRACE':([3,5,17,18,24,25,32,35,59,61,63,64,],[-2,-6,-4,-8,-7,-5,-1,-3,62,64,-9,-10,]),'ASSIGN':([3,],[13,]),'IN':([10,19,62,],[20,-14,-13,]),'TRUE':([15,16,26,40,41,],[29,29,29,29,29,]),'FALSE':([15,16,26,40,41,],[30,30,30,30,30,]),'THEN':([39,],[49,]),'DO':([44,],[54,]),'LBRACE':([45,54,],[55,58,]),} +_lr_action_items = {'LET':([0,4,6,7,8,9,12,13,19,24,30,31,32,33,34,42,49,53,55,],[2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,]),'ID':([0,2,4,6,7,8,9,10,12,13,19,23,24,25,30,31,32,33,34,42,49,51,53,55,60,],[3,11,3,3,3,3,3,11,3,3,3,11,3,39,3,3,3,3,3,3,3,56,3,3,-13,]),'LPAREN':([0,3,4,6,7,8,9,11,12,13,19,24,30,31,32,33,34,42,49,53,55,],[4,12,4,19,19,4,4,25,4,4,19,4,4,19,19,4,4,4,4,4,4,]),'CONST':([0,4,6,7,8,9,12,13,19,24,30,31,32,33,34,42,49,53,55,],[5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,]),'IF':([0,4,6,7,8,9,12,13,19,24,30,31,32,33,34,42,49,53,55,],[6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,]),'WHILE':([0,4,6,7,8,9,12,13,19,24,30,31,32,33,34,42,49,53,55,],[7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,]),'$end':([1,3,5,21,22,28,29,38,41,57,58,],[0,-2,-6,-4,-8,-7,-5,-1,-3,-9,-10,]),'AOP':([1,3,5,14,16,21,22,27,28,29,36,38,41,43,46,47,52,54,57,58,59,],[8,-2,-6,8,8,-4,8,8,8,-5,8,8,-3,8,8,8,8,8,8,-10,8,]),'SEMICOLON':([1,3,5,14,16,21,22,27,28,29,36,38,41,43,46,47,52,54,57,58,59,],[9,-2,-6,9,9,-4,9,9,9,-5,9,9,-3,9,9,9,9,9,9,-10,9,]),'RPAREN':([3,5,14,17,18,21,22,26,27,28,29,35,36,38,39,40,41,44,45,46,47,48,52,56,57,58,],[-2,-6,29,-21,-22,-4,-8,41,-11,-7,-5,48,29,-1,-15,50,-3,-19,-20,-17,-18,-23,-12,-16,-9,-10,]),'EQOP':([3,5,15,16,17,18,20,21,22,28,29,35,36,38,41,44,45,46,47,48,57,58,],[-2,-6,31,33,-21,-22,31,-4,-8,-7,-5,31,33,-1,-3,-19,31,-17,-18,-23,-9,-10,]),'COMP':([3,5,16,21,22,28,29,36,38,41,57,58,],[-2,-6,34,-4,-8,-7,-5,34,-1,-3,-9,-10,]),'COMMA':([3,5,21,22,26,27,28,29,38,39,40,41,52,56,57,58,],[-2,-6,-4,-8,42,-11,-7,-5,-1,-15,51,-3,-12,-16,-9,-10,]),'ELSE':([3,5,21,22,28,29,38,41,43,57,58,],[-2,-6,-4,-8,-7,-5,-1,-3,53,-9,-10,]),'THEN':([3,5,15,17,18,21,22,28,29,38,41,44,45,46,47,48,57,58,],[-2,-6,30,-21,-22,-4,-8,-7,-5,-1,-3,-19,-20,-17,-18,-23,-9,-10,]),'LOP':([3,5,15,17,18,20,21,22,28,29,35,38,41,44,45,46,47,48,57,58,],[-2,-6,32,-21,-22,32,-4,-8,-7,-5,32,-1,-3,-19,32,-17,-18,-23,-9,-10,]),'DO':([3,5,17,18,20,21,22,28,29,38,41,44,45,46,47,48,57,58,],[-2,-6,-21,-22,37,-4,-8,-7,-5,-1,-3,-19,-20,-17,-18,-23,-9,-10,]),'RBRACE':([3,5,21,22,28,29,38,41,54,57,58,59,],[-2,-6,-4,-8,-7,-5,-1,-3,58,-9,-10,60,]),'ASSIGN':([3,],[13,]),'TRUE':([6,7,19,31,32,],[17,17,17,17,17,]),'FALSE':([6,7,19,31,32,],[18,18,18,18,18,]),'IN':([10,23,60,],[24,-14,-13,]),'LBRACE':([37,50,],[49,55,]),} _lr_action = {} for _k, _v in _lr_action_items.items(): @@ -17,7 +17,7 @@ for _k, _v in _lr_action_items.items(): _lr_action[_x][_k] = _y del _lr_action_items -_lr_goto_items = {'E':([0,4,8,9,12,13,15,16,20,26,36,40,41,42,43,49,55,58,60,],[1,14,17,18,23,24,28,28,32,38,47,28,28,52,53,57,59,61,63,]),'D':([2,10,19,],[10,19,19,]),'A':([12,],[22,]),'B':([15,16,26,40,41,],[27,31,37,50,51,]),'V':([21,],[34,]),} +_lr_goto_items = {'E':([0,4,6,7,8,9,12,13,19,24,30,31,32,33,34,42,49,53,55,],[1,14,16,16,21,22,27,28,36,38,43,16,16,46,47,52,54,57,59,]),'D':([2,10,23,],[10,23,23,]),'B':([6,7,19,31,32,],[15,20,35,44,45,]),'A':([12,],[26,]),'V':([25,],[40,]),} _lr_goto = {} for _k, _v in _lr_goto_items.items(): @@ -35,19 +35,19 @@ _lr_productions = [ ('E -> CONST','E',1,'p_E_const','triplayacc.py',45), ('E -> ID ASSIGN E','E',3,'p_E_assign','triplayacc.py',49), ('E -> E SEMICOLON E','E',3,'p_E_seq','triplayacc.py',53), - ('E -> IF LPAREN B RPAREN THEN E ELSE E','E',8,'p_E_if','triplayacc.py',57), - ('E -> WHILE LPAREN B RPAREN DO LBRACE E RBRACE','E',8,'p_E_while','triplayacc.py',61), - ('A -> E','A',1,'p_A_single','triplayacc.py',69), - ('A -> A COMMA E','A',3,'p_A_multiple','triplayacc.py',73), - ('D -> ID LPAREN V RPAREN LBRACE E RBRACE','D',7,'p_D_single','triplayacc.py',81), - ('D -> D D','D',2,'p_D_concat','triplayacc.py',85), - ('V -> ID','V',1,'p_V_single','triplayacc.py',93), - ('V -> V COMMA ID','V',3,'p_V_multiple','triplayacc.py',97), - ('B -> E EQOP E','B',3,'p_B_eqop_E','triplayacc.py',105), - ('B -> E COMP E','B',3,'p_B_comp','triplayacc.py',109), - ('B -> B EQOP B','B',3,'p_B_eqop_B','triplayacc.py',113), - ('B -> B LOP B','B',3,'p_B_lop','triplayacc.py',117), - ('B -> TRUE','B',1,'p_B_true','triplayacc.py',121), - ('B -> FALSE','B',1,'p_B_false','triplayacc.py',125), - ('B -> LPAREN B RPAREN','B',3,'p_B_paren','triplayacc.py',129), + ('E -> IF B THEN E ELSE E','E',6,'p_E_if','triplayacc.py',57), + ('E -> WHILE B DO LBRACE E RBRACE','E',6,'p_E_while','triplayacc.py',61), + ('A -> E','A',1,'p_A_single','triplayacc.py',70), + ('A -> A COMMA E','A',3,'p_A_multiple','triplayacc.py',74), + ('D -> ID LPAREN V RPAREN LBRACE E RBRACE','D',7,'p_D_single','triplayacc.py',82), + ('D -> D D','D',2,'p_D_concat','triplayacc.py',86), + ('V -> ID','V',1,'p_V_single','triplayacc.py',94), + ('V -> V COMMA ID','V',3,'p_V_multiple','triplayacc.py',98), + ('B -> E EQOP E','B',3,'p_B_eqop_E','triplayacc.py',106), + ('B -> E COMP E','B',3,'p_B_comp','triplayacc.py',110), + ('B -> B EQOP B','B',3,'p_B_eqop_B','triplayacc.py',114), + ('B -> B LOP B','B',3,'p_B_lop','triplayacc.py',118), + ('B -> TRUE','B',1,'p_B_true','triplayacc.py',122), + ('B -> FALSE','B',1,'p_B_false','triplayacc.py',126), + ('B -> LPAREN B RPAREN','B',3,'p_B_paren','triplayacc.py',130), ] diff --git a/Project-02/triplalex.py b/Project-02/triplalex.py index c581772..b7c463d 100644 --- a/Project-02/triplalex.py +++ b/Project-02/triplalex.py @@ -72,11 +72,17 @@ def t_newline(t): # Ignore whitespace t_ignore = ' \t' -# Comments -def t_comment(t): +# Single-line comment +def t_comment_single(t): r'//.*' pass +# Multi-line comment +def t_comment_multi(t): + r'/\*([^*]|\*+[^*/])*\*/' + t.lexer.lineno += t.value.count('\n') + pass + # Error handling def t_error(t): print("Illegal character '%s'" % t.value[0]) diff --git a/Project-02/triplaprograms/func.tripla b/Project-02/triplaprograms/func.tripla index 643f804..9e531ae 100644 --- a/Project-02/triplaprograms/func.tripla +++ b/Project-02/triplaprograms/func.tripla @@ -1,7 +1,7 @@ let func(a,b) { - do { + while ( a > 0 && b != a ) do { b = b + 1; a = a - 1 - } while ( a > 0 && b != a ) + } } in func(10, 8) \ No newline at end of file diff --git a/Project-02/triplayacc.py b/Project-02/triplayacc.py index 650a2ff..62ea53f 100644 --- a/Project-02/triplayacc.py +++ b/Project-02/triplayacc.py @@ -54,12 +54,13 @@ def p_E_seq(p): p[0] = ast.SEQ(p[1], p[3]) def p_E_if(p): - 'E : IF LPAREN B RPAREN THEN E ELSE E' - p[0] = ast.IF(p[3], p[6], p[8]) + 'E : IF B THEN E ELSE E' + p[0] = ast.IF(p[2], p[4], p[6]) def p_E_while(p): - 'E : WHILE LPAREN B RPAREN DO LBRACE E RBRACE' - p[0] = ast.WHILE(p[3], p[7]) + 'E : WHILE B DO LBRACE E RBRACE' + p[0] = ast.WHILE(p[2], p[5]) + # ------------------------------------------------------------ # Rules for A