Added tranlation action for assignation
This commit is contained in:
parent
81a2de075c
commit
92b679e13c
5 changed files with 271 additions and 221 deletions
|
|
@ -26,9 +26,9 @@ symbols = {}
|
||||||
# symbolsTypes.append(symbolType)
|
# symbolsTypes.append(symbolType)
|
||||||
|
|
||||||
# Implementation using a dictionary
|
# Implementation using a dictionary
|
||||||
def addSymbol(name, symbolsTypes):
|
def addSymbol(name, symbolType):
|
||||||
initialValue = 0 if symbolsTypes == 'integer' else 0.0
|
initialValue = 0 if symbolType == 'integer' else 0.0
|
||||||
symbols[name] = [name, initialValue]
|
symbols[name] = [symbolType, initialValue]
|
||||||
|
|
||||||
def peek(list):
|
def peek(list):
|
||||||
if (len(list) == 0):
|
if (len(list) == 0):
|
||||||
|
|
@ -202,7 +202,7 @@ def p_B(p):
|
||||||
|
|
||||||
def p_S(p):
|
def p_S(p):
|
||||||
'''
|
'''
|
||||||
S : Dimensional equals EA
|
S : Dimensional action_7 equals EA action_8
|
||||||
| id parens
|
| id parens
|
||||||
| read RDimensional
|
| read RDimensional
|
||||||
| print RDimOrString
|
| print RDimOrString
|
||||||
|
|
@ -383,6 +383,17 @@ def p_action_6(p):
|
||||||
quadrupletIndex += 1
|
quadrupletIndex += 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def p_action_7(p):
|
||||||
|
"action_7 :"
|
||||||
|
operandsStack.append(p[-1])
|
||||||
|
|
||||||
|
|
||||||
|
def p_action_8(p):
|
||||||
|
"action_8 :"
|
||||||
|
operand2 = operandsStack.pop()
|
||||||
|
operand1 = operandsStack.pop()
|
||||||
|
resultQuadruplets.append('= ' + str(operand2) + ' ' + str(operand1) + '\n')
|
||||||
def p_error(p):
|
def p_error(p):
|
||||||
print('XXX Invalid program')
|
print('XXX Invalid program')
|
||||||
print(p)
|
print(p)
|
||||||
|
|
@ -399,6 +410,7 @@ if (len(sys.argv) > 1):
|
||||||
parser.parse(program)
|
parser.parse(program)
|
||||||
|
|
||||||
print(resultQuadruplets)
|
print(resultQuadruplets)
|
||||||
|
print(symbols)
|
||||||
resultFile.writelines(resultQuadruplets)
|
resultFile.writelines(resultQuadruplets)
|
||||||
|
|
||||||
# Close the files.
|
# Close the files.
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
|
|
@ -1,5 +1,5 @@
|
||||||
program test
|
program test
|
||||||
integer :: a, b
|
integer :: a, b
|
||||||
a = (2 + 1) * 2
|
a = (2 + 1) + 4 * 2 / 3 * b
|
||||||
b = a
|
b = a
|
||||||
end program
|
end program
|
||||||
|
|
@ -1,2 +1,7 @@
|
||||||
+ 2 1 T0
|
+ 2 1 T0
|
||||||
* T0 2 T1
|
* 4 2 T1
|
||||||
|
/ T1 3 T2
|
||||||
|
* T2 b T3
|
||||||
|
+ T0 T3 T4
|
||||||
|
= T4 a
|
||||||
|
= a b
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue