Added method to fill goto statements

This commit is contained in:
Mariano Uvalle 2019-04-12 05:55:09 +00:00
parent 2833e9595d
commit d7ebaa26ad
2 changed files with 44 additions and 1 deletions

View file

@ -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")