Created a unique pointer for every multi dimensional variable, added support for print statements
This commit is contained in:
parent
3bb50c40e1
commit
240f1c1255
5 changed files with 706 additions and 594 deletions
|
|
@ -22,11 +22,9 @@ typesStack = []
|
||||||
jumpsStack = []
|
jumpsStack = []
|
||||||
exitsStack = []
|
exitsStack = []
|
||||||
avail = []
|
avail = []
|
||||||
for i in range(49):
|
for i in range(50):
|
||||||
avail.append('$' + str(i))
|
avail.append('$' + str(i))
|
||||||
|
|
||||||
indirectPointer = '$49'
|
|
||||||
|
|
||||||
# Operations related to the table of symbols
|
# Operations related to the table of symbols
|
||||||
symbols = {}
|
symbols = {}
|
||||||
# Our variables start at direction 50, the temps take the first 49 directions.
|
# Our variables start at direction 50, the temps take the first 49 directions.
|
||||||
|
|
@ -58,7 +56,9 @@ def addSymbol(name, symbolType):
|
||||||
'dimension1': globalDimension1,
|
'dimension1': globalDimension1,
|
||||||
'dimension2': globalDimension2,
|
'dimension2': globalDimension2,
|
||||||
}
|
}
|
||||||
currentIndex += globalDimensionalSize
|
if globalDimensionalSize != 1:
|
||||||
|
symbols[name]['indirectPointer'] = f'${currentIndex + globalDimensionalSize}'
|
||||||
|
currentIndex += 1 if globalDimensionalSize == 1 else globalDimensionalSize + 1
|
||||||
|
|
||||||
# Returns the last item of a list without deleting it.
|
# Returns the last item of a list without deleting it.
|
||||||
|
|
||||||
|
|
@ -83,7 +83,7 @@ def isTemp(operand):
|
||||||
def isDirection(operand):
|
def isDirection(operand):
|
||||||
if type(operand) is not str:
|
if type(operand) is not str:
|
||||||
return False
|
return False
|
||||||
if "$" in operand:
|
if "$" in operand or "*" in operand:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
@ -281,7 +281,7 @@ def p_S(p):
|
||||||
S : Dimensional action_7 equals EA action_8
|
S : Dimensional action_7 equals EA action_8
|
||||||
| id parens
|
| id parens
|
||||||
| read RDimensional
|
| read RDimensional
|
||||||
| print RDimOrString
|
| print RDimOrString action_35
|
||||||
| if action_16 Relif ElseOrEmpty end if action_20
|
| if action_16 Relif ElseOrEmpty end if action_20
|
||||||
| do id action_24 equals EA action_25 coma EA action_26 IntOrEmpty then B action_29 end do
|
| do id action_24 equals EA action_25 coma EA action_26 IntOrEmpty then B action_29 end do
|
||||||
| do then action_21 B action_22 end do
|
| do then action_21 B action_22 end do
|
||||||
|
|
@ -330,8 +330,8 @@ def p_RDimOrString(p):
|
||||||
|
|
||||||
def p_DimOrString(p):
|
def p_DimOrString(p):
|
||||||
'''
|
'''
|
||||||
DimOrString : Dimensional
|
DimOrString : Dimensional action_1 action_33
|
||||||
| string
|
| string action_34
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -462,6 +462,7 @@ def p_action_1(p):
|
||||||
dimension1 = symbols[p[-1]]['dimension1']
|
dimension1 = symbols[p[-1]]['dimension1']
|
||||||
dimension2 = symbols[p[-1]]['dimension2']
|
dimension2 = symbols[p[-1]]['dimension2']
|
||||||
if dimension2 is not 0:
|
if dimension2 is not 0:
|
||||||
|
indirectPointer = symbols[p[-1]]['indirectPointer']
|
||||||
if isDirection(globalIndex1) or isDirection(globalIndex2):
|
if isDirection(globalIndex1) or isDirection(globalIndex2):
|
||||||
resultQuadruplets.append(f'* {globalIndex1} {dimension1} {indirectPointer}\n')
|
resultQuadruplets.append(f'* {globalIndex1} {dimension1} {indirectPointer}\n')
|
||||||
quadrupletIndex += 1
|
quadrupletIndex += 1
|
||||||
|
|
@ -474,6 +475,7 @@ def p_action_1(p):
|
||||||
direction += globalIndex2 + (globalIndex1 * dimension1)
|
direction += globalIndex2 + (globalIndex1 * dimension1)
|
||||||
operandsStack.append(f'${direction}')
|
operandsStack.append(f'${direction}')
|
||||||
elif dimension1 is not 0:
|
elif dimension1 is not 0:
|
||||||
|
indirectPointer = symbols[p[-1]]['indirectPointer']
|
||||||
if isDirection(globalIndex1):
|
if isDirection(globalIndex1):
|
||||||
resultQuadruplets.append(f'+ {direction} {globalIndex1} {indirectPointer}\n')
|
resultQuadruplets.append(f'+ {direction} {globalIndex1} {indirectPointer}\n')
|
||||||
quadrupletIndex += 1
|
quadrupletIndex += 1
|
||||||
|
|
@ -571,6 +573,7 @@ def p_action_7(p):
|
||||||
dimension1 = symbols[p[-1]]['dimension1']
|
dimension1 = symbols[p[-1]]['dimension1']
|
||||||
dimension2 = symbols[p[-1]]['dimension2']
|
dimension2 = symbols[p[-1]]['dimension2']
|
||||||
if dimension2 is not 0:
|
if dimension2 is not 0:
|
||||||
|
indirectPointer = symbols[p[-1]]['indirectPointer']
|
||||||
if isDirection(globalIndex1) or isDirection(globalIndex2):
|
if isDirection(globalIndex1) or isDirection(globalIndex2):
|
||||||
resultQuadruplets.append(f'* {globalIndex1} {dimension1} {indirectPointer}\n')
|
resultQuadruplets.append(f'* {globalIndex1} {dimension1} {indirectPointer}\n')
|
||||||
quadrupletIndex += 1
|
quadrupletIndex += 1
|
||||||
|
|
@ -583,6 +586,7 @@ def p_action_7(p):
|
||||||
direction += globalIndex2 + (globalIndex1 * dimension1)
|
direction += globalIndex2 + (globalIndex1 * dimension1)
|
||||||
operandsStack.append(f'${direction}')
|
operandsStack.append(f'${direction}')
|
||||||
elif dimension1 is not 0:
|
elif dimension1 is not 0:
|
||||||
|
indirectPointer = symbols[p[-1]]['indirectPointer']
|
||||||
if isDirection(globalIndex1):
|
if isDirection(globalIndex1):
|
||||||
resultQuadruplets.append(f'+ {direction} {globalIndex1} {indirectPointer}\n')
|
resultQuadruplets.append(f'+ {direction} {globalIndex1} {indirectPointer}\n')
|
||||||
quadrupletIndex += 1
|
quadrupletIndex += 1
|
||||||
|
|
@ -910,6 +914,28 @@ def p_action_32(p):
|
||||||
globalDimension2 = 0
|
globalDimension2 = 0
|
||||||
globalDimensionalSize = 1
|
globalDimensionalSize = 1
|
||||||
|
|
||||||
|
def p_action_33(p):
|
||||||
|
"action_33 :"
|
||||||
|
global quadrupletIndex
|
||||||
|
operand1 = operandsStack.pop()
|
||||||
|
typesStack.pop()
|
||||||
|
resultQuadruplets.append(f'print {operand1}\n')
|
||||||
|
quadrupletIndex += 1
|
||||||
|
|
||||||
|
|
||||||
|
def p_action_34(p):
|
||||||
|
"action_34 :"
|
||||||
|
global quadrupletIndex
|
||||||
|
resultQuadruplets.append(f'print {p[-1]}\n')
|
||||||
|
quadrupletIndex += 1
|
||||||
|
|
||||||
|
|
||||||
|
def p_action_35(p):
|
||||||
|
"action_35 :"
|
||||||
|
global quadrupletIndex
|
||||||
|
resultQuadruplets.append('print "\\n"\n')
|
||||||
|
quadrupletIndex += 1
|
||||||
|
|
||||||
|
|
||||||
def p_action_setDim1(p):
|
def p_action_setDim1(p):
|
||||||
"action_setDim1 :"
|
"action_setDim1 :"
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
|
|
@ -1,6 +1,6 @@
|
||||||
program test
|
program test
|
||||||
integer :: b
|
integer [10] :: a, b
|
||||||
if (.not. 2 > 3 .or. 5 < 4) then
|
integer :: c
|
||||||
b = 2
|
print a(3), ' ', b(0), ' ', c, ' hello'
|
||||||
end if
|
c = 2
|
||||||
end program
|
end program
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
> 2 3 $0
|
print $53
|
||||||
< 5 4 $1
|
print ' '
|
||||||
.or. $0 $1 $2
|
print $61
|
||||||
.not. $2 $0
|
print ' '
|
||||||
gotoF $0 7
|
print $72
|
||||||
= 2 $50
|
print ' hello'
|
||||||
|
print "\n"
|
||||||
|
= 2 $72
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue