Fix V->V rule

This commit is contained in:
Jan-Niclas Loosen
2025-11-25 16:30:48 +01:00
parent ee0e5b0b4c
commit 3cf18b9678
3 changed files with 24 additions and 16 deletions

View File

@@ -18,7 +18,7 @@ Rule 12 A -> A COMMA E
Rule 13 D -> ID LPAREN V RPAREN LBRACE E RBRACE Rule 13 D -> ID LPAREN V RPAREN LBRACE E RBRACE
Rule 14 D -> D D Rule 14 D -> D D
Rule 15 V -> ID Rule 15 V -> ID
Rule 16 V -> V COMMA ID Rule 16 V -> V COMMA V
Rule 17 B -> E EQOP E Rule 17 B -> E EQOP E
Rule 18 B -> E COMP E Rule 18 B -> E COMP E
Rule 19 B -> B EQOP B Rule 19 B -> B EQOP B
@@ -38,7 +38,7 @@ DO : 10
ELSE : 9 ELSE : 9
EQOP : 17 19 EQOP : 17 19
FALSE : 22 FALSE : 22
ID : 2 3 7 13 15 16 ID : 2 3 7 13 15
IF : 9 IF : 9
IN : 1 IN : 1
LBRACE : 10 13 LBRACE : 10 13
@@ -59,7 +59,7 @@ A : 3 12
B : 9 10 19 19 20 20 23 B : 9 10 19 19 20 20 23
D : 1 14 14 D : 1 14 14
E : 1 4 4 5 7 8 8 9 9 10 11 12 13 17 17 18 18 0 E : 1 4 4 5 7 8 8 9 9 10 11 12 13 17 17 18 18 0
V : 13 16 V : 13 16 16
Parsing method: LALR Parsing method: LALR
@@ -541,7 +541,7 @@ state 25
(13) D -> ID LPAREN . V RPAREN LBRACE E RBRACE (13) D -> ID LPAREN . V RPAREN LBRACE E RBRACE
(15) V -> . ID (15) V -> . ID
(16) V -> . V COMMA ID (16) V -> . V COMMA V
ID shift and go to state 39 ID shift and go to state 39
@@ -815,7 +815,7 @@ state 39
state 40 state 40
(13) D -> ID LPAREN V . RPAREN LBRACE E RBRACE (13) D -> ID LPAREN V . RPAREN LBRACE E RBRACE
(16) V -> V . COMMA ID (16) V -> V . COMMA V
RPAREN shift and go to state 50 RPAREN shift and go to state 50
COMMA shift and go to state 51 COMMA shift and go to state 51
@@ -980,10 +980,13 @@ state 50
state 51 state 51
(16) V -> V COMMA . ID (16) V -> V COMMA . V
(15) V -> . ID
(16) V -> . V COMMA V
ID shift and go to state 56 ID shift and go to state 39
V shift and go to state 56
state 52 state 52
@@ -1056,10 +1059,14 @@ state 55
state 56 state 56
(16) V -> V COMMA ID . (16) V -> V COMMA V .
(16) V -> V . COMMA V
RPAREN reduce using rule 16 (V -> V COMMA ID .) ! shift/reduce conflict for COMMA resolved as shift
COMMA reduce using rule 16 (V -> V COMMA ID .) RPAREN reduce using rule 16 (V -> V COMMA V .)
COMMA shift and go to state 51
! COMMA [ reduce using rule 16 (V -> V COMMA V .) ]
state 57 state 57
@@ -1135,5 +1142,6 @@ 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 SEMICOLON in state 38 resolved as shift
WARNING: shift/reduce conflict for EQOP in state 45 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 LOP in state 45 resolved as shift
WARNING: shift/reduce conflict for COMMA in state 56 resolved as shift
WARNING: shift/reduce conflict for AOP in state 57 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 WARNING: shift/reduce conflict for SEMICOLON in state 57 resolved as shift

View File

@@ -6,9 +6,9 @@ _tabversion = '3.10'
_lr_method = 'LALR' _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 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_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 VB : E EQOP EB : E COMP EB : B EQOP BB : B LOP BB : TRUEB : FALSEB : LPAREN B RPAREN'
_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_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,39,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,51,-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 = {} _lr_action = {}
for _k, _v in _lr_action_items.items(): 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 _lr_action[_x][_k] = _y
del _lr_action_items del _lr_action_items
_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_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,51,],[40,56,]),}
_lr_goto = {} _lr_goto = {}
for _k, _v in _lr_goto_items.items(): for _k, _v in _lr_goto_items.items():
@@ -42,7 +42,7 @@ _lr_productions = [
('D -> ID LPAREN V RPAREN LBRACE E RBRACE','D',7,'p_D_single','triplayacc.py',82), ('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), ('D -> D D','D',2,'p_D_concat','triplayacc.py',86),
('V -> ID','V',1,'p_V_single','triplayacc.py',94), ('V -> ID','V',1,'p_V_single','triplayacc.py',94),
('V -> V COMMA ID','V',3,'p_V_multiple','triplayacc.py',98), ('V -> V COMMA V','V',3,'p_V_multiple','triplayacc.py',98),
('B -> E EQOP E','B',3,'p_B_eqop_E','triplayacc.py',106), ('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 -> 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 EQOP B','B',3,'p_B_eqop_B','triplayacc.py',114),

View File

@@ -95,8 +95,8 @@ def p_V_single(p):
p[0] = [p[1]] p[0] = [p[1]]
def p_V_multiple(p): def p_V_multiple(p):
'V : V COMMA ID' 'V : V COMMA V'
p[0] = p[1] + [p[3]] p[0] = p[1] + p[3]
# ------------------------------------------------------------ # ------------------------------------------------------------
# Rules for B # Rules for B