Added translation for do statements with exit

This commit is contained in:
Mariano Uvalle 2019-04-12 14:08:28 -05:00
parent 304873e6ca
commit 1be80bcbd3
5 changed files with 613 additions and 518 deletions

View file

@ -250,9 +250,9 @@ def p_S(p):
| print RDimOrString
| if action_16 Relif ElseOrEmpty end if action_20
| do id equals EA coma EA IntOrEmpty then B end do
| do then B end do
| do then action_21 B action_22 end do
| swap Dimensional coma Dimensional
| exit
| exit action_23
'''
# Adjust the action to support matrices
@ -622,6 +622,36 @@ def p_action_20(p):
fillGoto(Dir, quadrupletIndex)
jumpsStack.pop()
def p_action_21(p):
"action_21 :"
jumpsStack.append(quadrupletIndex)
exitsStack.append('$')
def p_action_22(p):
"action_22 :"
global resultQuadruplets
global quadrupletIndex
Dir = jumpsStack.pop()
resultQuadruplets.append(f'goto {Dir}\n')
quadrupletIndex += 1
while(peek(exitsStack) != '$'):
Dir = exitsStack.pop()
fillGoto(Dir, quadrupletIndex)
exitsStack.pop()
def p_action_23(p):
"action_23 :"
global quadrupletIndex
global quadrupletIndex
exitsStack.append(quadrupletIndex)
resultQuadruplets.append('goto _\n')
quadrupletIndex += 1
def p_error(p):
print('XXX Invalid program')
print(p)
@ -642,8 +672,6 @@ if (len(sys.argv) > 1):
program = programFile.read().replace('\\n', '\n')
parser.parse(program)
print(resultQuadruplets)
print(symbols)
resultFile.writelines(resultQuadruplets)
# Close the files.

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

View file

@ -1,5 +1,6 @@
program test
integer :: a, b, c, d, x, y, z, w
real :: e, f
a = 2 + 4 * (2 + 1) / 3 * b
b = a
if (a > b) then
@ -11,4 +12,10 @@ elif (a > d) then
else
a = w
end if
do then
if (a > b .or. c > b) then
exit
end if
a = a + 1
end do
end program

View file

@ -18,3 +18,11 @@ gotoF $0 20
= $56 $50
goto 21
= $57 $50
> $50 $51 $0
> $52 $51 $1
.or. $0 $1 $2
gotoF $2 26
goto 29
+ $50 1 $2
= $2 $50
goto 21