From 3bb50c40e19d34b50fe4faf61540a891657c72bd Mon Sep 17 00:00:00 2001 From: AYM1607 Date: Thu, 25 Apr 2019 04:11:50 -0500 Subject: [PATCH] Change not operand to save the result in temp variable --- final_lang/fort.py | 10 +++++++--- final_lang/test3.fort | 8 +++----- final_lang/test3.fort.out | 14 ++++++-------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/final_lang/fort.py b/final_lang/fort.py index 14e303c..f63bc9e 100644 --- a/final_lang/fort.py +++ b/final_lang/fort.py @@ -276,7 +276,6 @@ def p_B(p): | ''' - def p_S(p): ''' S : Dimensional action_7 equals EA action_8 @@ -707,9 +706,14 @@ def p_action_15(p): if (peek(typesStack) is not 'bool'): raise Exception("Cannot use .not. with non boolean") global quadrupletIndex - operand1 = peek(operandsStack) + # It is not necessary to pop the types stack since the result will also + # be bool. + operand1 = operandsStack.pop() + temp = avail.pop(0) + operandsStack.append(temp) resultQuadruplets.append('.not. ' + str(operand1) + - ' ' + str(operand1) + '\n') + ' ' + str(temp) + '\n') + quadrupletIndex += 1 def p_action_16(p): diff --git a/final_lang/test3.fort b/final_lang/test3.fort index 663005b..6627aab 100644 --- a/final_lang/test3.fort +++ b/final_lang/test3.fort @@ -1,8 +1,6 @@ program test integer :: b -integer [10] :: a -real :: c -do b = 0, 9 then - a(b) = b -end do +if (.not. 2 > 3 .or. 5 < 4) then + b = 2 +end if end program \ No newline at end of file diff --git a/final_lang/test3.fort.out b/final_lang/test3.fort.out index 851a862..1aa974f 100644 --- a/final_lang/test3.fort.out +++ b/final_lang/test3.fort.out @@ -1,8 +1,6 @@ -= 0 $50 -<= $50 9 $0 -gotoF $0 9 -+ 51 $50 $49 -= $50 *49 -+ $50 1 $1 -= $1 $50 -goto 2 +> 2 3 $0 +< 5 4 $1 +.or. $0 $1 $2 +.not. $2 $0 +gotoF $0 7 += 2 $50