diff --git a/final_lang/fort.py b/final_lang/fort.py index 446345a..7ab9118 100644 --- a/final_lang/fort.py +++ b/final_lang/fort.py @@ -1,7 +1,7 @@ import ply.lex as lex import ply.yacc as yacc import sys -from stack import Stack +from typeValidation import resultingType resultQuadruplets = [] quadrupletIndex = 1 @@ -14,11 +14,12 @@ jumpsStack = [] exitsStack = [] avail = [] for i in range(50): - avail.append('T' + str(i)) + avail.append('$' + str(i)) # Operations related to the table of symbols symbols = {} -currentIndex = 0 +# Our variables start at direction 50, the temps take the first 50 directions. +currentIndex = 50 # Implementation using a dictionary def addSymbol(name, symbolType): @@ -30,12 +31,18 @@ def addSymbol(name, symbolType): 'direction': currentIndex } currentIndex += 1 - + +# Returns the last item of a list without deleting it. def peek(list): if (len(list) == 0): return None return list[len(list) - 1] +# Checks whether or not a an operand is a temp variable. +def isTemp(operan): + return + + tokens = [ 'doubleColon', 'coma', @@ -77,6 +84,7 @@ tokens = [ 'real', 'subroutine', ] + reserved = { 'program' : 'program', 'end' : 'end', @@ -326,7 +334,7 @@ def p_EItem(p): ''' EItem : Dimensional action_1 | int action_2 - | rea action_2 + | rea action_2_rea ''' def p_EQSymbols(p): @@ -342,12 +350,23 @@ def p_EQSymbols(p): def p_action_1(p): "action_1 :" - operandsStack.append(p[-1]) + if p[-1] not in symbols: + raise Exception(f'The variable {p[-1]} was not declared') + direction = symbols[p[-1]]['direction'] + sType = symbols[p[-1]]['type'] + operandsStack.append(f'${direction}') + typesStack.append(sType) def p_action_2(p): "action_2 :" operandsStack.append(p[-1]) + typesStack.append('integer') + +def p_action_2_rea(p): + "action_2_rea :" + operandsStack.append(p[-1]) + typesStack.append('real') def p_action_3(p): "action_3 :" @@ -360,8 +379,12 @@ def p_action_4(p): operator = operatorsStack.pop() operand2 = operandsStack.pop() operand1 = operandsStack.pop() + type2 = typesStack.pop() + type1 = typesStack.pop() + resultType = resultingType(operator, type1, type2) temp = avail.pop(0) operandsStack.append(temp) + typesStack.append(resultType) resultQuadruplets.append(str(operator) + ' ' + str(operand1) + ' ' + str(operand2) + ' ' + str(temp) + '\n') quadrupletIndex += 1 @@ -378,8 +401,12 @@ def p_action_6(p): operator = operatorsStack.pop() operand2 = operandsStack.pop() operand1 = operandsStack.pop() + type2 = typesStack.pop() + type1 = typesStack.pop() + resultType = resultingType(operator, type1, type2) temp = avail.pop(0) operandsStack.append(temp) + typesStack.append(resultType) resultQuadruplets.append(str(operator) + ' ' + str(operand1) + ' ' + str(operand2) + ' ' + str(temp) + '\n') quadrupletIndex += 1 @@ -387,14 +414,25 @@ def p_action_6(p): def p_action_7(p): "action_7 :" - operandsStack.append(p[-1]) + if p[-1] not in symbols: + raise Exception(f'The variable {p[-1]} was not declared') + direction = symbols[p[-1]]['direction'] + sType = symbols[p[-1]]['type'] + operandsStack.append(f'${direction}') + typesStack.append(sType) def p_action_8(p): "action_8 :" operand2 = operandsStack.pop() operand1 = operandsStack.pop() + type2 = typesStack.pop() + type1 = typesStack.pop() + # Result type only gets called to make sure the types are compatible. + resultingType('=', type1, type2) resultQuadruplets.append('= ' + str(operand2) + ' ' + str(operand1) + '\n') + + def p_error(p): print('XXX Invalid program') print(p) diff --git a/final_lang/parser.out b/final_lang/parser.out index 9154835..f897466 100644 --- a/final_lang/parser.out +++ b/final_lang/parser.out @@ -62,7 +62,7 @@ Rule 56 Equality -> openParen EL closedParen Rule 57 Equality -> not EL Rule 58 EItem -> Dimensional action_1 Rule 59 EItem -> int action_2 -Rule 60 EItem -> rea action_2 +Rule 60 EItem -> rea action_2_rea Rule 61 EQSymbols -> less Rule 62 EQSymbols -> more Rule 63 EQSymbols -> doubleEquals @@ -71,12 +71,13 @@ Rule 65 EQSymbols -> lessEquals Rule 66 EQSymbols -> moreEquals Rule 67 action_1 -> Rule 68 action_2 -> -Rule 69 action_3 -> -Rule 70 action_4 -> -Rule 71 action_5 -> -Rule 72 action_6 -> -Rule 73 action_7 -> -Rule 74 action_8 -> +Rule 69 action_2_rea -> +Rule 70 action_3 -> +Rule 71 action_4 -> +Rule 72 action_5 -> +Rule 73 action_6 -> +Rule 74 action_7 -> +Rule 75 action_8 -> Terminals, with rules where they appear @@ -150,7 +151,8 @@ SumOrSub : 42 Tipo : 2 V : 1 2 action_1 : 58 -action_2 : 59 60 +action_2 : 59 +action_2_rea : 60 action_3 : 42 action_4 : 42 action_5 : 46 @@ -362,9 +364,9 @@ state 15 state 16 (15) S -> Dimensional . action_7 equals EA action_8 - (73) action_7 -> . + (74) action_7 -> . - equals reduce using rule 73 (action_7 -> .) + equals reduce using rule 74 (action_7 -> .) action_7 shift and go to state 30 @@ -534,7 +536,7 @@ state 28 (50) EAParens -> . openParen EA closedParen (58) EItem -> . Dimensional action_1 (59) EItem -> . int action_2 - (60) EItem -> . rea action_2 + (60) EItem -> . rea action_2_rea (24) Dimensional -> . id DimensionsOrEmpty openParen shift and go to state 47 @@ -726,7 +728,7 @@ state 39 (57) Equality -> . not EL (58) EItem -> . Dimensional action_1 (59) EItem -> . int action_2 - (60) EItem -> . rea action_2 + (60) EItem -> . rea action_2_rea (24) Dimensional -> . id DimensionsOrEmpty openParen shift and go to state 61 @@ -856,7 +858,7 @@ state 47 (50) EAParens -> . openParen EA closedParen (58) EItem -> . Dimensional action_1 (59) EItem -> . int action_2 - (60) EItem -> . rea action_2 + (60) EItem -> . rea action_2_rea (24) Dimensional -> . id DimensionsOrEmpty openParen shift and go to state 47 @@ -1028,36 +1030,36 @@ state 53 state 54 - (60) EItem -> rea . action_2 - (68) action_2 -> . + (60) EItem -> rea . action_2_rea + (69) action_2_rea -> . - mul reduce using rule 68 (action_2 -> .) - div reduce using rule 68 (action_2 -> .) - coma reduce using rule 68 (action_2 -> .) - 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 -> .) - print reduce using rule 68 (action_2 -> .) - if reduce using rule 68 (action_2 -> .) - do reduce using rule 68 (action_2 -> .) - swap reduce using rule 68 (action_2 -> .) - exit reduce using rule 68 (action_2 -> .) - elif reduce using rule 68 (action_2 -> .) - else 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 -> .) + mul reduce using rule 69 (action_2_rea -> .) + div reduce using rule 69 (action_2_rea -> .) + coma reduce using rule 69 (action_2_rea -> .) + plus reduce using rule 69 (action_2_rea -> .) + minus reduce using rule 69 (action_2_rea -> .) + closedParen reduce using rule 69 (action_2_rea -> .) + less reduce using rule 69 (action_2_rea -> .) + more reduce using rule 69 (action_2_rea -> .) + doubleEquals reduce using rule 69 (action_2_rea -> .) + notEquals reduce using rule 69 (action_2_rea -> .) + lessEquals reduce using rule 69 (action_2_rea -> .) + moreEquals reduce using rule 69 (action_2_rea -> .) + end reduce using rule 69 (action_2_rea -> .) + id reduce using rule 69 (action_2_rea -> .) + read reduce using rule 69 (action_2_rea -> .) + print reduce using rule 69 (action_2_rea -> .) + if reduce using rule 69 (action_2_rea -> .) + do reduce using rule 69 (action_2_rea -> .) + swap reduce using rule 69 (action_2_rea -> .) + exit reduce using rule 69 (action_2_rea -> .) + elif reduce using rule 69 (action_2_rea -> .) + else reduce using rule 69 (action_2_rea -> .) + and reduce using rule 69 (action_2_rea -> .) + or reduce using rule 69 (action_2_rea -> .) + then reduce using rule 69 (action_2_rea -> .) - action_2 shift and go to state 84 + action_2_rea shift and go to state 84 state 55 @@ -1070,7 +1072,7 @@ state 55 (50) EAParens -> . openParen EA closedParen (58) EItem -> . Dimensional action_1 (59) EItem -> . int action_2 - (60) EItem -> . rea action_2 + (60) EItem -> . rea action_2_rea (24) Dimensional -> . id DimensionsOrEmpty openParen shift and go to state 47 @@ -1149,7 +1151,7 @@ state 61 (57) Equality -> . not EL (58) EItem -> . Dimensional action_1 (59) EItem -> . int action_2 - (60) EItem -> . rea action_2 + (60) EItem -> . rea action_2_rea (24) Dimensional -> . id DimensionsOrEmpty openParen shift and go to state 61 @@ -1226,7 +1228,7 @@ state 66 (57) Equality -> . not EL (58) EItem -> . Dimensional action_1 (59) EItem -> . int action_2 - (60) EItem -> . rea action_2 + (60) EItem -> . rea action_2_rea (24) Dimensional -> . id DimensionsOrEmpty openParen shift and go to state 61 @@ -1252,7 +1254,7 @@ state 67 (50) EAParens -> . openParen EA closedParen (58) EItem -> . Dimensional action_1 (59) EItem -> . int action_2 - (60) EItem -> . rea action_2 + (60) EItem -> . rea action_2_rea (24) Dimensional -> . id DimensionsOrEmpty openParen shift and go to state 47 @@ -1346,12 +1348,12 @@ state 74 state 75 (42) EA -> EA SumOrSub . action_3 MultDiv action_4 - (69) action_3 -> . + (70) action_3 -> . - openParen reduce using rule 69 (action_3 -> .) - int reduce using rule 69 (action_3 -> .) - rea reduce using rule 69 (action_3 -> .) - id reduce using rule 69 (action_3 -> .) + openParen reduce using rule 70 (action_3 -> .) + int reduce using rule 70 (action_3 -> .) + rea reduce using rule 70 (action_3 -> .) + id reduce using rule 70 (action_3 -> .) action_3 shift and go to state 111 @@ -1366,7 +1368,7 @@ state 76 (50) EAParens -> . openParen EA closedParen (58) EItem -> . Dimensional action_1 (59) EItem -> . int action_2 - (60) EItem -> . rea action_2 + (60) EItem -> . rea action_2_rea (24) Dimensional -> . id DimensionsOrEmpty openParen shift and go to state 47 @@ -1403,12 +1405,12 @@ state 78 state 79 (46) MultDiv -> MultDiv MDSymbols . action_5 EAParens action_6 - (71) action_5 -> . + (72) action_5 -> . - openParen reduce using rule 71 (action_5 -> .) - int reduce using rule 71 (action_5 -> .) - rea reduce using rule 71 (action_5 -> .) - id reduce using rule 71 (action_5 -> .) + openParen reduce using rule 72 (action_5 -> .) + int reduce using rule 72 (action_5 -> .) + rea reduce using rule 72 (action_5 -> .) + id reduce using rule 72 (action_5 -> .) action_5 shift and go to state 113 @@ -1496,53 +1498,53 @@ state 83 state 84 - (60) EItem -> rea action_2 . + (60) EItem -> rea action_2_rea . - mul reduce using rule 60 (EItem -> rea action_2 .) - div reduce using rule 60 (EItem -> rea action_2 .) - coma reduce using rule 60 (EItem -> rea action_2 .) - 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 .) - print reduce using rule 60 (EItem -> rea action_2 .) - if reduce using rule 60 (EItem -> rea action_2 .) - do reduce using rule 60 (EItem -> rea action_2 .) - swap reduce using rule 60 (EItem -> rea action_2 .) - 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 .) - 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 .) + mul reduce using rule 60 (EItem -> rea action_2_rea .) + div reduce using rule 60 (EItem -> rea action_2_rea .) + coma reduce using rule 60 (EItem -> rea action_2_rea .) + plus reduce using rule 60 (EItem -> rea action_2_rea .) + minus reduce using rule 60 (EItem -> rea action_2_rea .) + closedParen reduce using rule 60 (EItem -> rea action_2_rea .) + less reduce using rule 60 (EItem -> rea action_2_rea .) + more reduce using rule 60 (EItem -> rea action_2_rea .) + doubleEquals reduce using rule 60 (EItem -> rea action_2_rea .) + notEquals reduce using rule 60 (EItem -> rea action_2_rea .) + lessEquals reduce using rule 60 (EItem -> rea action_2_rea .) + moreEquals reduce using rule 60 (EItem -> rea action_2_rea .) + end reduce using rule 60 (EItem -> rea action_2_rea .) + id reduce using rule 60 (EItem -> rea action_2_rea .) + read reduce using rule 60 (EItem -> rea action_2_rea .) + print reduce using rule 60 (EItem -> rea action_2_rea .) + if reduce using rule 60 (EItem -> rea action_2_rea .) + do reduce using rule 60 (EItem -> rea action_2_rea .) + swap reduce using rule 60 (EItem -> rea action_2_rea .) + exit reduce using rule 60 (EItem -> rea action_2_rea .) + elif reduce using rule 60 (EItem -> rea action_2_rea .) + else reduce using rule 60 (EItem -> rea action_2_rea .) + and reduce using rule 60 (EItem -> rea action_2_rea .) + or reduce using rule 60 (EItem -> rea action_2_rea .) + then reduce using rule 60 (EItem -> rea action_2_rea .) state 85 (15) S -> Dimensional action_7 equals EA . action_8 (42) EA -> EA . SumOrSub action_3 MultDiv action_4 - (74) action_8 -> . + (75) 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 -> .) + end reduce using rule 75 (action_8 -> .) + id reduce using rule 75 (action_8 -> .) + read reduce using rule 75 (action_8 -> .) + print reduce using rule 75 (action_8 -> .) + if reduce using rule 75 (action_8 -> .) + do reduce using rule 75 (action_8 -> .) + swap reduce using rule 75 (action_8 -> .) + exit reduce using rule 75 (action_8 -> .) + elif reduce using rule 75 (action_8 -> .) + else reduce using rule 75 (action_8 -> .) plus shift and go to state 77 minus shift and go to state 78 @@ -1602,7 +1604,7 @@ state 89 (57) Equality -> . not EL (58) EItem -> . Dimensional action_1 (59) EItem -> . int action_2 - (60) EItem -> . rea action_2 + (60) EItem -> . rea action_2_rea (24) Dimensional -> . id DimensionsOrEmpty openParen shift and go to state 61 @@ -1670,7 +1672,7 @@ state 93 (57) Equality -> . not EL (58) EItem -> . Dimensional action_1 (59) EItem -> . int action_2 - (60) EItem -> . rea action_2 + (60) EItem -> . rea action_2_rea (24) Dimensional -> . id DimensionsOrEmpty openParen shift and go to state 61 @@ -1692,7 +1694,7 @@ state 94 (57) Equality -> . not EL (58) EItem -> . Dimensional action_1 (59) EItem -> . int action_2 - (60) EItem -> . rea action_2 + (60) EItem -> . rea action_2_rea (24) Dimensional -> . id DimensionsOrEmpty openParen shift and go to state 61 @@ -1710,7 +1712,7 @@ state 95 (55) Equality -> EItem EQSymbols . EItem (58) EItem -> . Dimensional action_1 (59) EItem -> . int action_2 - (60) EItem -> . rea action_2 + (60) EItem -> . rea action_2_rea (24) Dimensional -> . id DimensionsOrEmpty int shift and go to state 53 @@ -1927,7 +1929,7 @@ state 111 (50) EAParens -> . openParen EA closedParen (58) EItem -> . Dimensional action_1 (59) EItem -> . int action_2 - (60) EItem -> . rea action_2 + (60) EItem -> . rea action_2_rea (24) Dimensional -> . id DimensionsOrEmpty openParen shift and go to state 47 @@ -1960,7 +1962,7 @@ state 113 (50) EAParens -> . openParen EA closedParen (58) EItem -> . Dimensional action_1 (59) EItem -> . int action_2 - (60) EItem -> . rea action_2 + (60) EItem -> . rea action_2_rea (24) Dimensional -> . id DimensionsOrEmpty openParen shift and go to state 47 @@ -2083,7 +2085,7 @@ state 122 (50) EAParens -> . openParen EA closedParen (58) EItem -> . Dimensional action_1 (59) EItem -> . int action_2 - (60) EItem -> . rea action_2 + (60) EItem -> . rea action_2_rea (24) Dimensional -> . id DimensionsOrEmpty openParen shift and go to state 47 @@ -2124,25 +2126,25 @@ state 125 (42) EA -> EA SumOrSub action_3 MultDiv . action_4 (46) MultDiv -> MultDiv . MDSymbols action_5 EAParens action_6 - (70) action_4 -> . + (71) action_4 -> . (47) MDSymbols -> . mul (48) MDSymbols -> . div - coma reduce using rule 70 (action_4 -> .) - plus reduce using rule 70 (action_4 -> .) - minus reduce using rule 70 (action_4 -> .) - closedParen reduce using rule 70 (action_4 -> .) - end reduce using rule 70 (action_4 -> .) - id reduce using rule 70 (action_4 -> .) - read reduce using rule 70 (action_4 -> .) - print reduce using rule 70 (action_4 -> .) - if reduce using rule 70 (action_4 -> .) - do reduce using rule 70 (action_4 -> .) - swap reduce using rule 70 (action_4 -> .) - exit reduce using rule 70 (action_4 -> .) - elif reduce using rule 70 (action_4 -> .) - else reduce using rule 70 (action_4 -> .) - then reduce using rule 70 (action_4 -> .) + coma reduce using rule 71 (action_4 -> .) + plus reduce using rule 71 (action_4 -> .) + minus reduce using rule 71 (action_4 -> .) + closedParen reduce using rule 71 (action_4 -> .) + end reduce using rule 71 (action_4 -> .) + id reduce using rule 71 (action_4 -> .) + read reduce using rule 71 (action_4 -> .) + print reduce using rule 71 (action_4 -> .) + if reduce using rule 71 (action_4 -> .) + do reduce using rule 71 (action_4 -> .) + swap reduce using rule 71 (action_4 -> .) + exit reduce using rule 71 (action_4 -> .) + elif reduce using rule 71 (action_4 -> .) + else reduce using rule 71 (action_4 -> .) + then reduce using rule 71 (action_4 -> .) mul shift and go to state 80 div shift and go to state 81 @@ -2152,25 +2154,25 @@ state 125 state 126 (46) MultDiv -> MultDiv MDSymbols action_5 EAParens . action_6 - (72) action_6 -> . + (73) action_6 -> . - mul reduce using rule 72 (action_6 -> .) - div reduce using rule 72 (action_6 -> .) - coma reduce using rule 72 (action_6 -> .) - plus reduce using rule 72 (action_6 -> .) - minus reduce using rule 72 (action_6 -> .) - closedParen reduce using rule 72 (action_6 -> .) - end reduce using rule 72 (action_6 -> .) - id reduce using rule 72 (action_6 -> .) - read reduce using rule 72 (action_6 -> .) - print reduce using rule 72 (action_6 -> .) - if reduce using rule 72 (action_6 -> .) - do reduce using rule 72 (action_6 -> .) - swap reduce using rule 72 (action_6 -> .) - exit reduce using rule 72 (action_6 -> .) - elif reduce using rule 72 (action_6 -> .) - else reduce using rule 72 (action_6 -> .) - then reduce using rule 72 (action_6 -> .) + mul reduce using rule 73 (action_6 -> .) + div reduce using rule 73 (action_6 -> .) + coma reduce using rule 73 (action_6 -> .) + plus reduce using rule 73 (action_6 -> .) + minus reduce using rule 73 (action_6 -> .) + closedParen reduce using rule 73 (action_6 -> .) + end reduce using rule 73 (action_6 -> .) + id reduce using rule 73 (action_6 -> .) + read reduce using rule 73 (action_6 -> .) + print reduce using rule 73 (action_6 -> .) + if reduce using rule 73 (action_6 -> .) + do reduce using rule 73 (action_6 -> .) + swap reduce using rule 73 (action_6 -> .) + exit reduce using rule 73 (action_6 -> .) + elif reduce using rule 73 (action_6 -> .) + else reduce using rule 73 (action_6 -> .) + then reduce using rule 73 (action_6 -> .) action_6 shift and go to state 131 diff --git a/final_lang/parsetab.py b/final_lang/parsetab.py index 1015d09..027d195 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 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_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_rea\n \n EQSymbols : less\n | more\n | doubleEquals\n | notEquals\n | lessEquals\n | moreEquals\n action_1 :action_2 :action_2_rea :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,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_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,-69,33,33,33,-14,33,33,33,13,33,107,-70,33,-43,-44,-72,-47,-48,-58,-59,-60,-75,-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,-71,-73,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,-69,88,-14,104,-58,-59,-60,-75,-30,-32,-37,-22,-11,-5,-50,-25,-15,-19,-14,-21,-71,-73,-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,-69,-14,17,-58,-59,-60,-75,-30,-32,17,-22,-11,-5,-50,-25,-15,-19,-14,-21,-71,-73,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,-69,-14,18,-58,-59,-60,-75,-30,-32,18,-22,-11,-5,-50,-25,-15,-19,-14,-21,-71,-73,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,-69,-14,19,-58,-59,-60,-75,-30,-32,115,19,-22,-11,-5,-50,-25,-15,-19,-14,-21,-71,-73,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,-69,-14,20,-58,-59,-60,-75,-30,-32,20,123,-22,-11,-5,-50,-25,-15,-19,-14,-21,-71,-73,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,-69,-14,21,-58,-59,-60,-75,-30,-32,21,-22,-11,-5,-50,-25,-15,-19,-14,-21,-71,-73,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,-69,-14,22,-58,-59,-60,-75,-30,-32,22,-22,-11,-5,-50,-25,-15,-19,-14,-21,-71,-73,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,-70,53,-43,-44,-72,-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,-70,47,-43,-44,-72,-47,-48,61,61,61,47,47,47,]),'equals':([13,16,27,30,40,110,],[-26,-74,-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,-69,-58,-59,-60,-75,-30,-32,-22,-50,-25,-15,-19,-14,-21,-71,-73,-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,-69,-58,-59,-60,-75,-30,-32,-22,-50,-25,-15,-19,-14,-21,-71,-73,-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,-69,-58,-59,-60,118,-50,-25,-71,-73,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,-69,-58,-59,-60,-30,-32,122,-5,-50,-25,-71,-73,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,-69,-58,-59,-60,-50,-25,80,-73,-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,-69,-58,-59,-60,-50,-25,81,-73,-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,-69,77,-58,-59,-60,77,77,-50,-25,77,-71,-73,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,-69,78,-58,-59,-60,78,78,-50,-25,78,-71,-73,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,-69,92,-51,-53,109,110,-58,-59,-60,117,-57,-50,-25,-27,127,-56,-52,-54,-55,-71,-73,-42,-46,]),'less':([27,33,52,53,54,65,82,83,84,110,],[-24,-26,-67,-68,-69,96,-58,-59,-60,-25,]),'more':([27,33,52,53,54,65,82,83,84,110,],[-24,-26,-67,-68,-69,97,-58,-59,-60,-25,]),'doubleEquals':([27,33,52,53,54,65,82,83,84,110,],[-24,-26,-67,-68,-69,98,-58,-59,-60,-25,]),'notEquals':([27,33,52,53,54,65,82,83,84,110,],[-24,-26,-67,-68,-69,99,-58,-59,-60,-25,]),'lessEquals':([27,33,52,53,54,65,82,83,84,110,],[-24,-26,-67,-68,-69,100,-58,-59,-60,-25,]),'moreEquals':([27,33,52,53,54,65,82,83,84,110,],[-24,-26,-67,-68,-69,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,-69,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,-69,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,-70,54,-43,-44,-72,-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,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_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,],[83,]),'action_2_rea':([54,],[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(): @@ -27,78 +27,79 @@ for _k, _v in _lr_goto_items.items(): del _lr_goto_items _lr_productions = [ ("S' -> programa","S'",1,None,None,None), - ('programa -> program id V F B end program','programa',7,'p_programa','fort.py',148), - ('V -> V Tipo Dim doubleColon Rid','V',5,'p_V','fort.py',154), - ('V -> ','V',0,'p_V','fort.py',155), - ('Rid -> id','Rid',1,'p_Rid','fort.py',166), - ('Rid -> Rid coma id','Rid',3,'p_Rid','fort.py',167), - ('Tipo -> integer','Tipo',1,'p_Tipo','fort.py',178), - ('Tipo -> real','Tipo',1,'p_Tipo','fort.py',179), - ('Dim -> openBra int closedBra','Dim',3,'p_Dim','fort.py',186), - ('Dim -> openBra int closedBra openBra int closedBra','Dim',6,'p_Dim','fort.py',187), - ('Dim -> ','Dim',0,'p_Dim','fort.py',188), - ('F -> F subroutine id B end subroutine','F',6,'p_F','fort.py',193), - ('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 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), - ('S -> if Relif ElseOrEmpty end if','S',5,'p_S','fort.py',209), - ('S -> do id equals EA coma EA IntOrEmpty then B end do','S',11,'p_S','fort.py',210), - ('S -> do then B end do','S',5,'p_S','fort.py',211), - ('S -> swap Dimensional coma Dimensional','S',4,'p_S','fort.py',212), - ('S -> exit','S',1,'p_S','fort.py',213), - ('Dimensional -> id DimensionsOrEmpty','Dimensional',2,'p_Dimensional','fort.py',219), - ('DimensionsOrEmpty -> openParen EA ComaEAOrEmpty closedParen','DimensionsOrEmpty',4,'p_DimensionsOrEmpty','fort.py',226), - ('DimensionsOrEmpty -> ','DimensionsOrEmpty',0,'p_DimensionsOrEmpty','fort.py',227), - ('ComaEAOrEmpty -> coma EA','ComaEAOrEmpty',2,'p_ComaEAOrEmpty','fort.py',232), - ('ComaEAOrEmpty -> ','ComaEAOrEmpty',0,'p_ComaEAOrEmpty','fort.py',233), - ('RDimensional -> Dimensional','RDimensional',1,'p_RDimensional','fort.py',238), - ('RDimensional -> RDimensional coma Dimensional','RDimensional',3,'p_RDimensional','fort.py',239), - ('RDimOrString -> DimOrString','RDimOrString',1,'p_RDimOrString','fort.py',244), - ('RDimOrString -> RDimOrString coma DimOrString','RDimOrString',3,'p_RDimOrString','fort.py',245), - ('DimOrString -> Dimensional','DimOrString',1,'p_DimOrString','fort.py',250), - ('DimOrString -> string','DimOrString',1,'p_DimOrString','fort.py',251), - ('Relif -> openParen EL closedParen then B','Relif',5,'p_Relif','fort.py',256), - ('Relif -> Relif elif openParen EL closedParen then B','Relif',7,'p_Relif','fort.py',257), - ('ElseOrEmpty -> else B','ElseOrEmpty',2,'p_ElseOrEmpty','fort.py',262), - ('ElseOrEmpty -> ','ElseOrEmpty',0,'p_ElseOrEmpty','fort.py',263), - ('IntOrEmpty -> coma int','IntOrEmpty',2,'p_IntOrEmpty','fort.py',268), - ('IntOrEmpty -> ','IntOrEmpty',0,'p_IntOrEmpty','fort.py',269), - ('EA -> MultDiv','EA',1,'p_EA','fort.py',274), - ('EA -> EA SumOrSub action_3 MultDiv action_4','EA',5,'p_EA','fort.py',275), - ('SumOrSub -> plus','SumOrSub',1,'p_SumOrSub','fort.py',281), - ('SumOrSub -> minus','SumOrSub',1,'p_SumOrSub','fort.py',282), - ('MultDiv -> EAParens','MultDiv',1,'p_MultDiv','fort.py',288), - ('MultDiv -> MultDiv MDSymbols action_5 EAParens action_6','MultDiv',5,'p_MultDiv','fort.py',289), - ('MDSymbols -> mul','MDSymbols',1,'p_MDSymbols','fort.py',294), - ('MDSymbols -> div','MDSymbols',1,'p_MDSymbols','fort.py',295), - ('EAParens -> EItem','EAParens',1,'p_EAParens','fort.py',301), - ('EAParens -> openParen EA closedParen','EAParens',3,'p_EAParens','fort.py',302), - ('EL -> AND','EL',1,'p_EL','fort.py',307), - ('EL -> EL or AND','EL',3,'p_EL','fort.py',308), - ('AND -> Equality','AND',1,'p_AND','fort.py',313), - ('AND -> AND and Equality','AND',3,'p_AND','fort.py',314), - ('Equality -> EItem EQSymbols EItem','Equality',3,'p_Equality','fort.py',319), - ('Equality -> openParen EL closedParen','Equality',3,'p_Equality','fort.py',320), - ('Equality -> not EL','Equality',2,'p_Equality','fort.py',321), - ('EItem -> Dimensional action_1','EItem',2,'p_EItem','fort.py',326), - ('EItem -> int action_2','EItem',2,'p_EItem','fort.py',327), - ('EItem -> rea action_2','EItem',2,'p_EItem','fort.py',328), - ('EQSymbols -> less','EQSymbols',1,'p_EQSymbols','fort.py',333), - ('EQSymbols -> more','EQSymbols',1,'p_EQSymbols','fort.py',334), - ('EQSymbols -> doubleEquals','EQSymbols',1,'p_EQSymbols','fort.py',335), - ('EQSymbols -> notEquals','EQSymbols',1,'p_EQSymbols','fort.py',336), - ('EQSymbols -> lessEquals','EQSymbols',1,'p_EQSymbols','fort.py',337), - ('EQSymbols -> moreEquals','EQSymbols',1,'p_EQSymbols','fort.py',338), - ('action_1 -> ','action_1',0,'p_action_1','fort.py',343), - ('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',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), + ('programa -> program id V F B end program','programa',7,'p_programa','fort.py',157), + ('V -> V Tipo Dim doubleColon Rid','V',5,'p_V','fort.py',163), + ('V -> ','V',0,'p_V','fort.py',164), + ('Rid -> id','Rid',1,'p_Rid','fort.py',175), + ('Rid -> Rid coma id','Rid',3,'p_Rid','fort.py',176), + ('Tipo -> integer','Tipo',1,'p_Tipo','fort.py',187), + ('Tipo -> real','Tipo',1,'p_Tipo','fort.py',188), + ('Dim -> openBra int closedBra','Dim',3,'p_Dim','fort.py',195), + ('Dim -> openBra int closedBra openBra int closedBra','Dim',6,'p_Dim','fort.py',196), + ('Dim -> ','Dim',0,'p_Dim','fort.py',197), + ('F -> F subroutine id B end subroutine','F',6,'p_F','fort.py',202), + ('F -> ','F',0,'p_F','fort.py',203), + ('B -> B S','B',2,'p_B','fort.py',208), + ('B -> ','B',0,'p_B','fort.py',209), + ('S -> Dimensional action_7 equals EA action_8','S',5,'p_S','fort.py',214), + ('S -> id parens','S',2,'p_S','fort.py',215), + ('S -> read RDimensional','S',2,'p_S','fort.py',216), + ('S -> print RDimOrString','S',2,'p_S','fort.py',217), + ('S -> if Relif ElseOrEmpty end if','S',5,'p_S','fort.py',218), + ('S -> do id equals EA coma EA IntOrEmpty then B end do','S',11,'p_S','fort.py',219), + ('S -> do then B end do','S',5,'p_S','fort.py',220), + ('S -> swap Dimensional coma Dimensional','S',4,'p_S','fort.py',221), + ('S -> exit','S',1,'p_S','fort.py',222), + ('Dimensional -> id DimensionsOrEmpty','Dimensional',2,'p_Dimensional','fort.py',228), + ('DimensionsOrEmpty -> openParen EA ComaEAOrEmpty closedParen','DimensionsOrEmpty',4,'p_DimensionsOrEmpty','fort.py',235), + ('DimensionsOrEmpty -> ','DimensionsOrEmpty',0,'p_DimensionsOrEmpty','fort.py',236), + ('ComaEAOrEmpty -> coma EA','ComaEAOrEmpty',2,'p_ComaEAOrEmpty','fort.py',241), + ('ComaEAOrEmpty -> ','ComaEAOrEmpty',0,'p_ComaEAOrEmpty','fort.py',242), + ('RDimensional -> Dimensional','RDimensional',1,'p_RDimensional','fort.py',247), + ('RDimensional -> RDimensional coma Dimensional','RDimensional',3,'p_RDimensional','fort.py',248), + ('RDimOrString -> DimOrString','RDimOrString',1,'p_RDimOrString','fort.py',253), + ('RDimOrString -> RDimOrString coma DimOrString','RDimOrString',3,'p_RDimOrString','fort.py',254), + ('DimOrString -> Dimensional','DimOrString',1,'p_DimOrString','fort.py',259), + ('DimOrString -> string','DimOrString',1,'p_DimOrString','fort.py',260), + ('Relif -> openParen EL closedParen then B','Relif',5,'p_Relif','fort.py',265), + ('Relif -> Relif elif openParen EL closedParen then B','Relif',7,'p_Relif','fort.py',266), + ('ElseOrEmpty -> else B','ElseOrEmpty',2,'p_ElseOrEmpty','fort.py',271), + ('ElseOrEmpty -> ','ElseOrEmpty',0,'p_ElseOrEmpty','fort.py',272), + ('IntOrEmpty -> coma int','IntOrEmpty',2,'p_IntOrEmpty','fort.py',277), + ('IntOrEmpty -> ','IntOrEmpty',0,'p_IntOrEmpty','fort.py',278), + ('EA -> MultDiv','EA',1,'p_EA','fort.py',283), + ('EA -> EA SumOrSub action_3 MultDiv action_4','EA',5,'p_EA','fort.py',284), + ('SumOrSub -> plus','SumOrSub',1,'p_SumOrSub','fort.py',290), + ('SumOrSub -> minus','SumOrSub',1,'p_SumOrSub','fort.py',291), + ('MultDiv -> EAParens','MultDiv',1,'p_MultDiv','fort.py',297), + ('MultDiv -> MultDiv MDSymbols action_5 EAParens action_6','MultDiv',5,'p_MultDiv','fort.py',298), + ('MDSymbols -> mul','MDSymbols',1,'p_MDSymbols','fort.py',303), + ('MDSymbols -> div','MDSymbols',1,'p_MDSymbols','fort.py',304), + ('EAParens -> EItem','EAParens',1,'p_EAParens','fort.py',310), + ('EAParens -> openParen EA closedParen','EAParens',3,'p_EAParens','fort.py',311), + ('EL -> AND','EL',1,'p_EL','fort.py',316), + ('EL -> EL or AND','EL',3,'p_EL','fort.py',317), + ('AND -> Equality','AND',1,'p_AND','fort.py',322), + ('AND -> AND and Equality','AND',3,'p_AND','fort.py',323), + ('Equality -> EItem EQSymbols EItem','Equality',3,'p_Equality','fort.py',328), + ('Equality -> openParen EL closedParen','Equality',3,'p_Equality','fort.py',329), + ('Equality -> not EL','Equality',2,'p_Equality','fort.py',330), + ('EItem -> Dimensional action_1','EItem',2,'p_EItem','fort.py',335), + ('EItem -> int action_2','EItem',2,'p_EItem','fort.py',336), + ('EItem -> rea action_2_rea','EItem',2,'p_EItem','fort.py',337), + ('EQSymbols -> less','EQSymbols',1,'p_EQSymbols','fort.py',342), + ('EQSymbols -> more','EQSymbols',1,'p_EQSymbols','fort.py',343), + ('EQSymbols -> doubleEquals','EQSymbols',1,'p_EQSymbols','fort.py',344), + ('EQSymbols -> notEquals','EQSymbols',1,'p_EQSymbols','fort.py',345), + ('EQSymbols -> lessEquals','EQSymbols',1,'p_EQSymbols','fort.py',346), + ('EQSymbols -> moreEquals','EQSymbols',1,'p_EQSymbols','fort.py',347), + ('action_1 -> ','action_1',0,'p_action_1','fort.py',352), + ('action_2 -> ','action_2',0,'p_action_2','fort.py',362), + ('action_2_rea -> ','action_2_rea',0,'p_action_2_rea','fort.py',367), + ('action_3 -> ','action_3',0,'p_action_3','fort.py',372), + ('action_4 -> ','action_4',0,'p_action_4','fort.py',376), + ('action_5 -> ','action_5',0,'p_action_5','fort.py',393), + ('action_6 -> ','action_6',0,'p_action_6','fort.py',398), + ('action_7 -> ','action_7',0,'p_action_7','fort.py',416), + ('action_8 -> ','action_8',0,'p_action_8','fort.py',426), ] diff --git a/final_lang/stack.py b/final_lang/stack.py index c5d830b..7f13498 100644 --- a/final_lang/stack.py +++ b/final_lang/stack.py @@ -17,4 +17,6 @@ class Stack: return self.items[len(self.items)-1] def size(self): - return len(self.items) \ No newline at end of file + return len(self.items) + +hello = 'hello' \ No newline at end of file diff --git a/final_lang/test2.fort b/final_lang/test2.fort index c11aba4..7423924 100644 --- a/final_lang/test2.fort +++ b/final_lang/test2.fort @@ -1,6 +1,6 @@ program test integer :: a, b real :: c -a = (2 + 1) + 4 * 2 / 3 * b +a = 2 + 4 * (2 + 1) / 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 7bde334..f87268b 100644 --- a/final_lang/test2.fort.out +++ b/final_lang/test2.fort.out @@ -1,7 +1,7 @@ -+ 2 1 T0 -* 4 2 T1 -/ T1 3 T2 -* T2 b T3 -+ T0 T3 T4 -= T4 a -= a b ++ 2 1 $0 +* 4 $0 $1 +/ $1 3 $2 +* $2 $51 $3 ++ 2 $3 $4 += $4 $50 += $50 $51 diff --git a/final_lang/typeValidation.py b/final_lang/typeValidation.py new file mode 100644 index 0000000..25fb21c --- /dev/null +++ b/final_lang/typeValidation.py @@ -0,0 +1,125 @@ +typeValidationMap = { + '*': { + 'integer': { + 'integer': 'integer', + 'real': 'real', + }, + 'real': { + 'integer': 'real', + 'real': 'real' + }, + }, + '+': { + 'integer': { + 'integer': 'integer', + 'real': 'real', + }, + 'real': { + 'integer': 'real', + 'real': 'real' + }, + }, + '-': { + 'integer': { + 'integer': 'integer', + 'real': 'real', + }, + 'real': { + 'integer': 'real', + 'real': 'real' + }, + }, + '/': { + 'integer': { + 'integer': 'integer', + 'real': 'real', + }, + 'real': { + 'integer': 'real', + 'real': 'real' + }, + }, + '>': { + 'integer': { + 'integer': 'bool', + 'real': 'bool', + }, + 'real': { + 'integer': 'bool', + 'real': 'bool' + }, + }, + '<': { + 'integer': { + 'integer': 'bool', + 'real': 'bool', + }, + 'real': { + 'integer': 'bool', + 'real': 'bool' + }, + }, + '>=': { + 'integer': { + 'integer': 'bool', + 'real': 'bool', + }, + 'real': { + 'integer': 'bool', + 'real': 'bool' + }, + }, + '<=': { + 'integer': { + 'integer': 'bool', + 'real': 'bool', + }, + 'real': { + 'integer': 'bool', + 'real': 'bool' + }, + }, + '==': { + 'integer': { + 'integer': 'bool', + 'real': 'bool', + }, + 'real': { + 'integer': 'bool', + 'real': 'bool' + }, + }, + '/=': { + 'integer': { + 'integer': 'bool', + 'real': 'bool', + }, + 'real': { + 'integer': 'bool', + 'real': 'bool' + }, + }, + '=': { + 'integer': { + 'integer': 'integer', + }, + 'real': { + 'integer': 'real', + 'real': 'real', + }, + 'bool': { + 'bool': 'bool', + } + }, +} + +def resultingType(operator, operand1, operand2): + operatorMap = typeValidationMap[operator] + if operand1 in operatorMap: + operand1Map = operatorMap[operand1] + if operand2 in operand1Map: + return operand1Map[operand2] + else: + raise Exception('Operation not suppoerte') + else: + raise Exception('Operation not supported') \ No newline at end of file diff --git a/final_lang/types.py b/final_lang/types.py new file mode 100644 index 0000000..4fe51df --- /dev/null +++ b/final_lang/types.py @@ -0,0 +1,125 @@ +typeValidationMap = { + '*': { + 'integer': { + 'integer': 'integer', + 'real': 'real', + }, + 'real': { + 'integer': 'real', + 'real': 'real' + }, + }, + '+': { + 'integer': { + 'integer': 'integer', + 'real': 'real', + }, + 'real': { + 'integer': 'real', + 'real': 'real' + }, + }, + '-': { + 'integer': { + 'integer': 'integer', + 'real': 'real', + }, + 'real': { + 'integer': 'real', + 'real': 'real' + }, + }, + '/': { + 'integer': { + 'integer': 'integer', + 'real': 'real', + }, + 'real': { + 'integer': 'real', + 'real': 'real' + }, + }, + '>': { + 'integer': { + 'integer': 'bool', + 'real': 'bool', + }, + 'real': { + 'integer': 'bool', + 'real': 'bool' + }, + }, + '<': { + 'integer': { + 'integer': 'bool', + 'real': 'bool', + }, + 'real': { + 'integer': 'bool', + 'real': 'bool' + }, + }, + '>=': { + 'integer': { + 'integer': 'bool', + 'real': 'bool', + }, + 'real': { + 'integer': 'bool', + 'real': 'bool' + }, + }, + '<=': { + 'integer': { + 'integer': 'bool', + 'real': 'bool', + }, + 'real': { + 'integer': 'bool', + 'real': 'bool' + }, + }, + '==': { + 'integer': { + 'integer': 'bool', + 'real': 'bool', + }, + 'real': { + 'integer': 'bool', + 'real': 'bool' + }, + }, + '/=': { + 'integer': { + 'integer': 'bool', + 'real': 'bool', + }, + 'real': { + 'integer': 'bool', + 'real': 'bool' + }, + }, + '=': { + 'integer': { + 'integer': 'integer', + }, + 'real': { + 'integer': 'real', + 'real': 'real', + }, + 'bool': { + 'bool': 'bool', + } + }, +} + +def resultingType(operator, type1, type2): + operatorMap = typeValidationMap[operator] + if type1 in operatorMap: + type1Map = operatorMap[type1] + if type2 in type1Map: + return type1Map[type2] + else: + raise Exception('Operation not suppoerted') + else: + raise Exception('Operation not supported') \ No newline at end of file