Finished translation for Arithmetic and Logic operations
This commit is contained in:
parent
e42908d67e
commit
2833e9595d
8 changed files with 476 additions and 230 deletions
|
|
@ -3,6 +3,8 @@ import ply.yacc as yacc
|
|||
import sys
|
||||
from typeValidation import resultingType
|
||||
|
||||
kEqualityOperators = ['>', '<', '>=', '<=', '==', '/=',]
|
||||
|
||||
resultQuadruplets = []
|
||||
quadrupletIndex = 1
|
||||
|
||||
|
|
@ -39,8 +41,13 @@ def peek(list):
|
|||
return list[len(list) - 1]
|
||||
|
||||
# Checks whether or not a an operand is a temp variable.
|
||||
def isTemp(operan):
|
||||
return
|
||||
def isTemp(operand):
|
||||
if type(operand) is not str:
|
||||
return False
|
||||
operand = int(operand[1:])
|
||||
if (operand < 50):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
tokens = [
|
||||
|
|
@ -314,20 +321,20 @@ def p_EAParens(p):
|
|||
def p_EL(p):
|
||||
'''
|
||||
EL : AND
|
||||
| EL or AND
|
||||
| EL or action_10 AND action_9
|
||||
'''
|
||||
|
||||
def p_AND(p):
|
||||
'''
|
||||
AND : Equality
|
||||
| AND and Equality
|
||||
| AND and action_12 Equality action_11
|
||||
'''
|
||||
|
||||
def p_Equality(p):
|
||||
'''
|
||||
Equality : EItem EQSymbols EItem
|
||||
Equality : EItem EQSymbols action_13 EItem action_14
|
||||
| openParen EL closedParen
|
||||
| not EL
|
||||
| not EL action_15
|
||||
'''
|
||||
|
||||
def p_EItem(p):
|
||||
|
|
@ -346,6 +353,7 @@ def p_EQSymbols(p):
|
|||
| lessEquals
|
||||
| moreEquals
|
||||
'''
|
||||
p[0] = p[1]
|
||||
|
||||
|
||||
def p_action_1(p):
|
||||
|
|
@ -376,6 +384,7 @@ def p_action_4(p):
|
|||
"action_4 :"
|
||||
if (peek(operatorsStack) == '+' or peek(operatorsStack) == '-'):
|
||||
global quadrupletIndex
|
||||
global avail
|
||||
operator = operatorsStack.pop()
|
||||
operand2 = operandsStack.pop()
|
||||
operand1 = operandsStack.pop()
|
||||
|
|
@ -387,6 +396,10 @@ def p_action_4(p):
|
|||
typesStack.append(resultType)
|
||||
resultQuadruplets.append(str(operator) + ' ' + str(operand1) + ' ' + str(operand2) + ' ' + str(temp) + '\n')
|
||||
quadrupletIndex += 1
|
||||
if (isTemp(operand2)):
|
||||
avail = [operand2] + avail
|
||||
if (isTemp(operand1)):
|
||||
avail = [operand1] + avail
|
||||
|
||||
|
||||
def p_action_5(p):
|
||||
|
|
@ -398,6 +411,7 @@ def p_action_6(p):
|
|||
"action_6 :"
|
||||
if (peek(operatorsStack) == '*' or peek(operatorsStack) == '/'):
|
||||
global quadrupletIndex
|
||||
global avail
|
||||
operator = operatorsStack.pop()
|
||||
operand2 = operandsStack.pop()
|
||||
operand1 = operandsStack.pop()
|
||||
|
|
@ -409,6 +423,10 @@ def p_action_6(p):
|
|||
typesStack.append(resultType)
|
||||
resultQuadruplets.append(str(operator) + ' ' + str(operand1) + ' ' + str(operand2) + ' ' + str(temp) + '\n')
|
||||
quadrupletIndex += 1
|
||||
if (isTemp(operand2)):
|
||||
avail = [operand2] + avail
|
||||
if (isTemp(operand1)):
|
||||
avail = [operand1] + avail
|
||||
|
||||
|
||||
|
||||
|
|
@ -424,6 +442,8 @@ def p_action_7(p):
|
|||
|
||||
def p_action_8(p):
|
||||
"action_8 :"
|
||||
global quadrupletIndex
|
||||
global avail
|
||||
operand2 = operandsStack.pop()
|
||||
operand1 = operandsStack.pop()
|
||||
type2 = typesStack.pop()
|
||||
|
|
@ -431,6 +451,100 @@ def p_action_8(p):
|
|||
# Result type only gets called to make sure the types are compatible.
|
||||
resultingType('=', type1, type2)
|
||||
resultQuadruplets.append('= ' + str(operand2) + ' ' + str(operand1) + '\n')
|
||||
quadrupletIndex += 1
|
||||
# Return the operand to the availbale if it is a temporal.
|
||||
if (isTemp(operand2)):
|
||||
avail = [operand2] + avail
|
||||
|
||||
def p_action_9(p):
|
||||
"action_9 :"
|
||||
if (peek(operatorsStack) == '.or.'):
|
||||
global quadrupletIndex
|
||||
global avail
|
||||
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
|
||||
if (isTemp(operand2)):
|
||||
avail = [operand2] + avail
|
||||
if (isTemp(operand1)):
|
||||
avail = [operand1] + avail
|
||||
|
||||
|
||||
|
||||
def p_action_10(p):
|
||||
"action_10 :"
|
||||
operatorsStack.append(p[-1])
|
||||
|
||||
|
||||
def p_action_11(p):
|
||||
"action_11 :"
|
||||
if (peek(operatorsStack) == '.and.'):
|
||||
global quadrupletIndex
|
||||
global avail
|
||||
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
|
||||
if (isTemp(operand2)):
|
||||
avail = [operand2] + avail
|
||||
if (isTemp(operand1)):
|
||||
avail = [operand1] + avail
|
||||
|
||||
|
||||
def p_action_12(p):
|
||||
"action_12 :"
|
||||
operatorsStack.append(p[-1])
|
||||
|
||||
|
||||
def p_action_13(p):
|
||||
"action_13 :"
|
||||
operatorsStack.append(p[-1])
|
||||
|
||||
|
||||
def p_action_14(p):
|
||||
"action_14 :"
|
||||
if (peek(operatorsStack) in kEqualityOperators):
|
||||
global quadrupletIndex
|
||||
global avail
|
||||
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
|
||||
if (isTemp(operand2)):
|
||||
avail = [operand2] + avail
|
||||
if (isTemp(operand1)):
|
||||
avail = [operand1] + avail
|
||||
|
||||
|
||||
def p_action_15(p):
|
||||
"action_15 :"
|
||||
if (peek(typesStack) is not 'bool'):
|
||||
raise Exception("Cannot use .not. with non boolean")
|
||||
global quadrupletIndex
|
||||
operand1 = peek(operandsStack)
|
||||
resultQuadruplets.append('.not. ' + str(operand1) + ' ' + str(operand1) + '\n')
|
||||
|
||||
|
||||
def p_error(p):
|
||||
|
|
|
|||
|
|
@ -54,12 +54,12 @@ Rule 48 MDSymbols -> div
|
|||
Rule 49 EAParens -> EItem
|
||||
Rule 50 EAParens -> openParen EA closedParen
|
||||
Rule 51 EL -> AND
|
||||
Rule 52 EL -> EL or AND
|
||||
Rule 52 EL -> EL or action_10 AND action_9
|
||||
Rule 53 AND -> Equality
|
||||
Rule 54 AND -> AND and Equality
|
||||
Rule 55 Equality -> EItem EQSymbols EItem
|
||||
Rule 54 AND -> AND and action_12 Equality action_11
|
||||
Rule 55 Equality -> EItem EQSymbols action_13 EItem action_14
|
||||
Rule 56 Equality -> openParen EL closedParen
|
||||
Rule 57 Equality -> not EL
|
||||
Rule 57 Equality -> not EL action_15
|
||||
Rule 58 EItem -> Dimensional action_1
|
||||
Rule 59 EItem -> int action_2
|
||||
Rule 60 EItem -> rea action_2_rea
|
||||
|
|
@ -78,6 +78,13 @@ Rule 72 action_5 -> <empty>
|
|||
Rule 73 action_6 -> <empty>
|
||||
Rule 74 action_7 -> <empty>
|
||||
Rule 75 action_8 -> <empty>
|
||||
Rule 76 action_9 -> <empty>
|
||||
Rule 77 action_10 -> <empty>
|
||||
Rule 78 action_11 -> <empty>
|
||||
Rule 79 action_12 -> <empty>
|
||||
Rule 80 action_13 -> <empty>
|
||||
Rule 81 action_14 -> <empty>
|
||||
Rule 82 action_15 -> <empty>
|
||||
|
||||
Terminals, with rules where they appear
|
||||
|
||||
|
|
@ -151,6 +158,12 @@ SumOrSub : 42
|
|||
Tipo : 2
|
||||
V : 1 2
|
||||
action_1 : 58
|
||||
action_10 : 52
|
||||
action_11 : 54
|
||||
action_12 : 54
|
||||
action_13 : 55
|
||||
action_14 : 55
|
||||
action_15 : 57
|
||||
action_2 : 59
|
||||
action_2_rea : 60
|
||||
action_3 : 42
|
||||
|
|
@ -159,6 +172,7 @@ action_5 : 46
|
|||
action_6 : 46
|
||||
action_7 : 15
|
||||
action_8 : 15
|
||||
action_9 : 52
|
||||
programa : 0
|
||||
|
||||
Parsing method: LALR
|
||||
|
|
@ -520,9 +534,9 @@ state 27
|
|||
notEquals reduce using rule 24 (Dimensional -> id DimensionsOrEmpty .)
|
||||
lessEquals reduce using rule 24 (Dimensional -> id DimensionsOrEmpty .)
|
||||
moreEquals reduce using rule 24 (Dimensional -> id DimensionsOrEmpty .)
|
||||
then reduce using rule 24 (Dimensional -> id DimensionsOrEmpty .)
|
||||
and reduce using rule 24 (Dimensional -> id DimensionsOrEmpty .)
|
||||
or reduce using rule 24 (Dimensional -> id DimensionsOrEmpty .)
|
||||
then reduce using rule 24 (Dimensional -> id DimensionsOrEmpty .)
|
||||
|
||||
|
||||
state 28
|
||||
|
|
@ -628,9 +642,9 @@ state 33
|
|||
notEquals reduce using rule 26 (DimensionsOrEmpty -> .)
|
||||
lessEquals reduce using rule 26 (DimensionsOrEmpty -> .)
|
||||
moreEquals reduce using rule 26 (DimensionsOrEmpty -> .)
|
||||
then reduce using rule 26 (DimensionsOrEmpty -> .)
|
||||
and reduce using rule 26 (DimensionsOrEmpty -> .)
|
||||
or reduce using rule 26 (DimensionsOrEmpty -> .)
|
||||
then reduce using rule 26 (DimensionsOrEmpty -> .)
|
||||
|
||||
DimensionsOrEmpty shift and go to state 27
|
||||
|
||||
|
|
@ -720,12 +734,12 @@ state 39
|
|||
|
||||
(35) Relif -> openParen . EL closedParen then B
|
||||
(51) EL -> . AND
|
||||
(52) EL -> . EL or AND
|
||||
(52) EL -> . EL or action_10 AND action_9
|
||||
(53) AND -> . Equality
|
||||
(54) AND -> . AND and Equality
|
||||
(55) Equality -> . EItem EQSymbols EItem
|
||||
(54) AND -> . AND and action_12 Equality action_11
|
||||
(55) Equality -> . EItem EQSymbols action_13 EItem action_14
|
||||
(56) Equality -> . openParen EL closedParen
|
||||
(57) Equality -> . not EL
|
||||
(57) Equality -> . not EL action_15
|
||||
(58) EItem -> . Dimensional action_1
|
||||
(59) EItem -> . int action_2
|
||||
(60) EItem -> . rea action_2_rea
|
||||
|
|
@ -989,9 +1003,9 @@ state 52
|
|||
exit reduce using rule 67 (action_1 -> .)
|
||||
elif reduce using rule 67 (action_1 -> .)
|
||||
else reduce using rule 67 (action_1 -> .)
|
||||
then 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 -> .)
|
||||
|
||||
action_1 shift and go to state 82
|
||||
|
||||
|
|
@ -1022,9 +1036,9 @@ state 53
|
|||
exit reduce using rule 68 (action_2 -> .)
|
||||
elif reduce using rule 68 (action_2 -> .)
|
||||
else reduce using rule 68 (action_2 -> .)
|
||||
then 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 -> .)
|
||||
|
||||
action_2 shift and go to state 83
|
||||
|
||||
|
|
@ -1055,9 +1069,9 @@ state 54
|
|||
exit reduce using rule 69 (action_2_rea -> .)
|
||||
elif reduce using rule 69 (action_2_rea -> .)
|
||||
else reduce using rule 69 (action_2_rea -> .)
|
||||
then 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_rea shift and go to state 84
|
||||
|
||||
|
|
@ -1143,12 +1157,12 @@ state 61
|
|||
|
||||
(56) Equality -> openParen . EL closedParen
|
||||
(51) EL -> . AND
|
||||
(52) EL -> . EL or AND
|
||||
(52) EL -> . EL or action_10 AND action_9
|
||||
(53) AND -> . Equality
|
||||
(54) AND -> . AND and Equality
|
||||
(55) Equality -> . EItem EQSymbols EItem
|
||||
(54) AND -> . AND and action_12 Equality action_11
|
||||
(55) Equality -> . EItem EQSymbols action_13 EItem action_14
|
||||
(56) Equality -> . openParen EL closedParen
|
||||
(57) Equality -> . not EL
|
||||
(57) Equality -> . not EL action_15
|
||||
(58) EItem -> . Dimensional action_1
|
||||
(59) EItem -> . int action_2
|
||||
(60) EItem -> . rea action_2_rea
|
||||
|
|
@ -1169,7 +1183,7 @@ state 61
|
|||
state 62
|
||||
|
||||
(35) Relif -> openParen EL . closedParen then B
|
||||
(52) EL -> EL . or AND
|
||||
(52) EL -> EL . or action_10 AND action_9
|
||||
|
||||
closedParen shift and go to state 92
|
||||
or shift and go to state 93
|
||||
|
|
@ -1178,7 +1192,7 @@ state 62
|
|||
state 63
|
||||
|
||||
(51) EL -> AND .
|
||||
(54) AND -> AND . and Equality
|
||||
(54) AND -> AND . and action_12 Equality action_11
|
||||
|
||||
! shift/reduce conflict for and resolved as shift
|
||||
closedParen reduce using rule 51 (EL -> AND .)
|
||||
|
|
@ -1199,7 +1213,7 @@ state 64
|
|||
|
||||
state 65
|
||||
|
||||
(55) Equality -> EItem . EQSymbols EItem
|
||||
(55) Equality -> EItem . EQSymbols action_13 EItem action_14
|
||||
(61) EQSymbols -> . less
|
||||
(62) EQSymbols -> . more
|
||||
(63) EQSymbols -> . doubleEquals
|
||||
|
|
@ -1218,14 +1232,14 @@ state 65
|
|||
|
||||
state 66
|
||||
|
||||
(57) Equality -> not . EL
|
||||
(57) Equality -> not . EL action_15
|
||||
(51) EL -> . AND
|
||||
(52) EL -> . EL or AND
|
||||
(52) EL -> . EL or action_10 AND action_9
|
||||
(53) AND -> . Equality
|
||||
(54) AND -> . AND and Equality
|
||||
(55) Equality -> . EItem EQSymbols EItem
|
||||
(54) AND -> . AND and action_12 Equality action_11
|
||||
(55) Equality -> . EItem EQSymbols action_13 EItem action_14
|
||||
(56) Equality -> . openParen EL closedParen
|
||||
(57) Equality -> . not EL
|
||||
(57) Equality -> . not EL action_15
|
||||
(58) EItem -> . Dimensional action_1
|
||||
(59) EItem -> . int action_2
|
||||
(60) EItem -> . rea action_2_rea
|
||||
|
|
@ -1460,9 +1474,9 @@ 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 .)
|
||||
then 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 .)
|
||||
|
||||
|
||||
state 83
|
||||
|
|
@ -1491,9 +1505,9 @@ 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 .)
|
||||
then 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 .)
|
||||
|
||||
|
||||
state 84
|
||||
|
|
@ -1522,9 +1536,9 @@ state 84
|
|||
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 .)
|
||||
then 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
|
||||
|
|
@ -1596,12 +1610,12 @@ state 89
|
|||
|
||||
(36) Relif -> Relif elif openParen . EL closedParen then B
|
||||
(51) EL -> . AND
|
||||
(52) EL -> . EL or AND
|
||||
(52) EL -> . EL or action_10 AND action_9
|
||||
(53) AND -> . Equality
|
||||
(54) AND -> . AND and Equality
|
||||
(55) Equality -> . EItem EQSymbols EItem
|
||||
(54) AND -> . AND and action_12 Equality action_11
|
||||
(55) Equality -> . EItem EQSymbols action_13 EItem action_14
|
||||
(56) Equality -> . openParen EL closedParen
|
||||
(57) Equality -> . not EL
|
||||
(57) Equality -> . not EL action_15
|
||||
(58) EItem -> . Dimensional action_1
|
||||
(59) EItem -> . int action_2
|
||||
(60) EItem -> . rea action_2_rea
|
||||
|
|
@ -1649,7 +1663,7 @@ state 90
|
|||
state 91
|
||||
|
||||
(56) Equality -> openParen EL . closedParen
|
||||
(52) EL -> EL . or AND
|
||||
(52) EL -> EL . or action_10 AND action_9
|
||||
|
||||
closedParen shift and go to state 117
|
||||
or shift and go to state 93
|
||||
|
|
@ -1664,63 +1678,40 @@ state 92
|
|||
|
||||
state 93
|
||||
|
||||
(52) EL -> EL or . AND
|
||||
(53) AND -> . Equality
|
||||
(54) AND -> . AND and Equality
|
||||
(55) Equality -> . EItem EQSymbols EItem
|
||||
(56) Equality -> . openParen EL closedParen
|
||||
(57) Equality -> . not EL
|
||||
(58) EItem -> . Dimensional action_1
|
||||
(59) EItem -> . int action_2
|
||||
(60) EItem -> . rea action_2_rea
|
||||
(24) Dimensional -> . id DimensionsOrEmpty
|
||||
(52) EL -> EL or . action_10 AND action_9
|
||||
(77) action_10 -> .
|
||||
|
||||
openParen shift and go to state 61
|
||||
not shift and go to state 66
|
||||
int shift and go to state 53
|
||||
rea shift and go to state 54
|
||||
id shift and go to state 33
|
||||
openParen reduce using rule 77 (action_10 -> .)
|
||||
not reduce using rule 77 (action_10 -> .)
|
||||
int reduce using rule 77 (action_10 -> .)
|
||||
rea reduce using rule 77 (action_10 -> .)
|
||||
id reduce using rule 77 (action_10 -> .)
|
||||
|
||||
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
|
||||
action_10 shift and go to state 119
|
||||
|
||||
state 94
|
||||
|
||||
(54) AND -> AND and . Equality
|
||||
(55) Equality -> . EItem EQSymbols EItem
|
||||
(56) Equality -> . openParen EL closedParen
|
||||
(57) Equality -> . not EL
|
||||
(58) EItem -> . Dimensional action_1
|
||||
(59) EItem -> . int action_2
|
||||
(60) EItem -> . rea action_2_rea
|
||||
(24) Dimensional -> . id DimensionsOrEmpty
|
||||
(54) AND -> AND and . action_12 Equality action_11
|
||||
(79) action_12 -> .
|
||||
|
||||
openParen shift and go to state 61
|
||||
not shift and go to state 66
|
||||
int shift and go to state 53
|
||||
rea shift and go to state 54
|
||||
id shift and go to state 33
|
||||
openParen reduce using rule 79 (action_12 -> .)
|
||||
not reduce using rule 79 (action_12 -> .)
|
||||
int reduce using rule 79 (action_12 -> .)
|
||||
rea reduce using rule 79 (action_12 -> .)
|
||||
id reduce using rule 79 (action_12 -> .)
|
||||
|
||||
Equality shift and go to state 120
|
||||
EItem shift and go to state 65
|
||||
Dimensional shift and go to state 52
|
||||
action_12 shift and go to state 120
|
||||
|
||||
state 95
|
||||
|
||||
(55) Equality -> EItem EQSymbols . EItem
|
||||
(58) EItem -> . Dimensional action_1
|
||||
(59) EItem -> . int action_2
|
||||
(60) EItem -> . rea action_2_rea
|
||||
(24) Dimensional -> . id DimensionsOrEmpty
|
||||
(55) Equality -> EItem EQSymbols . action_13 EItem action_14
|
||||
(80) action_13 -> .
|
||||
|
||||
int shift and go to state 53
|
||||
rea shift and go to state 54
|
||||
id shift and go to state 33
|
||||
int reduce using rule 80 (action_13 -> .)
|
||||
rea reduce using rule 80 (action_13 -> .)
|
||||
id reduce using rule 80 (action_13 -> .)
|
||||
|
||||
EItem shift and go to state 121
|
||||
Dimensional shift and go to state 52
|
||||
action_13 shift and go to state 121
|
||||
|
||||
state 96
|
||||
|
||||
|
|
@ -1778,16 +1769,18 @@ state 101
|
|||
|
||||
state 102
|
||||
|
||||
(57) Equality -> not EL .
|
||||
(52) EL -> EL . or AND
|
||||
(57) Equality -> not EL . action_15
|
||||
(52) EL -> EL . or action_10 AND action_9
|
||||
(82) action_15 -> .
|
||||
|
||||
! 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 93
|
||||
and reduce using rule 82 (action_15 -> .)
|
||||
closedParen reduce using rule 82 (action_15 -> .)
|
||||
|
||||
! or [ reduce using rule 57 (Equality -> not EL .) ]
|
||||
! or [ reduce using rule 82 (action_15 -> .) ]
|
||||
|
||||
action_15 shift and go to state 122
|
||||
|
||||
state 103
|
||||
|
||||
|
|
@ -1796,7 +1789,7 @@ state 103
|
|||
(43) SumOrSub -> . plus
|
||||
(44) SumOrSub -> . minus
|
||||
|
||||
coma shift and go to state 122
|
||||
coma shift and go to state 123
|
||||
plus shift and go to state 77
|
||||
minus shift and go to state 78
|
||||
|
||||
|
|
@ -1806,7 +1799,7 @@ state 104
|
|||
|
||||
(21) S -> do then B end . do
|
||||
|
||||
do shift and go to state 123
|
||||
do shift and go to state 124
|
||||
|
||||
|
||||
state 105
|
||||
|
|
@ -1862,7 +1855,7 @@ state 108
|
|||
|
||||
(9) Dim -> openBra int closedBra openBra int . closedBra
|
||||
|
||||
closedBra shift and go to state 124
|
||||
closedBra shift and go to state 125
|
||||
|
||||
|
||||
state 109
|
||||
|
|
@ -1915,9 +1908,9 @@ state 110
|
|||
notEquals reduce using rule 25 (DimensionsOrEmpty -> openParen EA ComaEAOrEmpty closedParen .)
|
||||
lessEquals reduce using rule 25 (DimensionsOrEmpty -> openParen EA ComaEAOrEmpty closedParen .)
|
||||
moreEquals reduce using rule 25 (DimensionsOrEmpty -> openParen EA ComaEAOrEmpty closedParen .)
|
||||
then reduce using rule 25 (DimensionsOrEmpty -> openParen EA ComaEAOrEmpty closedParen .)
|
||||
and reduce using rule 25 (DimensionsOrEmpty -> openParen EA ComaEAOrEmpty closedParen .)
|
||||
or reduce using rule 25 (DimensionsOrEmpty -> openParen EA ComaEAOrEmpty closedParen .)
|
||||
then reduce using rule 25 (DimensionsOrEmpty -> openParen EA ComaEAOrEmpty closedParen .)
|
||||
|
||||
|
||||
state 111
|
||||
|
|
@ -1937,7 +1930,7 @@ state 111
|
|||
rea shift and go to state 54
|
||||
id shift and go to state 33
|
||||
|
||||
MultDiv shift and go to state 125
|
||||
MultDiv shift and go to state 126
|
||||
EAParens shift and go to state 50
|
||||
EItem shift and go to state 51
|
||||
Dimensional shift and go to state 52
|
||||
|
|
@ -1970,7 +1963,7 @@ state 113
|
|||
rea shift and go to state 54
|
||||
id shift and go to state 33
|
||||
|
||||
EAParens shift and go to state 126
|
||||
EAParens shift and go to state 127
|
||||
EItem shift and go to state 51
|
||||
Dimensional shift and go to state 52
|
||||
|
||||
|
|
@ -2009,9 +2002,9 @@ state 115
|
|||
state 116
|
||||
|
||||
(36) Relif -> Relif elif openParen EL . closedParen then B
|
||||
(52) EL -> EL . or AND
|
||||
(52) EL -> EL . or action_10 AND action_9
|
||||
|
||||
closedParen shift and go to state 127
|
||||
closedParen shift and go to state 128
|
||||
or shift and go to state 93
|
||||
|
||||
|
||||
|
|
@ -2041,41 +2034,79 @@ state 118
|
|||
else reduce using rule 14 (B -> .)
|
||||
end reduce using rule 14 (B -> .)
|
||||
|
||||
B shift and go to state 128
|
||||
B shift and go to state 129
|
||||
|
||||
state 119
|
||||
|
||||
(52) EL -> EL or AND .
|
||||
(54) AND -> AND . and Equality
|
||||
(52) EL -> EL or action_10 . AND action_9
|
||||
(53) AND -> . Equality
|
||||
(54) AND -> . AND and action_12 Equality action_11
|
||||
(55) Equality -> . EItem EQSymbols action_13 EItem action_14
|
||||
(56) Equality -> . openParen EL closedParen
|
||||
(57) Equality -> . not EL action_15
|
||||
(58) EItem -> . Dimensional action_1
|
||||
(59) EItem -> . int action_2
|
||||
(60) EItem -> . rea action_2_rea
|
||||
(24) Dimensional -> . id DimensionsOrEmpty
|
||||
|
||||
! 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 94
|
||||
|
||||
! and [ reduce using rule 52 (EL -> EL or AND .) ]
|
||||
openParen shift and go to state 61
|
||||
not shift and go to state 66
|
||||
int shift and go to state 53
|
||||
rea shift and go to state 54
|
||||
id shift and go to state 33
|
||||
|
||||
AND shift and go to state 130
|
||||
Equality shift and go to state 64
|
||||
EItem shift and go to state 65
|
||||
Dimensional shift and go to state 52
|
||||
|
||||
state 120
|
||||
|
||||
(54) AND -> AND and Equality .
|
||||
(54) AND -> AND and action_12 . Equality action_11
|
||||
(55) Equality -> . EItem EQSymbols action_13 EItem action_14
|
||||
(56) Equality -> . openParen EL closedParen
|
||||
(57) Equality -> . not EL action_15
|
||||
(58) EItem -> . Dimensional action_1
|
||||
(59) EItem -> . int action_2
|
||||
(60) EItem -> . rea action_2_rea
|
||||
(24) Dimensional -> . id DimensionsOrEmpty
|
||||
|
||||
and reduce using rule 54 (AND -> AND and Equality .)
|
||||
closedParen reduce using rule 54 (AND -> AND and Equality .)
|
||||
or reduce using rule 54 (AND -> AND and Equality .)
|
||||
openParen shift and go to state 61
|
||||
not shift and go to state 66
|
||||
int shift and go to state 53
|
||||
rea shift and go to state 54
|
||||
id shift and go to state 33
|
||||
|
||||
Equality shift and go to state 131
|
||||
EItem shift and go to state 65
|
||||
Dimensional shift and go to state 52
|
||||
|
||||
state 121
|
||||
|
||||
(55) Equality -> EItem EQSymbols EItem .
|
||||
(55) Equality -> EItem EQSymbols action_13 . EItem action_14
|
||||
(58) EItem -> . Dimensional action_1
|
||||
(59) EItem -> . int action_2
|
||||
(60) EItem -> . rea action_2_rea
|
||||
(24) Dimensional -> . id DimensionsOrEmpty
|
||||
|
||||
and reduce using rule 55 (Equality -> EItem EQSymbols EItem .)
|
||||
closedParen reduce using rule 55 (Equality -> EItem EQSymbols EItem .)
|
||||
or reduce using rule 55 (Equality -> EItem EQSymbols EItem .)
|
||||
int shift and go to state 53
|
||||
rea shift and go to state 54
|
||||
id shift and go to state 33
|
||||
|
||||
EItem shift and go to state 132
|
||||
Dimensional shift and go to state 52
|
||||
|
||||
state 122
|
||||
|
||||
(57) Equality -> not EL action_15 .
|
||||
|
||||
and reduce using rule 57 (Equality -> not EL action_15 .)
|
||||
closedParen reduce using rule 57 (Equality -> not EL action_15 .)
|
||||
or reduce using rule 57 (Equality -> not EL action_15 .)
|
||||
|
||||
|
||||
state 123
|
||||
|
||||
(20) S -> do id equals EA coma . EA IntOrEmpty then B end do
|
||||
(41) EA -> . MultDiv
|
||||
(42) EA -> . EA SumOrSub action_3 MultDiv action_4
|
||||
|
|
@ -2093,13 +2124,13 @@ state 122
|
|||
rea shift and go to state 54
|
||||
id shift and go to state 33
|
||||
|
||||
EA shift and go to state 129
|
||||
EA shift and go to state 133
|
||||
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 123
|
||||
state 124
|
||||
|
||||
(21) S -> do then B end do .
|
||||
|
||||
|
|
@ -2115,14 +2146,14 @@ state 123
|
|||
else reduce using rule 21 (S -> do then B end do .)
|
||||
|
||||
|
||||
state 124
|
||||
state 125
|
||||
|
||||
(9) Dim -> openBra int closedBra openBra int closedBra .
|
||||
|
||||
doubleColon reduce using rule 9 (Dim -> openBra int closedBra openBra int closedBra .)
|
||||
|
||||
|
||||
state 125
|
||||
state 126
|
||||
|
||||
(42) EA -> EA SumOrSub action_3 MultDiv . action_4
|
||||
(46) MultDiv -> MultDiv . MDSymbols action_5 EAParens action_6
|
||||
|
|
@ -2148,10 +2179,10 @@ state 125
|
|||
mul shift and go to state 80
|
||||
div shift and go to state 81
|
||||
|
||||
action_4 shift and go to state 130
|
||||
action_4 shift and go to state 134
|
||||
MDSymbols shift and go to state 79
|
||||
|
||||
state 126
|
||||
state 127
|
||||
|
||||
(46) MultDiv -> MultDiv MDSymbols action_5 EAParens . action_6
|
||||
(73) action_6 -> .
|
||||
|
|
@ -2174,16 +2205,16 @@ state 126
|
|||
else reduce using rule 73 (action_6 -> .)
|
||||
then reduce using rule 73 (action_6 -> .)
|
||||
|
||||
action_6 shift and go to state 131
|
||||
action_6 shift and go to state 135
|
||||
|
||||
state 127
|
||||
state 128
|
||||
|
||||
(36) Relif -> Relif elif openParen EL closedParen . then B
|
||||
|
||||
then shift and go to state 132
|
||||
then shift and go to state 136
|
||||
|
||||
|
||||
state 128
|
||||
state 129
|
||||
|
||||
(35) Relif -> openParen EL closedParen then B .
|
||||
(13) B -> B . S
|
||||
|
|
@ -2212,7 +2243,44 @@ state 128
|
|||
S shift and go to state 15
|
||||
Dimensional shift and go to state 16
|
||||
|
||||
state 129
|
||||
state 130
|
||||
|
||||
(52) EL -> EL or action_10 AND . action_9
|
||||
(54) AND -> AND . and action_12 Equality action_11
|
||||
(76) action_9 -> .
|
||||
|
||||
! shift/reduce conflict for and resolved as shift
|
||||
and shift and go to state 94
|
||||
closedParen reduce using rule 76 (action_9 -> .)
|
||||
or reduce using rule 76 (action_9 -> .)
|
||||
|
||||
! and [ reduce using rule 76 (action_9 -> .) ]
|
||||
|
||||
action_9 shift and go to state 137
|
||||
|
||||
state 131
|
||||
|
||||
(54) AND -> AND and action_12 Equality . action_11
|
||||
(78) action_11 -> .
|
||||
|
||||
and reduce using rule 78 (action_11 -> .)
|
||||
closedParen reduce using rule 78 (action_11 -> .)
|
||||
or reduce using rule 78 (action_11 -> .)
|
||||
|
||||
action_11 shift and go to state 138
|
||||
|
||||
state 132
|
||||
|
||||
(55) Equality -> EItem EQSymbols action_13 EItem . action_14
|
||||
(81) action_14 -> .
|
||||
|
||||
and reduce using rule 81 (action_14 -> .)
|
||||
closedParen reduce using rule 81 (action_14 -> .)
|
||||
or reduce using rule 81 (action_14 -> .)
|
||||
|
||||
action_14 shift and go to state 139
|
||||
|
||||
state 133
|
||||
|
||||
(20) S -> do id equals EA coma EA . IntOrEmpty then B end do
|
||||
(42) EA -> EA . SumOrSub action_3 MultDiv action_4
|
||||
|
|
@ -2221,15 +2289,15 @@ state 129
|
|||
(43) SumOrSub -> . plus
|
||||
(44) SumOrSub -> . minus
|
||||
|
||||
coma shift and go to state 133
|
||||
coma shift and go to state 140
|
||||
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 134
|
||||
IntOrEmpty shift and go to state 141
|
||||
SumOrSub shift and go to state 75
|
||||
|
||||
state 130
|
||||
state 134
|
||||
|
||||
(42) EA -> EA SumOrSub action_3 MultDiv action_4 .
|
||||
|
||||
|
|
@ -2250,7 +2318,7 @@ state 130
|
|||
then reduce using rule 42 (EA -> EA SumOrSub action_3 MultDiv action_4 .)
|
||||
|
||||
|
||||
state 131
|
||||
state 135
|
||||
|
||||
(46) MultDiv -> MultDiv MDSymbols action_5 EAParens action_6 .
|
||||
|
||||
|
|
@ -2273,7 +2341,7 @@ state 131
|
|||
then reduce using rule 46 (MultDiv -> MultDiv MDSymbols action_5 EAParens action_6 .)
|
||||
|
||||
|
||||
state 132
|
||||
state 136
|
||||
|
||||
(36) Relif -> Relif elif openParen EL closedParen then . B
|
||||
(13) B -> . B S
|
||||
|
|
@ -2290,23 +2358,50 @@ state 132
|
|||
else reduce using rule 14 (B -> .)
|
||||
end reduce using rule 14 (B -> .)
|
||||
|
||||
B shift and go to state 135
|
||||
B shift and go to state 142
|
||||
|
||||
state 133
|
||||
state 137
|
||||
|
||||
(52) EL -> EL or action_10 AND action_9 .
|
||||
|
||||
closedParen reduce using rule 52 (EL -> EL or action_10 AND action_9 .)
|
||||
or reduce using rule 52 (EL -> EL or action_10 AND action_9 .)
|
||||
and reduce using rule 52 (EL -> EL or action_10 AND action_9 .)
|
||||
|
||||
|
||||
state 138
|
||||
|
||||
(54) AND -> AND and action_12 Equality action_11 .
|
||||
|
||||
and reduce using rule 54 (AND -> AND and action_12 Equality action_11 .)
|
||||
closedParen reduce using rule 54 (AND -> AND and action_12 Equality action_11 .)
|
||||
or reduce using rule 54 (AND -> AND and action_12 Equality action_11 .)
|
||||
|
||||
|
||||
state 139
|
||||
|
||||
(55) Equality -> EItem EQSymbols action_13 EItem action_14 .
|
||||
|
||||
and reduce using rule 55 (Equality -> EItem EQSymbols action_13 EItem action_14 .)
|
||||
closedParen reduce using rule 55 (Equality -> EItem EQSymbols action_13 EItem action_14 .)
|
||||
or reduce using rule 55 (Equality -> EItem EQSymbols action_13 EItem action_14 .)
|
||||
|
||||
|
||||
state 140
|
||||
|
||||
(39) IntOrEmpty -> coma . int
|
||||
|
||||
int shift and go to state 136
|
||||
int shift and go to state 143
|
||||
|
||||
|
||||
state 134
|
||||
state 141
|
||||
|
||||
(20) S -> do id equals EA coma EA IntOrEmpty . then B end do
|
||||
|
||||
then shift and go to state 137
|
||||
then shift and go to state 144
|
||||
|
||||
|
||||
state 135
|
||||
state 142
|
||||
|
||||
(36) Relif -> Relif elif openParen EL closedParen then B .
|
||||
(13) B -> B . S
|
||||
|
|
@ -2335,14 +2430,14 @@ state 135
|
|||
S shift and go to state 15
|
||||
Dimensional shift and go to state 16
|
||||
|
||||
state 136
|
||||
state 143
|
||||
|
||||
(39) IntOrEmpty -> coma int .
|
||||
|
||||
then reduce using rule 39 (IntOrEmpty -> coma int .)
|
||||
|
||||
|
||||
state 137
|
||||
state 144
|
||||
|
||||
(20) S -> do id equals EA coma EA IntOrEmpty then . B end do
|
||||
(13) B -> . B S
|
||||
|
|
@ -2357,9 +2452,9 @@ state 137
|
|||
swap reduce using rule 14 (B -> .)
|
||||
exit reduce using rule 14 (B -> .)
|
||||
|
||||
B shift and go to state 138
|
||||
B shift and go to state 145
|
||||
|
||||
state 138
|
||||
state 145
|
||||
|
||||
(20) S -> do id equals EA coma EA IntOrEmpty then B . end do
|
||||
(13) B -> B . S
|
||||
|
|
@ -2374,7 +2469,7 @@ state 138
|
|||
(23) S -> . exit
|
||||
(24) Dimensional -> . id DimensionsOrEmpty
|
||||
|
||||
end shift and go to state 139
|
||||
end shift and go to state 146
|
||||
id shift and go to state 13
|
||||
read shift and go to state 17
|
||||
print shift and go to state 18
|
||||
|
|
@ -2386,14 +2481,14 @@ state 138
|
|||
S shift and go to state 15
|
||||
Dimensional shift and go to state 16
|
||||
|
||||
state 139
|
||||
state 146
|
||||
|
||||
(20) S -> do id equals EA coma EA IntOrEmpty then B end . do
|
||||
|
||||
do shift and go to state 140
|
||||
do shift and go to state 147
|
||||
|
||||
|
||||
state 140
|
||||
state 147
|
||||
|
||||
(20) S -> do id equals EA coma EA IntOrEmpty then B end do .
|
||||
|
||||
|
|
@ -2413,4 +2508,4 @@ WARNING: Conflicts:
|
|||
WARNING:
|
||||
WARNING: shift/reduce conflict for and in state 63 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
|
||||
WARNING: shift/reduce conflict for and in state 130 resolved as shift
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -4,7 +4,7 @@ integer :: m1Rows, m1Columns, m2Rows, m2Columns, temp, temp2
|
|||
subroutine sumMatrices
|
||||
do temp = 1, m1Rows then
|
||||
do temp2 = 1, m1Columns then
|
||||
resultMatrix(temp,temp2) = matrix(temp,temp2) + matrix(temp,temp2)
|
||||
resultMatrix(temp,temp2) = matrix1(temp,temp2) + matrix2(temp,temp2)
|
||||
resultMatrix(1,1) = 2
|
||||
end do
|
||||
end do
|
||||
|
|
|
|||
4
final_lang/test.fort.out
Normal file
4
final_lang/test.fort.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
+ $58 $51 $0
|
||||
= $0 $57
|
||||
= 2 $52
|
||||
== $53 $55 $0
|
||||
|
|
@ -3,4 +3,7 @@ integer :: a, b
|
|||
real :: c
|
||||
a = 2 + 4 * (2 + 1) / 3 * b
|
||||
b = a
|
||||
if (a == b .and. c > b) then
|
||||
b = b + 1
|
||||
end if
|
||||
end program
|
||||
|
|
@ -1,7 +1,12 @@
|
|||
+ 2 1 $0
|
||||
* 4 $0 $1
|
||||
/ $1 3 $2
|
||||
* $2 $51 $3
|
||||
+ 2 $3 $4
|
||||
= $4 $50
|
||||
/ $1 3 $0
|
||||
* $0 $51 $1
|
||||
+ 2 $1 $0
|
||||
= $0 $50
|
||||
= $50 $51
|
||||
== $50 $51 $0
|
||||
> $52 $51 $1
|
||||
.and. $0 $1 $2
|
||||
+ $51 1 $0
|
||||
= $0 $51
|
||||
|
|
|
|||
|
|
@ -111,6 +111,16 @@ typeValidationMap = {
|
|||
'bool': 'bool',
|
||||
}
|
||||
},
|
||||
'.and.': {
|
||||
'bool': {
|
||||
'bool': 'bool',
|
||||
}
|
||||
},
|
||||
'.or.': {
|
||||
'bool': {
|
||||
'bool': 'bool',
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
def resultingType(operator, type1, type2):
|
||||
|
|
@ -120,6 +130,14 @@ def resultingType(operator, type1, type2):
|
|||
if type2 in type1Map:
|
||||
return type1Map[type2]
|
||||
else:
|
||||
raise Exception('Operation not suppoerted')
|
||||
raise Exception(f'''
|
||||
Operation not suppoerted:
|
||||
|
||||
operator {operator} can't be used with types: {type1} and {type2}
|
||||
''')
|
||||
else:
|
||||
raise Exception('Operation not supported')
|
||||
raise Exception(f'''
|
||||
Operation not supported:
|
||||
|
||||
operator {operator} can't be used with types: {type1} and {type2}
|
||||
''')
|
||||
Loading…
Add table
Add a link
Reference in a new issue