Added method to fill goto statements
This commit is contained in:
parent
2833e9595d
commit
d7ebaa26ad
2 changed files with 44 additions and 1 deletions
12
final_lang/experiments.py
Normal file
12
final_lang/experiments.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
quads = ['= a b c', 'goto _', 'gotoF $2 _']
|
||||
|
||||
def fillGoto(position, fillValue):
|
||||
global quads
|
||||
quads[position] = quads[position].replace('_', str(fillValue))
|
||||
return
|
||||
|
||||
print(quads)
|
||||
fillGoto(1, 4)
|
||||
print(quads)
|
||||
fillGoto(2, 5)
|
||||
print(quads)
|
||||
|
|
@ -3,6 +3,10 @@ import ply.yacc as yacc
|
|||
import sys
|
||||
from typeValidation import resultingType
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
#--------------------------------Globals-------------------------------------
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
kEqualityOperators = ['>', '<', '>=', '<=', '==', '/=',]
|
||||
|
||||
resultQuadruplets = []
|
||||
|
|
@ -23,7 +27,11 @@ symbols = {}
|
|||
# Our variables start at direction 50, the temps take the first 50 directions.
|
||||
currentIndex = 50
|
||||
|
||||
# Implementation using a dictionary
|
||||
#----------------------------------------------------------------------------
|
||||
#------------------------------Util methods----------------------------------
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# Adds a symbol to the symbols table.
|
||||
def addSymbol(name, symbolType):
|
||||
global currentIndex
|
||||
initialValue = 0 if symbolType == 'integer' else 0.0
|
||||
|
|
@ -49,6 +57,15 @@ def isTemp(operand):
|
|||
return True
|
||||
return False
|
||||
|
||||
def fillGoto(position, fillValue):
|
||||
global resultQuadruplets
|
||||
resultQuadruplets[position] = resultQuadruplets[position].replace('_', str(fillValue))
|
||||
return
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
#---------------------------------LEXER--------------------------------------
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
|
||||
tokens = [
|
||||
'doubleColon',
|
||||
|
|
@ -159,6 +176,12 @@ def t_error(t):
|
|||
|
||||
lexer = lex.lex()
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
#---------------------------------PARSER-------------------------------------
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
|
||||
def p_programa(p):
|
||||
'''
|
||||
programa : program id V F B end program
|
||||
|
|
@ -355,6 +378,9 @@ def p_EQSymbols(p):
|
|||
'''
|
||||
p[0] = p[1]
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
#-----------------------------PARSER ACTIONS---------------------------------
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
def p_action_1(p):
|
||||
"action_1 :"
|
||||
|
|
@ -553,6 +579,11 @@ def p_error(p):
|
|||
|
||||
parser = yacc.yacc()
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
#--------------------INTERMEDIATE CODE FILE GENERATION-----------------------
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
if (len(sys.argv) > 1):
|
||||
programName = sys.argv[1]
|
||||
programFile = open(programName, "r")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue