From d7ebaa26ad0bb026e993f834ef37e81369dd706a Mon Sep 17 00:00:00 2001 From: AYM1607 Date: Fri, 12 Apr 2019 05:55:09 +0000 Subject: [PATCH] Added method to fill goto statements --- final_lang/experiments.py | 12 ++++++++++++ final_lang/fort.py | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 final_lang/experiments.py diff --git a/final_lang/experiments.py b/final_lang/experiments.py new file mode 100644 index 0000000..d988a4f --- /dev/null +++ b/final_lang/experiments.py @@ -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) \ No newline at end of file diff --git a/final_lang/fort.py b/final_lang/fort.py index bec52ca..2f16486 100644 --- a/final_lang/fort.py +++ b/final_lang/fort.py @@ -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")