From 31a845c82ec6e771bd7190d2e43fda26b7a8de80 Mon Sep 17 00:00:00 2001 From: pprabh2007 <32813957+pprabh2007@users.noreply.github.com> Date: Tue, 11 Dec 2018 21:31:48 +0530 Subject: [PATCH 1/2] Add files via upload --- libs/sudocode_c.py | 83 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 70 insertions(+), 13 deletions(-) diff --git a/libs/sudocode_c.py b/libs/sudocode_c.py index 83feb8c..e50fad7 100644 --- a/libs/sudocode_c.py +++ b/libs/sudocode_c.py @@ -1,5 +1,67 @@ #print(__name__) +def variable_line(line_elem): + + ''' Uncomment for testing this function individually + + line_elem = line_elem.split(" ") #tokenisation at space + line_elem[-1] = line_elem[-1].replace("\n","") #replacing new line char with null char + line_elem[0] = line_elem[0].lower() + line_elem=list(filter(lambda x: x!='', line_elem)) + ''' + + elem_no=0 #the index of the word in the line we are probing + var_type="" #the type of variable + var_value='' #the value of variable + var_identifier="" #variable indentifier + if(line_elem[elem_no] in ["int", "float"]): #check if there is a type specified + var_type=line_elem[elem_no] #assign the type + elem_no+=1 #increment elem_no i.e. to probe the next element + if(var_type=="int"): + var_value="0" + elif(var_type=="float"): + var_value="0.0" + + else: # assign float + var_type="float" + var_value="0.0" + + + #if there is an equal to, separate the identifier and value + + #CASES TO BE DEALT WITH: + # + # + # + # + + + + if('=' in line_elem[elem_no]): + pos=line_elem[elem_no].find("=") + var_identifier=line_elem[elem_no][0:pos] + line_elem[elem_no]=line_elem[elem_no][pos:] + + else: + var_identifier=line_elem[elem_no] + elem_no+=1 + + #print(len(line_elem)) + + #checking if there is a value assigned or not. If it is assign it. + + if(elem_no