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 = []
|
||||
exitsStack = []
|
||||
avail = []
|
||||
for i in range(49):
|
||||
for i in range(50):
|
||||
avail.append('$' + str(i))
|
||||
|
||||
indirectPointer = '$49'
|
||||
|
||||
# Operations related to the table of symbols
|
||||
symbols = {}
|
||||
# Our variables start at direction 50, the temps take the first 49 directions.
|
||||
|
|
@ -58,7 +56,9 @@ def addSymbol(name, symbolType):
|
|||
'dimension1': globalDimension1,
|
||||
'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.
|
||||
|
||||
|
|
@ -83,7 +83,7 @@ def isTemp(operand):
|
|||
def isDirection(operand):
|
||||
if type(operand) is not str:
|
||||
return False
|
||||
if "$" in operand:
|
||||
if "$" in operand or "*" in operand:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
|
@ -281,7 +281,7 @@ def p_S(p):
|
|||
S : Dimensional action_7 equals EA action_8
|
||||
| id parens
|
||||
| read RDimensional
|
||||
| print RDimOrString
|
||||
| print RDimOrString action_35
|
||||
| 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 then action_21 B action_22 end do
|
||||
|
|
@ -330,8 +330,8 @@ def p_RDimOrString(p):
|
|||
|
||||
def p_DimOrString(p):
|
||||
'''
|
||||
DimOrString : Dimensional
|
||||
| string
|
||||
DimOrString : Dimensional action_1 action_33
|
||||
| string action_34
|
||||
'''
|
||||
|
||||
|
||||
|
|
@ -462,6 +462,7 @@ def p_action_1(p):
|
|||
dimension1 = symbols[p[-1]]['dimension1']
|
||||
dimension2 = symbols[p[-1]]['dimension2']
|
||||
if dimension2 is not 0:
|
||||
indirectPointer = symbols[p[-1]]['indirectPointer']
|
||||
if isDirection(globalIndex1) or isDirection(globalIndex2):
|
||||
resultQuadruplets.append(f'* {globalIndex1} {dimension1} {indirectPointer}\n')
|
||||
quadrupletIndex += 1
|
||||
|
|
@ -474,6 +475,7 @@ def p_action_1(p):
|
|||
direction += globalIndex2 + (globalIndex1 * dimension1)
|
||||
operandsStack.append(f'${direction}')
|
||||
elif dimension1 is not 0:
|
||||
indirectPointer = symbols[p[-1]]['indirectPointer']
|
||||
if isDirection(globalIndex1):
|
||||
resultQuadruplets.append(f'+ {direction} {globalIndex1} {indirectPointer}\n')
|
||||
quadrupletIndex += 1
|
||||
|
|
@ -571,6 +573,7 @@ def p_action_7(p):
|
|||
dimension1 = symbols[p[-1]]['dimension1']
|
||||
dimension2 = symbols[p[-1]]['dimension2']
|
||||
if dimension2 is not 0:
|
||||
indirectPointer = symbols[p[-1]]['indirectPointer']
|
||||
if isDirection(globalIndex1) or isDirection(globalIndex2):
|
||||
resultQuadruplets.append(f'* {globalIndex1} {dimension1} {indirectPointer}\n')
|
||||
quadrupletIndex += 1
|
||||
|
|
@ -583,6 +586,7 @@ def p_action_7(p):
|
|||
direction += globalIndex2 + (globalIndex1 * dimension1)
|
||||
operandsStack.append(f'${direction}')
|
||||
elif dimension1 is not 0:
|
||||
indirectPointer = symbols[p[-1]]['indirectPointer']
|
||||
if isDirection(globalIndex1):
|
||||
resultQuadruplets.append(f'+ {direction} {globalIndex1} {indirectPointer}\n')
|
||||
quadrupletIndex += 1
|
||||
|
|
@ -910,6 +914,28 @@ def p_action_32(p):
|
|||
globalDimension2 = 0
|
||||
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):
|
||||
"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
|
||||
integer :: b
|
||||
if (.not. 2 > 3 .or. 5 < 4) then
|
||||
b = 2
|
||||
end if
|
||||
integer [10] :: a, b
|
||||
integer :: c
|
||||
print a(3), ' ', b(0), ' ', c, ' hello'
|
||||
c = 2
|
||||
end program
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
> 2 3 $0
|
||||
< 5 4 $1
|
||||
.or. $0 $1 $2
|
||||
.not. $2 $0
|
||||
gotoF $0 7
|
||||
= 2 $50
|
||||
print $53
|
||||
print ' '
|
||||
print $61
|
||||
print ' '
|
||||
print $72
|
||||
print ' hello'
|
||||
print "\n"
|
||||
= 2 $72
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue