Change priority of tokens

This commit is contained in:
Jan-Niclas Loosen
2025-12-03 21:10:07 +01:00
parent 3cf18b9678
commit 6e9f0331ed
4 changed files with 31 additions and 37 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 224 KiB

After

Width:  |  Height:  |  Size: 252 KiB

View File

@@ -480,8 +480,7 @@ state 22
(4) E -> E . AOP E (4) E -> E . AOP E
(8) E -> E . SEMICOLON E (8) E -> E . SEMICOLON E
! shift/reduce conflict for AOP resolved as shift SEMICOLON reduce using rule 8 (E -> E SEMICOLON E .)
! shift/reduce conflict for SEMICOLON resolved as shift
$end reduce using rule 8 (E -> E SEMICOLON E .) $end reduce using rule 8 (E -> E SEMICOLON E .)
RPAREN 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 .) EQOP reduce using rule 8 (E -> E SEMICOLON E .)
@@ -493,10 +492,9 @@ state 22
DO 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 .) RBRACE reduce using rule 8 (E -> E SEMICOLON E .)
AOP shift and go to state 8 AOP shift and go to state 8
SEMICOLON shift and go to state 9
! AOP [ reduce using rule 8 (E -> E SEMICOLON E .) ] ! AOP [ reduce using rule 8 (E -> E SEMICOLON E .) ]
! SEMICOLON [ reduce using rule 8 (E -> E SEMICOLON E .) ] ! SEMICOLON [ shift and go to state 9 ]
state 23 state 23
@@ -785,8 +783,7 @@ state 38
(4) E -> E . AOP E (4) E -> E . AOP E
(8) E -> E . SEMICOLON E (8) E -> E . SEMICOLON E
! shift/reduce conflict for AOP resolved as shift SEMICOLON reduce using rule 1 (E -> LET D IN E .)
! shift/reduce conflict for SEMICOLON resolved as shift
$end reduce using rule 1 (E -> LET D IN E .) $end reduce using rule 1 (E -> LET D IN E .)
RPAREN 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 .) EQOP reduce using rule 1 (E -> LET D IN E .)
@@ -798,10 +795,9 @@ state 38
DO 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 .) RBRACE reduce using rule 1 (E -> LET D IN E .)
AOP shift and go to state 8 AOP shift and go to state 8
SEMICOLON shift and go to state 9
! AOP [ reduce using rule 1 (E -> LET D IN E .) ] ! AOP [ reduce using rule 1 (E -> LET D IN E .) ]
! SEMICOLON [ reduce using rule 1 (E -> LET D IN E .) ] ! SEMICOLON [ shift and go to state 9 ]
state 39 state 39
@@ -1133,13 +1129,9 @@ state 60
WARNING: WARNING:
WARNING: Conflicts: WARNING: Conflicts:
WARNING: WARNING:
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 ID in state 23 resolved as shift
WARNING: shift/reduce conflict for AOP in state 28 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 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 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 COMMA in state 56 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 VB : E EQOP EB : E COMP EB : B EQOP BB : B LOP BB : TRUEB : FALSEB : LPAREN B RPAREN' _lr_signature = 'EleftSEMICOLONrightINleftCOMPleftEQOPleftAOPAOP 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,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_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,-8,9,9,-5,9,-1,-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():
@@ -27,27 +27,27 @@ for _k, _v in _lr_goto_items.items():
del _lr_goto_items del _lr_goto_items
_lr_productions = [ _lr_productions = [
("S' -> E","S'",1,None,None,None), ("S' -> E","S'",1,None,None,None),
('E -> LET D IN E','E',4,'p_E_let','triplayacc.py',23), ('E -> LET D IN E','E',4,'p_E_let','triplayacc.py',25),
('E -> ID','E',1,'p_E_id','triplayacc.py',27), ('E -> ID','E',1,'p_E_id','triplayacc.py',29),
('E -> ID LPAREN A RPAREN','E',4,'p_E_call','triplayacc.py',31), ('E -> ID LPAREN A RPAREN','E',4,'p_E_call','triplayacc.py',33),
('E -> E AOP E','E',3,'p_E_aop','triplayacc.py',36), ('E -> E AOP E','E',3,'p_E_aop','triplayacc.py',38),
('E -> LPAREN E RPAREN','E',3,'p_E_paren','triplayacc.py',40), ('E -> LPAREN E RPAREN','E',3,'p_E_paren','triplayacc.py',42),
('E -> CONST','E',1,'p_E_const','triplayacc.py',45), ('E -> CONST','E',1,'p_E_const','triplayacc.py',47),
('E -> ID ASSIGN E','E',3,'p_E_assign','triplayacc.py',49), ('E -> ID ASSIGN E','E',3,'p_E_assign','triplayacc.py',51),
('E -> E SEMICOLON E','E',3,'p_E_seq','triplayacc.py',53), ('E -> E SEMICOLON E','E',3,'p_E_seq','triplayacc.py',55),
('E -> IF B THEN E ELSE E','E',6,'p_E_if','triplayacc.py',57), ('E -> IF B THEN E ELSE E','E',6,'p_E_if','triplayacc.py',59),
('E -> WHILE B DO LBRACE E RBRACE','E',6,'p_E_while','triplayacc.py',61), ('E -> WHILE B DO LBRACE E RBRACE','E',6,'p_E_while','triplayacc.py',63),
('A -> E','A',1,'p_A_single','triplayacc.py',70), ('A -> E','A',1,'p_A_single','triplayacc.py',72),
('A -> A COMMA E','A',3,'p_A_multiple','triplayacc.py',74), ('A -> A COMMA E','A',3,'p_A_multiple','triplayacc.py',76),
('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',84),
('D -> D D','D',2,'p_D_concat','triplayacc.py',86), ('D -> D D','D',2,'p_D_concat','triplayacc.py',88),
('V -> ID','V',1,'p_V_single','triplayacc.py',94), ('V -> ID','V',1,'p_V_single','triplayacc.py',96),
('V -> V COMMA V','V',3,'p_V_multiple','triplayacc.py',98), ('V -> V COMMA V','V',3,'p_V_multiple','triplayacc.py',100),
('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',108),
('B -> E COMP E','B',3,'p_B_comp','triplayacc.py',110), ('B -> E COMP E','B',3,'p_B_comp','triplayacc.py',112),
('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',116),
('B -> B LOP B','B',3,'p_B_lop','triplayacc.py',118), ('B -> B LOP B','B',3,'p_B_lop','triplayacc.py',120),
('B -> TRUE','B',1,'p_B_true','triplayacc.py',122), ('B -> TRUE','B',1,'p_B_true','triplayacc.py',124),
('B -> FALSE','B',1,'p_B_false','triplayacc.py',126), ('B -> FALSE','B',1,'p_B_false','triplayacc.py',128),
('B -> LPAREN B RPAREN','B',3,'p_B_paren','triplayacc.py',130), ('B -> LPAREN B RPAREN','B',3,'p_B_paren','triplayacc.py',132),
] ]

View File

@@ -8,6 +8,8 @@ from triplalex import tokens
# Operator precedence # Operator precedence
precedence = ( precedence = (
('left', 'SEMICOLON'),
('right', 'IN'),
('left', 'COMP'), ('left', 'COMP'),
('left', 'EQOP'), ('left', 'EQOP'),
('left', 'AOP'), ('left', 'AOP'),