From 92b679e13c31288a8b9c5d5950f6eceb95ac6070 Mon Sep 17 00:00:00 2001 From: AYM1607 Date: Fri, 5 Apr 2019 03:23:41 +0000 Subject: [PATCH] Added tranlation action for assignation --- final_lang/fort.py | 20 +- final_lang/parser.out | 449 ++++++++++++++++++++------------------ final_lang/parsetab.py | 14 +- final_lang/test2.fort | 2 +- final_lang/test2.fort.out | 7 +- 5 files changed, 271 insertions(+), 221 deletions(-) diff --git a/final_lang/fort.py b/final_lang/fort.py index 04e0a2f..f614670 100644 --- a/final_lang/fort.py +++ b/final_lang/fort.py @@ -26,9 +26,9 @@ symbols = {} # symbolsTypes.append(symbolType) # Implementation using a dictionary -def addSymbol(name, symbolsTypes): - initialValue = 0 if symbolsTypes == 'integer' else 0.0 - symbols[name] = [name, initialValue] +def addSymbol(name, symbolType): + initialValue = 0 if symbolType == 'integer' else 0.0 + symbols[name] = [symbolType, initialValue] def peek(list): if (len(list) == 0): @@ -202,7 +202,7 @@ def p_B(p): def p_S(p): ''' - S : Dimensional equals EA + S : Dimensional action_7 equals EA action_8 | id parens | read RDimensional | print RDimOrString @@ -383,6 +383,17 @@ def p_action_6(p): quadrupletIndex += 1 + +def p_action_7(p): + "action_7 :" + operandsStack.append(p[-1]) + + +def p_action_8(p): + "action_8 :" + operand2 = operandsStack.pop() + operand1 = operandsStack.pop() + resultQuadruplets.append('= ' + str(operand2) + ' ' + str(operand1) + '\n') def p_error(p): print('XXX Invalid program') print(p) @@ -399,6 +410,7 @@ if (len(sys.argv) > 1): parser.parse(program) print(resultQuadruplets) + print(symbols) resultFile.writelines(resultQuadruplets) # Close the files. diff --git a/final_lang/parser.out b/final_lang/parser.out index f8fb348..9154835 100644 --- a/final_lang/parser.out +++ b/final_lang/parser.out @@ -17,7 +17,7 @@ Rule 11 F -> F subroutine id B end subroutine Rule 12 F -> Rule 13 B -> B S Rule 14 B -> -Rule 15 S -> Dimensional equals EA +Rule 15 S -> Dimensional action_7 equals EA action_8 Rule 16 S -> id parens Rule 17 S -> read RDimensional Rule 18 S -> print RDimOrString @@ -75,6 +75,8 @@ Rule 69 action_3 -> Rule 70 action_4 -> Rule 71 action_5 -> Rule 72 action_6 -> +Rule 73 action_7 -> +Rule 74 action_8 -> Terminals, with rules where they appear @@ -153,6 +155,8 @@ action_3 : 42 action_4 : 42 action_5 : 46 action_6 : 46 +action_7 : 15 +action_8 : 15 programa : 0 Parsing method: LALR @@ -274,7 +278,7 @@ state 9 (1) programa -> program id V F B . end program (13) B -> B . S - (15) S -> . Dimensional equals EA + (15) S -> . Dimensional action_7 equals EA action_8 (16) S -> . id parens (17) S -> . read RDimensional (18) S -> . print RDimOrString @@ -357,10 +361,12 @@ state 15 state 16 - (15) S -> Dimensional . equals EA + (15) S -> Dimensional . action_7 equals EA action_8 + (73) action_7 -> . - equals shift and go to state 30 + equals reduce using rule 73 (action_7 -> .) + action_7 shift and go to state 30 state 17 @@ -551,28 +557,10 @@ state 29 state 30 - (15) S -> Dimensional equals . EA - (41) EA -> . MultDiv - (42) EA -> . EA SumOrSub action_3 MultDiv action_4 - (45) MultDiv -> . EAParens - (46) MultDiv -> . MultDiv MDSymbols action_5 EAParens action_6 - (49) EAParens -> . EItem - (50) EAParens -> . openParen EA closedParen - (58) EItem -> . Dimensional action_1 - (59) EItem -> . int action_2 - (60) EItem -> . rea action_2 - (24) Dimensional -> . id DimensionsOrEmpty + (15) S -> Dimensional action_7 . equals EA action_8 - openParen shift and go to state 47 - int shift and go to state 53 - rea shift and go to state 54 - id shift and go to state 33 + equals shift and go to state 55 - Dimensional shift and go to state 52 - EA shift and go to state 55 - MultDiv shift and go to state 49 - EAParens shift and go to state 50 - EItem shift and go to state 51 state 31 @@ -788,7 +776,7 @@ state 43 (11) F -> F subroutine id B . end subroutine (13) B -> B . S - (15) S -> . Dimensional equals EA + (15) S -> . Dimensional action_7 equals EA action_8 (16) S -> . id parens (17) S -> . read RDimensional (18) S -> . print RDimOrString @@ -983,6 +971,12 @@ state 52 plus reduce using rule 67 (action_1 -> .) minus reduce using rule 67 (action_1 -> .) closedParen reduce using rule 67 (action_1 -> .) + less reduce using rule 67 (action_1 -> .) + more reduce using rule 67 (action_1 -> .) + doubleEquals reduce using rule 67 (action_1 -> .) + notEquals reduce using rule 67 (action_1 -> .) + lessEquals reduce using rule 67 (action_1 -> .) + moreEquals reduce using rule 67 (action_1 -> .) end reduce using rule 67 (action_1 -> .) id reduce using rule 67 (action_1 -> .) read reduce using rule 67 (action_1 -> .) @@ -993,12 +987,6 @@ state 52 exit reduce using rule 67 (action_1 -> .) elif reduce using rule 67 (action_1 -> .) else reduce using rule 67 (action_1 -> .) - less reduce using rule 67 (action_1 -> .) - more reduce using rule 67 (action_1 -> .) - doubleEquals reduce using rule 67 (action_1 -> .) - notEquals reduce using rule 67 (action_1 -> .) - lessEquals reduce using rule 67 (action_1 -> .) - moreEquals reduce using rule 67 (action_1 -> .) and reduce using rule 67 (action_1 -> .) or reduce using rule 67 (action_1 -> .) then reduce using rule 67 (action_1 -> .) @@ -1016,6 +1004,12 @@ state 53 plus reduce using rule 68 (action_2 -> .) minus reduce using rule 68 (action_2 -> .) closedParen reduce using rule 68 (action_2 -> .) + less reduce using rule 68 (action_2 -> .) + more reduce using rule 68 (action_2 -> .) + doubleEquals reduce using rule 68 (action_2 -> .) + notEquals reduce using rule 68 (action_2 -> .) + lessEquals reduce using rule 68 (action_2 -> .) + moreEquals reduce using rule 68 (action_2 -> .) end reduce using rule 68 (action_2 -> .) id reduce using rule 68 (action_2 -> .) read reduce using rule 68 (action_2 -> .) @@ -1026,12 +1020,6 @@ state 53 exit reduce using rule 68 (action_2 -> .) elif reduce using rule 68 (action_2 -> .) else reduce using rule 68 (action_2 -> .) - less reduce using rule 68 (action_2 -> .) - more reduce using rule 68 (action_2 -> .) - doubleEquals reduce using rule 68 (action_2 -> .) - notEquals reduce using rule 68 (action_2 -> .) - lessEquals reduce using rule 68 (action_2 -> .) - moreEquals reduce using rule 68 (action_2 -> .) and reduce using rule 68 (action_2 -> .) or reduce using rule 68 (action_2 -> .) then reduce using rule 68 (action_2 -> .) @@ -1049,6 +1037,12 @@ state 54 plus reduce using rule 68 (action_2 -> .) minus reduce using rule 68 (action_2 -> .) closedParen reduce using rule 68 (action_2 -> .) + less reduce using rule 68 (action_2 -> .) + more reduce using rule 68 (action_2 -> .) + doubleEquals reduce using rule 68 (action_2 -> .) + notEquals reduce using rule 68 (action_2 -> .) + lessEquals reduce using rule 68 (action_2 -> .) + moreEquals reduce using rule 68 (action_2 -> .) end reduce using rule 68 (action_2 -> .) id reduce using rule 68 (action_2 -> .) read reduce using rule 68 (action_2 -> .) @@ -1059,12 +1053,6 @@ state 54 exit reduce using rule 68 (action_2 -> .) elif reduce using rule 68 (action_2 -> .) else reduce using rule 68 (action_2 -> .) - less reduce using rule 68 (action_2 -> .) - more reduce using rule 68 (action_2 -> .) - doubleEquals reduce using rule 68 (action_2 -> .) - notEquals reduce using rule 68 (action_2 -> .) - lessEquals reduce using rule 68 (action_2 -> .) - moreEquals reduce using rule 68 (action_2 -> .) and reduce using rule 68 (action_2 -> .) or reduce using rule 68 (action_2 -> .) then reduce using rule 68 (action_2 -> .) @@ -1073,25 +1061,28 @@ state 54 state 55 - (15) S -> Dimensional equals EA . - (42) EA -> EA . SumOrSub action_3 MultDiv action_4 - (43) SumOrSub -> . plus - (44) SumOrSub -> . minus + (15) S -> Dimensional action_7 equals . EA action_8 + (41) EA -> . MultDiv + (42) EA -> . EA SumOrSub action_3 MultDiv action_4 + (45) MultDiv -> . EAParens + (46) MultDiv -> . MultDiv MDSymbols action_5 EAParens action_6 + (49) EAParens -> . EItem + (50) EAParens -> . openParen EA closedParen + (58) EItem -> . Dimensional action_1 + (59) EItem -> . int action_2 + (60) EItem -> . rea action_2 + (24) Dimensional -> . id DimensionsOrEmpty - end reduce using rule 15 (S -> Dimensional equals EA .) - id reduce using rule 15 (S -> Dimensional equals EA .) - read reduce using rule 15 (S -> Dimensional equals EA .) - print reduce using rule 15 (S -> Dimensional equals EA .) - if reduce using rule 15 (S -> Dimensional equals EA .) - do reduce using rule 15 (S -> Dimensional equals EA .) - swap reduce using rule 15 (S -> Dimensional equals EA .) - exit reduce using rule 15 (S -> Dimensional equals EA .) - elif reduce using rule 15 (S -> Dimensional equals EA .) - else reduce using rule 15 (S -> Dimensional equals EA .) - plus shift and go to state 77 - minus shift and go to state 78 + openParen shift and go to state 47 + int shift and go to state 53 + rea shift and go to state 54 + id shift and go to state 33 - SumOrSub shift and go to state 75 + Dimensional shift and go to state 52 + EA shift and go to state 85 + MultDiv shift and go to state 49 + EAParens shift and go to state 50 + EItem shift and go to state 51 state 56 @@ -1100,7 +1091,7 @@ state 56 id shift and go to state 33 - Dimensional shift and go to state 85 + Dimensional shift and go to state 86 state 57 @@ -1112,21 +1103,21 @@ state 57 string shift and go to state 37 id shift and go to state 33 - DimOrString shift and go to state 86 + DimOrString shift and go to state 87 Dimensional shift and go to state 36 state 58 (19) S -> if Relif ElseOrEmpty . end if - end shift and go to state 87 + end shift and go to state 88 state 59 (36) Relif -> Relif elif . openParen EL closedParen then B - openParen shift and go to state 88 + openParen shift and go to state 89 state 60 @@ -1144,7 +1135,7 @@ state 60 exit reduce using rule 14 (B -> .) end reduce using rule 14 (B -> .) - B shift and go to state 89 + B shift and go to state 90 state 61 @@ -1167,7 +1158,7 @@ state 61 rea shift and go to state 54 id shift and go to state 33 - EL shift and go to state 90 + EL shift and go to state 91 AND shift and go to state 63 Equality shift and go to state 64 EItem shift and go to state 65 @@ -1178,8 +1169,8 @@ state 62 (35) Relif -> openParen EL . closedParen then B (52) EL -> EL . or AND - closedParen shift and go to state 91 - or shift and go to state 92 + closedParen shift and go to state 92 + or shift and go to state 93 state 63 @@ -1190,7 +1181,7 @@ state 63 ! shift/reduce conflict for and resolved as shift closedParen reduce using rule 51 (EL -> AND .) or reduce using rule 51 (EL -> AND .) - and shift and go to state 93 + and shift and go to state 94 ! and [ reduce using rule 51 (EL -> AND .) ] @@ -1214,14 +1205,14 @@ state 65 (65) EQSymbols -> . lessEquals (66) EQSymbols -> . moreEquals - less shift and go to state 95 - more shift and go to state 96 - doubleEquals shift and go to state 97 - notEquals shift and go to state 98 - lessEquals shift and go to state 99 - moreEquals shift and go to state 100 + less shift and go to state 96 + more shift and go to state 97 + doubleEquals shift and go to state 98 + notEquals shift and go to state 99 + lessEquals shift and go to state 100 + moreEquals shift and go to state 101 - EQSymbols shift and go to state 94 + EQSymbols shift and go to state 95 state 66 @@ -1244,7 +1235,7 @@ state 66 rea shift and go to state 54 id shift and go to state 33 - EL shift and go to state 101 + EL shift and go to state 102 AND shift and go to state 63 Equality shift and go to state 64 EItem shift and go to state 65 @@ -1269,7 +1260,7 @@ state 67 rea shift and go to state 54 id shift and go to state 33 - EA shift and go to state 102 + EA shift and go to state 103 MultDiv shift and go to state 49 EAParens shift and go to state 50 EItem shift and go to state 51 @@ -1279,7 +1270,7 @@ state 68 (21) S -> do then B . end do (13) B -> B . S - (15) S -> . Dimensional equals EA + (15) S -> . Dimensional action_7 equals EA action_8 (16) S -> . id parens (17) S -> . read RDimensional (18) S -> . print RDimOrString @@ -1290,7 +1281,7 @@ state 68 (23) S -> . exit (24) Dimensional -> . id DimensionsOrEmpty - end shift and go to state 103 + end shift and go to state 104 id shift and go to state 13 read shift and go to state 17 print shift and go to state 18 @@ -1309,27 +1300,27 @@ state 69 id shift and go to state 33 - Dimensional shift and go to state 104 + Dimensional shift and go to state 105 state 70 (11) F -> F subroutine id B end . subroutine - subroutine shift and go to state 105 + subroutine shift and go to state 106 state 71 (5) Rid -> Rid coma . id - id shift and go to state 106 + id shift and go to state 107 state 72 (9) Dim -> openBra int closedBra openBra . int closedBra - int shift and go to state 107 + int shift and go to state 108 state 73 @@ -1339,7 +1330,7 @@ state 73 (43) SumOrSub -> . plus (44) SumOrSub -> . minus - closedParen shift and go to state 108 + closedParen shift and go to state 109 plus shift and go to state 77 minus shift and go to state 78 @@ -1349,7 +1340,7 @@ state 74 (25) DimensionsOrEmpty -> openParen EA ComaEAOrEmpty . closedParen - closedParen shift and go to state 109 + closedParen shift and go to state 110 state 75 @@ -1362,7 +1353,7 @@ state 75 rea reduce using rule 69 (action_3 -> .) id reduce using rule 69 (action_3 -> .) - action_3 shift and go to state 110 + action_3 shift and go to state 111 state 76 @@ -1383,7 +1374,7 @@ state 76 rea shift and go to state 54 id shift and go to state 33 - EA shift and go to state 111 + EA shift and go to state 112 MultDiv shift and go to state 49 EAParens shift and go to state 50 EItem shift and go to state 51 @@ -1419,7 +1410,7 @@ state 79 rea reduce using rule 71 (action_5 -> .) id reduce using rule 71 (action_5 -> .) - action_5 shift and go to state 112 + action_5 shift and go to state 113 state 80 @@ -1451,6 +1442,12 @@ state 82 plus reduce using rule 58 (EItem -> Dimensional action_1 .) minus reduce using rule 58 (EItem -> Dimensional action_1 .) closedParen reduce using rule 58 (EItem -> Dimensional action_1 .) + less reduce using rule 58 (EItem -> Dimensional action_1 .) + more reduce using rule 58 (EItem -> Dimensional action_1 .) + doubleEquals reduce using rule 58 (EItem -> Dimensional action_1 .) + notEquals reduce using rule 58 (EItem -> Dimensional action_1 .) + lessEquals reduce using rule 58 (EItem -> Dimensional action_1 .) + moreEquals reduce using rule 58 (EItem -> Dimensional action_1 .) end reduce using rule 58 (EItem -> Dimensional action_1 .) id reduce using rule 58 (EItem -> Dimensional action_1 .) read reduce using rule 58 (EItem -> Dimensional action_1 .) @@ -1461,12 +1458,6 @@ state 82 exit reduce using rule 58 (EItem -> Dimensional action_1 .) elif reduce using rule 58 (EItem -> Dimensional action_1 .) else reduce using rule 58 (EItem -> Dimensional action_1 .) - less reduce using rule 58 (EItem -> Dimensional action_1 .) - more reduce using rule 58 (EItem -> Dimensional action_1 .) - doubleEquals reduce using rule 58 (EItem -> Dimensional action_1 .) - notEquals reduce using rule 58 (EItem -> Dimensional action_1 .) - lessEquals reduce using rule 58 (EItem -> Dimensional action_1 .) - moreEquals reduce using rule 58 (EItem -> Dimensional action_1 .) and reduce using rule 58 (EItem -> Dimensional action_1 .) or reduce using rule 58 (EItem -> Dimensional action_1 .) then reduce using rule 58 (EItem -> Dimensional action_1 .) @@ -1482,6 +1473,12 @@ state 83 plus reduce using rule 59 (EItem -> int action_2 .) minus reduce using rule 59 (EItem -> int action_2 .) closedParen reduce using rule 59 (EItem -> int action_2 .) + less reduce using rule 59 (EItem -> int action_2 .) + more reduce using rule 59 (EItem -> int action_2 .) + doubleEquals reduce using rule 59 (EItem -> int action_2 .) + notEquals reduce using rule 59 (EItem -> int action_2 .) + lessEquals reduce using rule 59 (EItem -> int action_2 .) + moreEquals reduce using rule 59 (EItem -> int action_2 .) end reduce using rule 59 (EItem -> int action_2 .) id reduce using rule 59 (EItem -> int action_2 .) read reduce using rule 59 (EItem -> int action_2 .) @@ -1492,12 +1489,6 @@ state 83 exit reduce using rule 59 (EItem -> int action_2 .) elif reduce using rule 59 (EItem -> int action_2 .) else reduce using rule 59 (EItem -> int action_2 .) - less reduce using rule 59 (EItem -> int action_2 .) - more reduce using rule 59 (EItem -> int action_2 .) - doubleEquals reduce using rule 59 (EItem -> int action_2 .) - notEquals reduce using rule 59 (EItem -> int action_2 .) - lessEquals reduce using rule 59 (EItem -> int action_2 .) - moreEquals reduce using rule 59 (EItem -> int action_2 .) and reduce using rule 59 (EItem -> int action_2 .) or reduce using rule 59 (EItem -> int action_2 .) then reduce using rule 59 (EItem -> int action_2 .) @@ -1513,6 +1504,12 @@ state 84 plus reduce using rule 60 (EItem -> rea action_2 .) minus reduce using rule 60 (EItem -> rea action_2 .) closedParen reduce using rule 60 (EItem -> rea action_2 .) + less reduce using rule 60 (EItem -> rea action_2 .) + more reduce using rule 60 (EItem -> rea action_2 .) + doubleEquals reduce using rule 60 (EItem -> rea action_2 .) + notEquals reduce using rule 60 (EItem -> rea action_2 .) + lessEquals reduce using rule 60 (EItem -> rea action_2 .) + moreEquals reduce using rule 60 (EItem -> rea action_2 .) end reduce using rule 60 (EItem -> rea action_2 .) id reduce using rule 60 (EItem -> rea action_2 .) read reduce using rule 60 (EItem -> rea action_2 .) @@ -1523,12 +1520,6 @@ state 84 exit reduce using rule 60 (EItem -> rea action_2 .) elif reduce using rule 60 (EItem -> rea action_2 .) else reduce using rule 60 (EItem -> rea action_2 .) - less reduce using rule 60 (EItem -> rea action_2 .) - more reduce using rule 60 (EItem -> rea action_2 .) - doubleEquals reduce using rule 60 (EItem -> rea action_2 .) - notEquals reduce using rule 60 (EItem -> rea action_2 .) - lessEquals reduce using rule 60 (EItem -> rea action_2 .) - moreEquals reduce using rule 60 (EItem -> rea action_2 .) and reduce using rule 60 (EItem -> rea action_2 .) or reduce using rule 60 (EItem -> rea action_2 .) then reduce using rule 60 (EItem -> rea action_2 .) @@ -1536,6 +1527,30 @@ state 84 state 85 + (15) S -> Dimensional action_7 equals EA . action_8 + (42) EA -> EA . SumOrSub action_3 MultDiv action_4 + (74) action_8 -> . + (43) SumOrSub -> . plus + (44) SumOrSub -> . minus + + end reduce using rule 74 (action_8 -> .) + id reduce using rule 74 (action_8 -> .) + read reduce using rule 74 (action_8 -> .) + print reduce using rule 74 (action_8 -> .) + if reduce using rule 74 (action_8 -> .) + do reduce using rule 74 (action_8 -> .) + swap reduce using rule 74 (action_8 -> .) + exit reduce using rule 74 (action_8 -> .) + elif reduce using rule 74 (action_8 -> .) + else reduce using rule 74 (action_8 -> .) + plus shift and go to state 77 + minus shift and go to state 78 + + action_8 shift and go to state 114 + SumOrSub shift and go to state 75 + +state 86 + (30) RDimensional -> RDimensional coma Dimensional . coma reduce using rule 30 (RDimensional -> RDimensional coma Dimensional .) @@ -1551,7 +1566,7 @@ state 85 else reduce using rule 30 (RDimensional -> RDimensional coma Dimensional .) -state 86 +state 87 (32) RDimOrString -> RDimOrString coma DimOrString . @@ -1568,14 +1583,14 @@ state 86 else reduce using rule 32 (RDimOrString -> RDimOrString coma DimOrString .) -state 87 +state 88 (19) S -> if Relif ElseOrEmpty end . if - if shift and go to state 113 + if shift and go to state 115 -state 88 +state 89 (36) Relif -> Relif elif openParen . EL closedParen then B (51) EL -> . AND @@ -1596,17 +1611,17 @@ state 88 rea shift and go to state 54 id shift and go to state 33 - EL shift and go to state 114 + EL shift and go to state 116 AND shift and go to state 63 Equality shift and go to state 64 EItem shift and go to state 65 Dimensional shift and go to state 52 -state 89 +state 90 (37) ElseOrEmpty -> else B . (13) B -> B . S - (15) S -> . Dimensional equals EA + (15) S -> . Dimensional action_7 equals EA action_8 (16) S -> . id parens (17) S -> . read RDimensional (18) S -> . print RDimOrString @@ -1629,24 +1644,24 @@ state 89 S shift and go to state 15 Dimensional shift and go to state 16 -state 90 +state 91 (56) Equality -> openParen EL . closedParen (52) EL -> EL . or AND - closedParen shift and go to state 115 - or shift and go to state 92 - - -state 91 - - (35) Relif -> openParen EL closedParen . then B - - then shift and go to state 116 + closedParen shift and go to state 117 + or shift and go to state 93 state 92 + (35) Relif -> openParen EL closedParen . then B + + then shift and go to state 118 + + +state 93 + (52) EL -> EL or . AND (53) AND -> . Equality (54) AND -> . AND and Equality @@ -1664,12 +1679,12 @@ state 92 rea shift and go to state 54 id shift and go to state 33 - AND shift and go to state 117 + AND shift and go to state 119 Equality shift and go to state 64 EItem shift and go to state 65 Dimensional shift and go to state 52 -state 93 +state 94 (54) AND -> AND and . Equality (55) Equality -> . EItem EQSymbols EItem @@ -1686,11 +1701,11 @@ state 93 rea shift and go to state 54 id shift and go to state 33 - Equality shift and go to state 118 + Equality shift and go to state 120 EItem shift and go to state 65 Dimensional shift and go to state 52 -state 94 +state 95 (55) Equality -> EItem EQSymbols . EItem (58) EItem -> . Dimensional action_1 @@ -1702,10 +1717,10 @@ state 94 rea shift and go to state 54 id shift and go to state 33 - EItem shift and go to state 119 + EItem shift and go to state 121 Dimensional shift and go to state 52 -state 95 +state 96 (61) EQSymbols -> less . @@ -1714,7 +1729,7 @@ state 95 id reduce using rule 61 (EQSymbols -> less .) -state 96 +state 97 (62) EQSymbols -> more . @@ -1723,7 +1738,7 @@ state 96 id reduce using rule 62 (EQSymbols -> more .) -state 97 +state 98 (63) EQSymbols -> doubleEquals . @@ -1732,7 +1747,7 @@ state 97 id reduce using rule 63 (EQSymbols -> doubleEquals .) -state 98 +state 99 (64) EQSymbols -> notEquals . @@ -1741,7 +1756,7 @@ state 98 id reduce using rule 64 (EQSymbols -> notEquals .) -state 99 +state 100 (65) EQSymbols -> lessEquals . @@ -1750,7 +1765,7 @@ state 99 id reduce using rule 65 (EQSymbols -> lessEquals .) -state 100 +state 101 (66) EQSymbols -> moreEquals . @@ -1759,7 +1774,7 @@ state 100 id reduce using rule 66 (EQSymbols -> moreEquals .) -state 101 +state 102 (57) Equality -> not EL . (52) EL -> EL . or AND @@ -1767,32 +1782,32 @@ state 101 ! shift/reduce conflict for or resolved as shift and reduce using rule 57 (Equality -> not EL .) closedParen reduce using rule 57 (Equality -> not EL .) - or shift and go to state 92 + or shift and go to state 93 ! or [ reduce using rule 57 (Equality -> not EL .) ] -state 102 +state 103 (20) S -> do id equals EA . coma EA IntOrEmpty then B end do (42) EA -> EA . SumOrSub action_3 MultDiv action_4 (43) SumOrSub -> . plus (44) SumOrSub -> . minus - coma shift and go to state 120 + coma shift and go to state 122 plus shift and go to state 77 minus shift and go to state 78 SumOrSub shift and go to state 75 -state 103 +state 104 (21) S -> do then B end . do - do shift and go to state 121 + do shift and go to state 123 -state 104 +state 105 (22) S -> swap Dimensional coma Dimensional . @@ -1808,7 +1823,7 @@ state 104 else reduce using rule 22 (S -> swap Dimensional coma Dimensional .) -state 105 +state 106 (11) F -> F subroutine id B end subroutine . @@ -1823,7 +1838,7 @@ state 105 exit reduce using rule 11 (F -> F subroutine id B end subroutine .) -state 106 +state 107 (5) Rid -> Rid coma id . @@ -1841,14 +1856,14 @@ state 106 exit reduce using rule 5 (Rid -> Rid coma id .) -state 107 +state 108 (9) Dim -> openBra int closedBra openBra int . closedBra - closedBra shift and go to state 122 + closedBra shift and go to state 124 -state 108 +state 109 (50) EAParens -> openParen EA closedParen . @@ -1871,7 +1886,7 @@ state 108 then reduce using rule 50 (EAParens -> openParen EA closedParen .) -state 109 +state 110 (25) DimensionsOrEmpty -> openParen EA ComaEAOrEmpty closedParen . @@ -1903,7 +1918,7 @@ state 109 then reduce using rule 25 (DimensionsOrEmpty -> openParen EA ComaEAOrEmpty closedParen .) -state 110 +state 111 (42) EA -> EA SumOrSub action_3 . MultDiv action_4 (45) MultDiv -> . EAParens @@ -1920,12 +1935,12 @@ state 110 rea shift and go to state 54 id shift and go to state 33 - MultDiv shift and go to state 123 + MultDiv shift and go to state 125 EAParens shift and go to state 50 EItem shift and go to state 51 Dimensional shift and go to state 52 -state 111 +state 112 (27) ComaEAOrEmpty -> coma EA . (42) EA -> EA . SumOrSub action_3 MultDiv action_4 @@ -1938,7 +1953,7 @@ state 111 SumOrSub shift and go to state 75 -state 112 +state 113 (46) MultDiv -> MultDiv MDSymbols action_5 . EAParens action_6 (49) EAParens -> . EItem @@ -1953,11 +1968,27 @@ state 112 rea shift and go to state 54 id shift and go to state 33 - EAParens shift and go to state 124 + EAParens shift and go to state 126 EItem shift and go to state 51 Dimensional shift and go to state 52 -state 113 +state 114 + + (15) S -> Dimensional action_7 equals EA action_8 . + + end reduce using rule 15 (S -> Dimensional action_7 equals EA action_8 .) + id reduce using rule 15 (S -> Dimensional action_7 equals EA action_8 .) + read reduce using rule 15 (S -> Dimensional action_7 equals EA action_8 .) + print reduce using rule 15 (S -> Dimensional action_7 equals EA action_8 .) + if reduce using rule 15 (S -> Dimensional action_7 equals EA action_8 .) + do reduce using rule 15 (S -> Dimensional action_7 equals EA action_8 .) + swap reduce using rule 15 (S -> Dimensional action_7 equals EA action_8 .) + exit reduce using rule 15 (S -> Dimensional action_7 equals EA action_8 .) + elif reduce using rule 15 (S -> Dimensional action_7 equals EA action_8 .) + else reduce using rule 15 (S -> Dimensional action_7 equals EA action_8 .) + + +state 115 (19) S -> if Relif ElseOrEmpty end if . @@ -1973,16 +2004,16 @@ state 113 else reduce using rule 19 (S -> if Relif ElseOrEmpty end if .) -state 114 +state 116 (36) Relif -> Relif elif openParen EL . closedParen then B (52) EL -> EL . or AND - closedParen shift and go to state 125 - or shift and go to state 92 + closedParen shift and go to state 127 + or shift and go to state 93 -state 115 +state 117 (56) Equality -> openParen EL closedParen . @@ -1991,7 +2022,7 @@ state 115 or reduce using rule 56 (Equality -> openParen EL closedParen .) -state 116 +state 118 (35) Relif -> openParen EL closedParen then . B (13) B -> . B S @@ -2008,9 +2039,9 @@ state 116 else reduce using rule 14 (B -> .) end reduce using rule 14 (B -> .) - B shift and go to state 126 + B shift and go to state 128 -state 117 +state 119 (52) EL -> EL or AND . (54) AND -> AND . and Equality @@ -2018,12 +2049,12 @@ state 117 ! shift/reduce conflict for and resolved as shift closedParen reduce using rule 52 (EL -> EL or AND .) or reduce using rule 52 (EL -> EL or AND .) - and shift and go to state 93 + and shift and go to state 94 ! and [ reduce using rule 52 (EL -> EL or AND .) ] -state 118 +state 120 (54) AND -> AND and Equality . @@ -2032,7 +2063,7 @@ state 118 or reduce using rule 54 (AND -> AND and Equality .) -state 119 +state 121 (55) Equality -> EItem EQSymbols EItem . @@ -2041,7 +2072,7 @@ state 119 or reduce using rule 55 (Equality -> EItem EQSymbols EItem .) -state 120 +state 122 (20) S -> do id equals EA coma . EA IntOrEmpty then B end do (41) EA -> . MultDiv @@ -2060,13 +2091,13 @@ state 120 rea shift and go to state 54 id shift and go to state 33 - EA shift and go to state 127 + EA shift and go to state 129 MultDiv shift and go to state 49 EAParens shift and go to state 50 EItem shift and go to state 51 Dimensional shift and go to state 52 -state 121 +state 123 (21) S -> do then B end do . @@ -2082,14 +2113,14 @@ state 121 else reduce using rule 21 (S -> do then B end do .) -state 122 +state 124 (9) Dim -> openBra int closedBra openBra int closedBra . doubleColon reduce using rule 9 (Dim -> openBra int closedBra openBra int closedBra .) -state 123 +state 125 (42) EA -> EA SumOrSub action_3 MultDiv . action_4 (46) MultDiv -> MultDiv . MDSymbols action_5 EAParens action_6 @@ -2115,10 +2146,10 @@ state 123 mul shift and go to state 80 div shift and go to state 81 - action_4 shift and go to state 128 + action_4 shift and go to state 130 MDSymbols shift and go to state 79 -state 124 +state 126 (46) MultDiv -> MultDiv MDSymbols action_5 EAParens . action_6 (72) action_6 -> . @@ -2141,20 +2172,20 @@ state 124 else reduce using rule 72 (action_6 -> .) then reduce using rule 72 (action_6 -> .) - action_6 shift and go to state 129 + action_6 shift and go to state 131 -state 125 +state 127 (36) Relif -> Relif elif openParen EL closedParen . then B - then shift and go to state 130 + then shift and go to state 132 -state 126 +state 128 (35) Relif -> openParen EL closedParen then B . (13) B -> B . S - (15) S -> . Dimensional equals EA + (15) S -> . Dimensional action_7 equals EA action_8 (16) S -> . id parens (17) S -> . read RDimensional (18) S -> . print RDimOrString @@ -2179,7 +2210,7 @@ state 126 S shift and go to state 15 Dimensional shift and go to state 16 -state 127 +state 129 (20) S -> do id equals EA coma EA . IntOrEmpty then B end do (42) EA -> EA . SumOrSub action_3 MultDiv action_4 @@ -2188,15 +2219,15 @@ state 127 (43) SumOrSub -> . plus (44) SumOrSub -> . minus - coma shift and go to state 131 + coma shift and go to state 133 then reduce using rule 40 (IntOrEmpty -> .) plus shift and go to state 77 minus shift and go to state 78 - IntOrEmpty shift and go to state 132 + IntOrEmpty shift and go to state 134 SumOrSub shift and go to state 75 -state 128 +state 130 (42) EA -> EA SumOrSub action_3 MultDiv action_4 . @@ -2217,7 +2248,7 @@ state 128 then reduce using rule 42 (EA -> EA SumOrSub action_3 MultDiv action_4 .) -state 129 +state 131 (46) MultDiv -> MultDiv MDSymbols action_5 EAParens action_6 . @@ -2240,7 +2271,7 @@ state 129 then reduce using rule 46 (MultDiv -> MultDiv MDSymbols action_5 EAParens action_6 .) -state 130 +state 132 (36) Relif -> Relif elif openParen EL closedParen then . B (13) B -> . B S @@ -2257,27 +2288,27 @@ state 130 else reduce using rule 14 (B -> .) end reduce using rule 14 (B -> .) - B shift and go to state 133 - -state 131 - - (39) IntOrEmpty -> coma . int - - int shift and go to state 134 - - -state 132 - - (20) S -> do id equals EA coma EA IntOrEmpty . then B end do - - then shift and go to state 135 - + B shift and go to state 135 state 133 + (39) IntOrEmpty -> coma . int + + int shift and go to state 136 + + +state 134 + + (20) S -> do id equals EA coma EA IntOrEmpty . then B end do + + then shift and go to state 137 + + +state 135 + (36) Relif -> Relif elif openParen EL closedParen then B . (13) B -> B . S - (15) S -> . Dimensional equals EA + (15) S -> . Dimensional action_7 equals EA action_8 (16) S -> . id parens (17) S -> . read RDimensional (18) S -> . print RDimOrString @@ -2302,14 +2333,14 @@ state 133 S shift and go to state 15 Dimensional shift and go to state 16 -state 134 +state 136 (39) IntOrEmpty -> coma int . then reduce using rule 39 (IntOrEmpty -> coma int .) -state 135 +state 137 (20) S -> do id equals EA coma EA IntOrEmpty then . B end do (13) B -> . B S @@ -2324,13 +2355,13 @@ state 135 swap reduce using rule 14 (B -> .) exit reduce using rule 14 (B -> .) - B shift and go to state 136 + B shift and go to state 138 -state 136 +state 138 (20) S -> do id equals EA coma EA IntOrEmpty then B . end do (13) B -> B . S - (15) S -> . Dimensional equals EA + (15) S -> . Dimensional action_7 equals EA action_8 (16) S -> . id parens (17) S -> . read RDimensional (18) S -> . print RDimOrString @@ -2341,7 +2372,7 @@ state 136 (23) S -> . exit (24) Dimensional -> . id DimensionsOrEmpty - end shift and go to state 137 + end shift and go to state 139 id shift and go to state 13 read shift and go to state 17 print shift and go to state 18 @@ -2353,14 +2384,14 @@ state 136 S shift and go to state 15 Dimensional shift and go to state 16 -state 137 +state 139 (20) S -> do id equals EA coma EA IntOrEmpty then B end . do - do shift and go to state 138 + do shift and go to state 140 -state 138 +state 140 (20) S -> do id equals EA coma EA IntOrEmpty then B end do . @@ -2379,5 +2410,5 @@ WARNING: WARNING: Conflicts: WARNING: WARNING: shift/reduce conflict for and in state 63 resolved as shift -WARNING: shift/reduce conflict for or in state 101 resolved as shift -WARNING: shift/reduce conflict for and in state 117 resolved as shift +WARNING: shift/reduce conflict for or in state 102 resolved as shift +WARNING: shift/reduce conflict for and in state 119 resolved as shift diff --git a/final_lang/parsetab.py b/final_lang/parsetab.py index 0b6782e..1015d09 100644 --- a/final_lang/parsetab.py +++ b/final_lang/parsetab.py @@ -6,9 +6,9 @@ _tabversion = '3.10' _lr_method = 'LALR' -_lr_signature = 'and closedBra closedParen coma div do doubleColon doubleEquals elif else end equals exit id if int integer less lessEquals minus more moreEquals mul not notEquals openBra openParen or parens plus print program rea read real string subroutine swap then\n programa : program id V F B end program\n \n V : V Tipo Dim doubleColon Rid\n |\n \n Rid : id\n | Rid coma id\n \n Tipo : integer\n | real\n \n Dim : openBra int closedBra\n | openBra int closedBra openBra int closedBra\n |\n \n F : F subroutine id B end subroutine\n |\n \n B : B S\n |\n \n S : Dimensional equals EA\n | id parens\n | read RDimensional\n | print RDimOrString\n | if Relif ElseOrEmpty end if\n | do id equals EA coma EA IntOrEmpty then B end do\n | do then B end do\n | swap Dimensional coma Dimensional\n | exit\n \n Dimensional : id DimensionsOrEmpty\n \n DimensionsOrEmpty : openParen EA ComaEAOrEmpty closedParen\n |\n \n ComaEAOrEmpty : coma EA\n |\n \n RDimensional : Dimensional\n | RDimensional coma Dimensional\n \n RDimOrString : DimOrString\n | RDimOrString coma DimOrString\n \n DimOrString : Dimensional\n | string\n \n Relif : openParen EL closedParen then B\n | Relif elif openParen EL closedParen then B\n \n ElseOrEmpty : else B\n |\n \n IntOrEmpty : coma int\n |\n \n EA : MultDiv\n | EA SumOrSub action_3 MultDiv action_4\n \n SumOrSub : plus\n | minus\n \n MultDiv : EAParens\n | MultDiv MDSymbols action_5 EAParens action_6\n \n MDSymbols : mul\n | div\n \n EAParens : EItem\n | openParen EA closedParen\n \n EL : AND\n | EL or AND\n \n AND : Equality\n | AND and Equality\n \n Equality : EItem EQSymbols EItem\n | openParen EL closedParen\n | not EL\n \n EItem : Dimensional action_1\n | int action_2\n | rea action_2\n \n EQSymbols : less\n | more\n | doubleEquals\n | notEquals\n | lessEquals\n | moreEquals\n action_1 :action_2 :action_3 :action_4 :action_5 :action_6 :' +_lr_signature = 'and closedBra closedParen coma div do doubleColon doubleEquals elif else end equals exit id if int integer less lessEquals minus more moreEquals mul not notEquals openBra openParen or parens plus print program rea read real string subroutine swap then\n programa : program id V F B end program\n \n V : V Tipo Dim doubleColon Rid\n |\n \n Rid : id\n | Rid coma id\n \n Tipo : integer\n | real\n \n Dim : openBra int closedBra\n | openBra int closedBra openBra int closedBra\n |\n \n F : F subroutine id B end subroutine\n |\n \n B : B S\n |\n \n S : Dimensional action_7 equals EA action_8\n | id parens\n | read RDimensional\n | print RDimOrString\n | if Relif ElseOrEmpty end if\n | do id equals EA coma EA IntOrEmpty then B end do\n | do then B end do\n | swap Dimensional coma Dimensional\n | exit\n \n Dimensional : id DimensionsOrEmpty\n \n DimensionsOrEmpty : openParen EA ComaEAOrEmpty closedParen\n |\n \n ComaEAOrEmpty : coma EA\n |\n \n RDimensional : Dimensional\n | RDimensional coma Dimensional\n \n RDimOrString : DimOrString\n | RDimOrString coma DimOrString\n \n DimOrString : Dimensional\n | string\n \n Relif : openParen EL closedParen then B\n | Relif elif openParen EL closedParen then B\n \n ElseOrEmpty : else B\n |\n \n IntOrEmpty : coma int\n |\n \n EA : MultDiv\n | EA SumOrSub action_3 MultDiv action_4\n \n SumOrSub : plus\n | minus\n \n MultDiv : EAParens\n | MultDiv MDSymbols action_5 EAParens action_6\n \n MDSymbols : mul\n | div\n \n EAParens : EItem\n | openParen EA closedParen\n \n EL : AND\n | EL or AND\n \n AND : Equality\n | AND and Equality\n \n Equality : EItem EQSymbols EItem\n | openParen EL closedParen\n | not EL\n \n EItem : Dimensional action_1\n | int action_2\n | rea action_2\n \n EQSymbols : less\n | more\n | doubleEquals\n | notEquals\n | lessEquals\n | moreEquals\n action_1 :action_2 :action_3 :action_4 :action_5 :action_6 :action_7 :action_8 :' -_lr_action_items = {'program':([0,14,],[2,29,]),'$end':([1,29,],[0,-1,]),'id':([2,3,4,5,9,10,15,17,18,20,21,22,23,24,26,27,28,30,31,32,33,34,35,36,37,39,41,43,44,45,47,49,50,51,52,53,54,55,56,57,60,61,66,67,68,69,71,75,76,77,78,79,80,81,82,83,84,85,86,88,89,92,93,94,95,96,97,98,99,100,104,105,106,108,109,110,112,113,116,120,121,123,124,126,128,129,130,133,135,136,138,],[3,-3,-12,-14,13,23,-13,33,33,40,33,-23,-14,45,-16,-24,33,33,-17,-29,-26,-18,-31,-33,-34,33,-14,13,-2,-4,33,-41,-45,-49,-67,-68,-68,-15,33,33,-14,33,33,33,13,33,106,-69,33,-43,-44,-71,-47,-48,-58,-59,-60,-30,-32,33,13,33,33,33,-61,-62,-63,-64,-65,-66,-22,-11,-5,-50,-25,33,33,-19,-14,33,-21,-70,-72,13,-42,-46,-14,13,-14,13,-20,]),'integer':([3,4,44,45,106,],[-3,7,-2,-4,-5,]),'real':([3,4,44,45,106,],[-3,8,-2,-4,-5,]),'subroutine':([3,4,5,44,45,70,105,106,],[-3,-12,10,-2,-4,105,-11,-5,]),'end':([3,4,5,9,15,22,23,26,27,31,32,33,34,35,36,37,38,41,43,44,45,49,50,51,52,53,54,55,58,60,68,82,83,84,85,86,89,104,105,106,108,109,113,116,121,123,124,126,128,129,130,133,135,136,138,],[-3,-12,-14,14,-13,-23,-14,-16,-24,-17,-29,-26,-18,-31,-33,-34,-38,-14,70,-2,-4,-41,-45,-49,-67,-68,-68,-15,87,-14,103,-58,-59,-60,-30,-32,-37,-22,-11,-5,-50,-25,-19,-14,-21,-70,-72,-35,-42,-46,-14,-36,-14,137,-20,]),'read':([3,4,5,9,15,22,23,26,27,31,32,33,34,35,36,37,41,43,44,45,49,50,51,52,53,54,55,60,68,82,83,84,85,86,89,104,105,106,108,109,113,116,121,123,124,126,128,129,130,133,135,136,138,],[-3,-12,-14,17,-13,-23,-14,-16,-24,-17,-29,-26,-18,-31,-33,-34,-14,17,-2,-4,-41,-45,-49,-67,-68,-68,-15,-14,17,-58,-59,-60,-30,-32,17,-22,-11,-5,-50,-25,-19,-14,-21,-70,-72,17,-42,-46,-14,17,-14,17,-20,]),'print':([3,4,5,9,15,22,23,26,27,31,32,33,34,35,36,37,41,43,44,45,49,50,51,52,53,54,55,60,68,82,83,84,85,86,89,104,105,106,108,109,113,116,121,123,124,126,128,129,130,133,135,136,138,],[-3,-12,-14,18,-13,-23,-14,-16,-24,-17,-29,-26,-18,-31,-33,-34,-14,18,-2,-4,-41,-45,-49,-67,-68,-68,-15,-14,18,-58,-59,-60,-30,-32,18,-22,-11,-5,-50,-25,-19,-14,-21,-70,-72,18,-42,-46,-14,18,-14,18,-20,]),'if':([3,4,5,9,15,22,23,26,27,31,32,33,34,35,36,37,41,43,44,45,49,50,51,52,53,54,55,60,68,82,83,84,85,86,87,89,104,105,106,108,109,113,116,121,123,124,126,128,129,130,133,135,136,138,],[-3,-12,-14,19,-13,-23,-14,-16,-24,-17,-29,-26,-18,-31,-33,-34,-14,19,-2,-4,-41,-45,-49,-67,-68,-68,-15,-14,19,-58,-59,-60,-30,-32,113,19,-22,-11,-5,-50,-25,-19,-14,-21,-70,-72,19,-42,-46,-14,19,-14,19,-20,]),'do':([3,4,5,9,15,22,23,26,27,31,32,33,34,35,36,37,41,43,44,45,49,50,51,52,53,54,55,60,68,82,83,84,85,86,89,103,104,105,106,108,109,113,116,121,123,124,126,128,129,130,133,135,136,137,138,],[-3,-12,-14,20,-13,-23,-14,-16,-24,-17,-29,-26,-18,-31,-33,-34,-14,20,-2,-4,-41,-45,-49,-67,-68,-68,-15,-14,20,-58,-59,-60,-30,-32,20,121,-22,-11,-5,-50,-25,-19,-14,-21,-70,-72,20,-42,-46,-14,20,-14,20,138,-20,]),'swap':([3,4,5,9,15,22,23,26,27,31,32,33,34,35,36,37,41,43,44,45,49,50,51,52,53,54,55,60,68,82,83,84,85,86,89,104,105,106,108,109,113,116,121,123,124,126,128,129,130,133,135,136,138,],[-3,-12,-14,21,-13,-23,-14,-16,-24,-17,-29,-26,-18,-31,-33,-34,-14,21,-2,-4,-41,-45,-49,-67,-68,-68,-15,-14,21,-58,-59,-60,-30,-32,21,-22,-11,-5,-50,-25,-19,-14,-21,-70,-72,21,-42,-46,-14,21,-14,21,-20,]),'exit':([3,4,5,9,15,22,23,26,27,31,32,33,34,35,36,37,41,43,44,45,49,50,51,52,53,54,55,60,68,82,83,84,85,86,89,104,105,106,108,109,113,116,121,123,124,126,128,129,130,133,135,136,138,],[-3,-12,-14,22,-13,-23,-14,-16,-24,-17,-29,-26,-18,-31,-33,-34,-14,22,-2,-4,-41,-45,-49,-67,-68,-68,-15,-14,22,-58,-59,-60,-30,-32,22,-22,-11,-5,-50,-25,-19,-14,-21,-70,-72,22,-42,-46,-14,22,-14,22,-20,]),'openBra':([6,7,8,46,],[12,-6,-7,72,]),'doubleColon':([6,7,8,11,46,122,],[-10,-6,-7,24,-8,-9,]),'int':([12,28,30,39,47,61,66,67,72,75,76,77,78,79,80,81,88,92,93,94,95,96,97,98,99,100,110,112,120,131,],[25,53,53,53,53,53,53,53,107,-69,53,-43,-44,-71,-47,-48,53,53,53,53,-61,-62,-63,-64,-65,-66,53,53,53,134,]),'parens':([13,],[26,]),'openParen':([13,19,28,30,33,39,47,59,61,66,67,75,76,77,78,79,80,81,88,92,93,110,112,120,],[28,39,47,47,28,61,47,88,61,61,47,-69,47,-43,-44,-71,-47,-48,61,61,61,47,47,47,]),'equals':([13,16,27,40,109,],[-26,30,-24,67,-25,]),'elif':([15,22,26,27,31,32,33,34,35,36,37,38,49,50,51,52,53,54,55,82,83,84,85,86,104,108,109,113,116,121,123,124,126,128,129,130,133,138,],[-13,-23,-16,-24,-17,-29,-26,-18,-31,-33,-34,59,-41,-45,-49,-67,-68,-68,-15,-58,-59,-60,-30,-32,-22,-50,-25,-19,-14,-21,-70,-72,-35,-42,-46,-14,-36,-20,]),'else':([15,22,26,27,31,32,33,34,35,36,37,38,49,50,51,52,53,54,55,82,83,84,85,86,104,108,109,113,116,121,123,124,126,128,129,130,133,138,],[-13,-23,-16,-24,-17,-29,-26,-18,-31,-33,-34,60,-41,-45,-49,-67,-68,-68,-15,-58,-59,-60,-30,-32,-22,-50,-25,-19,-14,-21,-70,-72,-35,-42,-46,-14,-36,-20,]),'string':([18,57,],[37,37,]),'then':([20,27,33,49,50,51,52,53,54,82,83,84,91,108,109,123,124,125,127,128,129,132,134,],[41,-24,-26,-41,-45,-49,-67,-68,-68,-58,-59,-60,116,-50,-25,-70,-72,130,-40,-42,-46,135,-39,]),'closedBra':([25,107,],[46,122,]),'coma':([27,31,32,33,34,35,36,37,42,44,45,48,49,50,51,52,53,54,82,83,84,85,86,102,106,108,109,123,124,127,128,129,],[-24,56,-29,-26,57,-31,-33,-34,69,71,-4,76,-41,-45,-49,-67,-68,-68,-58,-59,-60,-30,-32,120,-5,-50,-25,-70,-72,131,-42,-46,]),'mul':([27,33,49,50,51,52,53,54,82,83,84,108,109,123,124,129,],[-24,-26,80,-45,-49,-67,-68,-68,-58,-59,-60,-50,-25,80,-72,-46,]),'div':([27,33,49,50,51,52,53,54,82,83,84,108,109,123,124,129,],[-24,-26,81,-45,-49,-67,-68,-68,-58,-59,-60,-50,-25,81,-72,-46,]),'plus':([27,33,48,49,50,51,52,53,54,55,73,82,83,84,102,108,109,111,123,124,127,128,129,],[-24,-26,77,-41,-45,-49,-67,-68,-68,77,77,-58,-59,-60,77,-50,-25,77,-70,-72,77,-42,-46,]),'minus':([27,33,48,49,50,51,52,53,54,55,73,82,83,84,102,108,109,111,123,124,127,128,129,],[-24,-26,78,-41,-45,-49,-67,-68,-68,78,78,-58,-59,-60,78,-50,-25,78,-70,-72,78,-42,-46,]),'closedParen':([27,33,48,49,50,51,52,53,54,62,63,64,73,74,82,83,84,90,101,108,109,111,114,115,117,118,119,123,124,128,129,],[-24,-26,-28,-41,-45,-49,-67,-68,-68,91,-51,-53,108,109,-58,-59,-60,115,-57,-50,-25,-27,125,-56,-52,-54,-55,-70,-72,-42,-46,]),'less':([27,33,52,53,54,65,82,83,84,109,],[-24,-26,-67,-68,-68,95,-58,-59,-60,-25,]),'more':([27,33,52,53,54,65,82,83,84,109,],[-24,-26,-67,-68,-68,96,-58,-59,-60,-25,]),'doubleEquals':([27,33,52,53,54,65,82,83,84,109,],[-24,-26,-67,-68,-68,97,-58,-59,-60,-25,]),'notEquals':([27,33,52,53,54,65,82,83,84,109,],[-24,-26,-67,-68,-68,98,-58,-59,-60,-25,]),'lessEquals':([27,33,52,53,54,65,82,83,84,109,],[-24,-26,-67,-68,-68,99,-58,-59,-60,-25,]),'moreEquals':([27,33,52,53,54,65,82,83,84,109,],[-24,-26,-67,-68,-68,100,-58,-59,-60,-25,]),'and':([27,33,52,53,54,63,64,82,83,84,101,109,115,117,118,119,],[-24,-26,-67,-68,-68,93,-53,-58,-59,-60,-57,-25,-56,93,-54,-55,]),'or':([27,33,52,53,54,62,63,64,82,83,84,90,101,109,114,115,117,118,119,],[-24,-26,-67,-68,-68,92,-51,-53,-58,-59,-60,92,92,-25,92,-56,-52,-54,-55,]),'rea':([28,30,39,47,61,66,67,75,76,77,78,79,80,81,88,92,93,94,95,96,97,98,99,100,110,112,120,],[54,54,54,54,54,54,54,-69,54,-43,-44,-71,-47,-48,54,54,54,54,-61,-62,-63,-64,-65,-66,54,54,54,]),'not':([39,61,66,88,92,93,],[66,66,66,66,66,66,]),} +_lr_action_items = {'program':([0,14,],[2,29,]),'$end':([1,29,],[0,-1,]),'id':([2,3,4,5,9,10,15,17,18,20,21,22,23,24,26,27,28,31,32,33,34,35,36,37,39,41,43,44,45,47,49,50,51,52,53,54,55,56,57,60,61,66,67,68,69,71,75,76,77,78,79,80,81,82,83,84,85,86,87,89,90,93,94,95,96,97,98,99,100,101,105,106,107,109,110,111,113,114,115,118,122,123,125,126,128,130,131,132,135,137,138,140,],[3,-3,-12,-14,13,23,-13,33,33,40,33,-23,-14,45,-16,-24,33,-17,-29,-26,-18,-31,-33,-34,33,-14,13,-2,-4,33,-41,-45,-49,-67,-68,-68,33,33,33,-14,33,33,33,13,33,107,-69,33,-43,-44,-71,-47,-48,-58,-59,-60,-74,-30,-32,33,13,33,33,33,-61,-62,-63,-64,-65,-66,-22,-11,-5,-50,-25,33,33,-15,-19,-14,33,-21,-70,-72,13,-42,-46,-14,13,-14,13,-20,]),'integer':([3,4,44,45,107,],[-3,7,-2,-4,-5,]),'real':([3,4,44,45,107,],[-3,8,-2,-4,-5,]),'subroutine':([3,4,5,44,45,70,106,107,],[-3,-12,10,-2,-4,106,-11,-5,]),'end':([3,4,5,9,15,22,23,26,27,31,32,33,34,35,36,37,38,41,43,44,45,49,50,51,52,53,54,58,60,68,82,83,84,85,86,87,90,105,106,107,109,110,114,115,118,123,125,126,128,130,131,132,135,137,138,140,],[-3,-12,-14,14,-13,-23,-14,-16,-24,-17,-29,-26,-18,-31,-33,-34,-38,-14,70,-2,-4,-41,-45,-49,-67,-68,-68,88,-14,104,-58,-59,-60,-74,-30,-32,-37,-22,-11,-5,-50,-25,-15,-19,-14,-21,-70,-72,-35,-42,-46,-14,-36,-14,139,-20,]),'read':([3,4,5,9,15,22,23,26,27,31,32,33,34,35,36,37,41,43,44,45,49,50,51,52,53,54,60,68,82,83,84,85,86,87,90,105,106,107,109,110,114,115,118,123,125,126,128,130,131,132,135,137,138,140,],[-3,-12,-14,17,-13,-23,-14,-16,-24,-17,-29,-26,-18,-31,-33,-34,-14,17,-2,-4,-41,-45,-49,-67,-68,-68,-14,17,-58,-59,-60,-74,-30,-32,17,-22,-11,-5,-50,-25,-15,-19,-14,-21,-70,-72,17,-42,-46,-14,17,-14,17,-20,]),'print':([3,4,5,9,15,22,23,26,27,31,32,33,34,35,36,37,41,43,44,45,49,50,51,52,53,54,60,68,82,83,84,85,86,87,90,105,106,107,109,110,114,115,118,123,125,126,128,130,131,132,135,137,138,140,],[-3,-12,-14,18,-13,-23,-14,-16,-24,-17,-29,-26,-18,-31,-33,-34,-14,18,-2,-4,-41,-45,-49,-67,-68,-68,-14,18,-58,-59,-60,-74,-30,-32,18,-22,-11,-5,-50,-25,-15,-19,-14,-21,-70,-72,18,-42,-46,-14,18,-14,18,-20,]),'if':([3,4,5,9,15,22,23,26,27,31,32,33,34,35,36,37,41,43,44,45,49,50,51,52,53,54,60,68,82,83,84,85,86,87,88,90,105,106,107,109,110,114,115,118,123,125,126,128,130,131,132,135,137,138,140,],[-3,-12,-14,19,-13,-23,-14,-16,-24,-17,-29,-26,-18,-31,-33,-34,-14,19,-2,-4,-41,-45,-49,-67,-68,-68,-14,19,-58,-59,-60,-74,-30,-32,115,19,-22,-11,-5,-50,-25,-15,-19,-14,-21,-70,-72,19,-42,-46,-14,19,-14,19,-20,]),'do':([3,4,5,9,15,22,23,26,27,31,32,33,34,35,36,37,41,43,44,45,49,50,51,52,53,54,60,68,82,83,84,85,86,87,90,104,105,106,107,109,110,114,115,118,123,125,126,128,130,131,132,135,137,138,139,140,],[-3,-12,-14,20,-13,-23,-14,-16,-24,-17,-29,-26,-18,-31,-33,-34,-14,20,-2,-4,-41,-45,-49,-67,-68,-68,-14,20,-58,-59,-60,-74,-30,-32,20,123,-22,-11,-5,-50,-25,-15,-19,-14,-21,-70,-72,20,-42,-46,-14,20,-14,20,140,-20,]),'swap':([3,4,5,9,15,22,23,26,27,31,32,33,34,35,36,37,41,43,44,45,49,50,51,52,53,54,60,68,82,83,84,85,86,87,90,105,106,107,109,110,114,115,118,123,125,126,128,130,131,132,135,137,138,140,],[-3,-12,-14,21,-13,-23,-14,-16,-24,-17,-29,-26,-18,-31,-33,-34,-14,21,-2,-4,-41,-45,-49,-67,-68,-68,-14,21,-58,-59,-60,-74,-30,-32,21,-22,-11,-5,-50,-25,-15,-19,-14,-21,-70,-72,21,-42,-46,-14,21,-14,21,-20,]),'exit':([3,4,5,9,15,22,23,26,27,31,32,33,34,35,36,37,41,43,44,45,49,50,51,52,53,54,60,68,82,83,84,85,86,87,90,105,106,107,109,110,114,115,118,123,125,126,128,130,131,132,135,137,138,140,],[-3,-12,-14,22,-13,-23,-14,-16,-24,-17,-29,-26,-18,-31,-33,-34,-14,22,-2,-4,-41,-45,-49,-67,-68,-68,-14,22,-58,-59,-60,-74,-30,-32,22,-22,-11,-5,-50,-25,-15,-19,-14,-21,-70,-72,22,-42,-46,-14,22,-14,22,-20,]),'openBra':([6,7,8,46,],[12,-6,-7,72,]),'doubleColon':([6,7,8,11,46,124,],[-10,-6,-7,24,-8,-9,]),'int':([12,28,39,47,55,61,66,67,72,75,76,77,78,79,80,81,89,93,94,95,96,97,98,99,100,101,111,113,122,133,],[25,53,53,53,53,53,53,53,108,-69,53,-43,-44,-71,-47,-48,53,53,53,53,-61,-62,-63,-64,-65,-66,53,53,53,136,]),'parens':([13,],[26,]),'openParen':([13,19,28,33,39,47,55,59,61,66,67,75,76,77,78,79,80,81,89,93,94,111,113,122,],[28,39,47,28,61,47,47,89,61,61,47,-69,47,-43,-44,-71,-47,-48,61,61,61,47,47,47,]),'equals':([13,16,27,30,40,110,],[-26,-73,-24,55,67,-25,]),'elif':([15,22,26,27,31,32,33,34,35,36,37,38,49,50,51,52,53,54,82,83,84,85,86,87,105,109,110,114,115,118,123,125,126,128,130,131,132,135,140,],[-13,-23,-16,-24,-17,-29,-26,-18,-31,-33,-34,59,-41,-45,-49,-67,-68,-68,-58,-59,-60,-74,-30,-32,-22,-50,-25,-15,-19,-14,-21,-70,-72,-35,-42,-46,-14,-36,-20,]),'else':([15,22,26,27,31,32,33,34,35,36,37,38,49,50,51,52,53,54,82,83,84,85,86,87,105,109,110,114,115,118,123,125,126,128,130,131,132,135,140,],[-13,-23,-16,-24,-17,-29,-26,-18,-31,-33,-34,60,-41,-45,-49,-67,-68,-68,-58,-59,-60,-74,-30,-32,-22,-50,-25,-15,-19,-14,-21,-70,-72,-35,-42,-46,-14,-36,-20,]),'string':([18,57,],[37,37,]),'then':([20,27,33,49,50,51,52,53,54,82,83,84,92,109,110,125,126,127,129,130,131,134,136,],[41,-24,-26,-41,-45,-49,-67,-68,-68,-58,-59,-60,118,-50,-25,-70,-72,132,-40,-42,-46,137,-39,]),'closedBra':([25,108,],[46,124,]),'coma':([27,31,32,33,34,35,36,37,42,44,45,48,49,50,51,52,53,54,82,83,84,86,87,103,107,109,110,125,126,129,130,131,],[-24,56,-29,-26,57,-31,-33,-34,69,71,-4,76,-41,-45,-49,-67,-68,-68,-58,-59,-60,-30,-32,122,-5,-50,-25,-70,-72,133,-42,-46,]),'mul':([27,33,49,50,51,52,53,54,82,83,84,109,110,125,126,131,],[-24,-26,80,-45,-49,-67,-68,-68,-58,-59,-60,-50,-25,80,-72,-46,]),'div':([27,33,49,50,51,52,53,54,82,83,84,109,110,125,126,131,],[-24,-26,81,-45,-49,-67,-68,-68,-58,-59,-60,-50,-25,81,-72,-46,]),'plus':([27,33,48,49,50,51,52,53,54,73,82,83,84,85,103,109,110,112,125,126,129,130,131,],[-24,-26,77,-41,-45,-49,-67,-68,-68,77,-58,-59,-60,77,77,-50,-25,77,-70,-72,77,-42,-46,]),'minus':([27,33,48,49,50,51,52,53,54,73,82,83,84,85,103,109,110,112,125,126,129,130,131,],[-24,-26,78,-41,-45,-49,-67,-68,-68,78,-58,-59,-60,78,78,-50,-25,78,-70,-72,78,-42,-46,]),'closedParen':([27,33,48,49,50,51,52,53,54,62,63,64,73,74,82,83,84,91,102,109,110,112,116,117,119,120,121,125,126,130,131,],[-24,-26,-28,-41,-45,-49,-67,-68,-68,92,-51,-53,109,110,-58,-59,-60,117,-57,-50,-25,-27,127,-56,-52,-54,-55,-70,-72,-42,-46,]),'less':([27,33,52,53,54,65,82,83,84,110,],[-24,-26,-67,-68,-68,96,-58,-59,-60,-25,]),'more':([27,33,52,53,54,65,82,83,84,110,],[-24,-26,-67,-68,-68,97,-58,-59,-60,-25,]),'doubleEquals':([27,33,52,53,54,65,82,83,84,110,],[-24,-26,-67,-68,-68,98,-58,-59,-60,-25,]),'notEquals':([27,33,52,53,54,65,82,83,84,110,],[-24,-26,-67,-68,-68,99,-58,-59,-60,-25,]),'lessEquals':([27,33,52,53,54,65,82,83,84,110,],[-24,-26,-67,-68,-68,100,-58,-59,-60,-25,]),'moreEquals':([27,33,52,53,54,65,82,83,84,110,],[-24,-26,-67,-68,-68,101,-58,-59,-60,-25,]),'and':([27,33,52,53,54,63,64,82,83,84,102,110,117,119,120,121,],[-24,-26,-67,-68,-68,94,-53,-58,-59,-60,-57,-25,-56,94,-54,-55,]),'or':([27,33,52,53,54,62,63,64,82,83,84,91,102,110,116,117,119,120,121,],[-24,-26,-67,-68,-68,93,-51,-53,-58,-59,-60,93,93,-25,93,-56,-52,-54,-55,]),'rea':([28,39,47,55,61,66,67,75,76,77,78,79,80,81,89,93,94,95,96,97,98,99,100,101,111,113,122,],[54,54,54,54,54,54,54,-69,54,-43,-44,-71,-47,-48,54,54,54,54,-61,-62,-63,-64,-65,-66,54,54,54,]),'not':([39,61,66,89,93,94,],[66,66,66,66,66,66,]),} _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 = {'programa':([0,],[1,]),'V':([3,],[4,]),'F':([4,],[5,]),'Tipo':([4,],[6,]),'B':([5,23,41,60,116,130,135,],[9,43,68,89,126,133,136,]),'Dim':([6,],[11,]),'S':([9,43,68,89,126,133,136,],[15,15,15,15,15,15,15,]),'Dimensional':([9,17,18,21,28,30,39,43,47,56,57,61,66,67,68,69,76,88,89,92,93,94,110,112,120,126,133,136,],[16,32,36,42,52,52,52,16,52,85,36,52,52,52,16,104,52,52,16,52,52,52,52,52,52,16,16,16,]),'DimensionsOrEmpty':([13,33,],[27,27,]),'RDimensional':([17,],[31,]),'RDimOrString':([18,],[34,]),'DimOrString':([18,57,],[35,86,]),'Relif':([19,],[38,]),'Rid':([24,],[44,]),'EA':([28,30,47,67,76,120,],[48,55,73,102,111,127,]),'MultDiv':([28,30,47,67,76,110,120,],[49,49,49,49,49,123,49,]),'EAParens':([28,30,47,67,76,110,112,120,],[50,50,50,50,50,50,124,50,]),'EItem':([28,30,39,47,61,66,67,76,88,92,93,94,110,112,120,],[51,51,65,51,65,65,51,51,65,65,65,119,51,51,51,]),'ElseOrEmpty':([38,],[58,]),'EL':([39,61,66,88,],[62,90,101,114,]),'AND':([39,61,66,88,92,],[63,63,63,63,117,]),'Equality':([39,61,66,88,92,93,],[64,64,64,64,64,118,]),'ComaEAOrEmpty':([48,],[74,]),'SumOrSub':([48,55,73,102,111,127,],[75,75,75,75,75,75,]),'MDSymbols':([49,123,],[79,79,]),'action_1':([52,],[82,]),'action_2':([53,54,],[83,84,]),'EQSymbols':([65,],[94,]),'action_3':([75,],[110,]),'action_5':([79,],[112,]),'action_4':([123,],[128,]),'action_6':([124,],[129,]),'IntOrEmpty':([127,],[132,]),} +_lr_goto_items = {'programa':([0,],[1,]),'V':([3,],[4,]),'F':([4,],[5,]),'Tipo':([4,],[6,]),'B':([5,23,41,60,118,132,137,],[9,43,68,90,128,135,138,]),'Dim':([6,],[11,]),'S':([9,43,68,90,128,135,138,],[15,15,15,15,15,15,15,]),'Dimensional':([9,17,18,21,28,39,43,47,55,56,57,61,66,67,68,69,76,89,90,93,94,95,111,113,122,128,135,138,],[16,32,36,42,52,52,16,52,52,86,36,52,52,52,16,105,52,52,16,52,52,52,52,52,52,16,16,16,]),'DimensionsOrEmpty':([13,33,],[27,27,]),'action_7':([16,],[30,]),'RDimensional':([17,],[31,]),'RDimOrString':([18,],[34,]),'DimOrString':([18,57,],[35,87,]),'Relif':([19,],[38,]),'Rid':([24,],[44,]),'EA':([28,47,55,67,76,122,],[48,73,85,103,112,129,]),'MultDiv':([28,47,55,67,76,111,122,],[49,49,49,49,49,125,49,]),'EAParens':([28,47,55,67,76,111,113,122,],[50,50,50,50,50,50,126,50,]),'EItem':([28,39,47,55,61,66,67,76,89,93,94,95,111,113,122,],[51,65,51,51,65,65,51,51,65,65,65,121,51,51,51,]),'ElseOrEmpty':([38,],[58,]),'EL':([39,61,66,89,],[62,91,102,116,]),'AND':([39,61,66,89,93,],[63,63,63,63,119,]),'Equality':([39,61,66,89,93,94,],[64,64,64,64,64,120,]),'ComaEAOrEmpty':([48,],[74,]),'SumOrSub':([48,73,85,103,112,129,],[75,75,75,75,75,75,]),'MDSymbols':([49,125,],[79,79,]),'action_1':([52,],[82,]),'action_2':([53,54,],[83,84,]),'EQSymbols':([65,],[95,]),'action_3':([75,],[111,]),'action_5':([79,],[113,]),'action_8':([85,],[114,]),'action_4':([125,],[130,]),'action_6':([126,],[131,]),'IntOrEmpty':([129,],[134,]),} _lr_goto = {} for _k, _v in _lr_goto_items.items(): @@ -41,7 +41,7 @@ _lr_productions = [ ('F -> ','F',0,'p_F','fort.py',194), ('B -> B S','B',2,'p_B','fort.py',199), ('B -> ','B',0,'p_B','fort.py',200), - ('S -> Dimensional equals EA','S',3,'p_S','fort.py',205), + ('S -> Dimensional action_7 equals EA action_8','S',5,'p_S','fort.py',205), ('S -> id parens','S',2,'p_S','fort.py',206), ('S -> read RDimensional','S',2,'p_S','fort.py',207), ('S -> print RDimOrString','S',2,'p_S','fort.py',208), @@ -97,6 +97,8 @@ _lr_productions = [ ('action_2 -> ','action_2',0,'p_action_2','fort.py',348), ('action_3 -> ','action_3',0,'p_action_3','fort.py',352), ('action_4 -> ','action_4',0,'p_action_4','fort.py',356), - ('action_5 -> ','action_5',0,'p_action_5','fort.py',368), - ('action_6 -> ','action_6',0,'p_action_6','fort.py',373), + ('action_5 -> ','action_5',0,'p_action_5','fort.py',369), + ('action_6 -> ','action_6',0,'p_action_6','fort.py',374), + ('action_7 -> ','action_7',0,'p_action_7','fort.py',388), + ('action_8 -> ','action_8',0,'p_action_8','fort.py',393), ] diff --git a/final_lang/test2.fort b/final_lang/test2.fort index f095164..658dff3 100644 --- a/final_lang/test2.fort +++ b/final_lang/test2.fort @@ -1,5 +1,5 @@ program test integer :: a, b -a = (2 + 1) * 2 +a = (2 + 1) + 4 * 2 / 3 * b b = a end program \ No newline at end of file diff --git a/final_lang/test2.fort.out b/final_lang/test2.fort.out index 9677fba..7bde334 100644 --- a/final_lang/test2.fort.out +++ b/final_lang/test2.fort.out @@ -1,2 +1,7 @@ + 2 1 T0 -* T0 2 T1 +* 4 2 T1 +/ T1 3 T2 +* T2 b T3 ++ T0 T3 T4 += T4 a += a b