def p_ARRAY_ASGN(p): '''ASGN : Identifier EQUALS ARRAY DOT NEW LPAREN NUMBER RPAREN ''' p[0] = {} if sym_tab.exists(p[1]): sym_tab.add_attri(p[1], 'type', 'ARRAY') if p[1] in sym_tab.scope[len(sym_tab.scope) - 1]: place = sym_tab.getAttri( p[1], sym_tab.scope[len(sym_tab.scope) - 1]['__scope__']) else: disp_val = sym_tab.getAttri(p[1], 'level') offset = sym_tab.getAttri(p[1], 'offset') place = sym_tab.new_temp((disp_val, offset), variable=p[1]) sym_tab.add_attri(p[1], sym_tab.scope[len(self.scope) - 1]['__scope__'], p[1]) TAC.emit('=', '[]', place, p[7]) p[0]['code'] = ['=' + ',' + '[]' + ',' + str(place) + ',' + p[7]] else: sym_tab.addID(p[1], 'ARRAY') # Create a temporary for the current scope displayValue, offset = sym_tab.getAttri( p[1], 'scopeLevel'), sym_tab.getAttri(p[1], 'offset') place = sym_tab.new_temp((displayValue, offset), variable=p[1]) sym_tab.add_attri(p[1], sym_tab.scope[len(sym_tab.scope) - 1]['__scope__'], p[1]) TAC.emit('=', '[]', place, p[7])
def p_varname(p): ''' VARNAME : Identifier ''' p[0] = {} if sym_tab.exists(p[1]): p[0]['type'] = sym_tab.getAttri(p[1], 'type') # Here we have to load in the value of the variable if not p[1] in sym_tab.scope[len(sym_tab.scope) - 1]: # If an identifier is used, we assume that it is present in memory displayValue, offset = sym_tab.getAttri( p[1], 'scopeLevel'), sym_tab.getAttri(p[1], 'offset') p[0]['place'] = sym_tab.newTemp((displayValue, offset), variable=p[1], loadFromMemory=True) sym_tab.addAttribute(p[1], sym_tab.getCurrentScope(), p[0]['place']) else: p[0]['code'] = [] p[0]['place'] = sym_tab.getAttri( p[1], sym_tab.scope[len(sym_tab.scope) - 1]['__scope__']) else: print "F**K OFF"
def p_ARG_relational(p) : ''' ARG : Identifier EQUALS ARG SemiColon ''' p[0] = {} place = None if sym_tab.exists(p[1]): sym_tab.add_attri(p[1]) if p[1] in sym_tab.scope[len(sym_tab.scope)-1] : place = sym_tab.getAttri(p[1],sym_tab.scope[len(sym_tab.scope)-1]['__scope__']) else : disp_val = sym_tab.getAttri(p[1],'scopelevel') offset = sym_tab.getAttri(p[1],'offset') place = sym_tab.new_temp((disp_val, offset), variable=p[1]) sym_tab.add_attri(p[1],sym_tab.scope[len(self.scope) - 1]['__scope__'],p[1]) TAC.emit('=',p[1],str(p[3]['place']),'') p[0]['code']=p[3]['code']+['='+','+str(p[1])+','+str(p[3]['place']) +','+'' ] else : sym_tab.addID(p[1], p[3]['type']) print p[3], "FOOO" # Create a temporary for the current scope displayValue, offset = sym_tab.getAttri(p[1], 'scopeLevel'), sym_tab.getAttri(p[1], 'offset') place = sym_tab.new_temp((displayValue, offset), variable=p[1]) sym_tab.add_attri(p[1], sym_tab.scope[len(sym_tab.scope)-1]['__scope__'], p[1]) TAC.emit('=',p[1],str(p[3]['place']),'') p[0]['code']=p[3]['code']+['='+','+str(p[1])+','+str(p[3]['place']) +','+'' ] print p[3], "RANDi"
def p_complex169(p): '''complex169 : empty ''' for args in p[-2] : print args sym_tab.addID(args['name'],args['type']) displayValue, offset = sym_tab.getAttri(args['name'], 'level'), sym_tab.getAttri(argument['name'], 'offset') place = sym_tab.new_temp((displayValue, offset), variable=argument['name'], loadFromMemory=True) sym_tab.addAttri(args['name'], sym_tab.getCurrentScope(), place)
def p_complex145(p): '''complex145 : empty''' p[0] = {} p[0]['name_fun'] = sym_tab.get_name() sym_tab.addID(p[-1], "function") displayValue, offset = sym_tab.getAttri(p[-1], 'level'), sym_tab.getAttri(p[-1], 'offset') place = sym_tab.new_temp((displayValue, offset), variable=p[-1]) sym_tab.add_attri(p[-1], sym_tab.getCurrentScope(), place) sym_tab.add_attri(p[-1], 'name_fun', p[0]['name_fun']) sym_tab.add_Sc(p[0]['name_fun']) TAC.code[p[0]['name_fun']] = [] TAC.quad[p[0]['name_fun']] = 0 TAC.nq[p[0]['name_fun']] = -1
def p_varname(p) : ''' VARNAME : Identifier ''' p[0] = {} p[0]['ptr'] = Leaf('id',p[1]) if sym_tab.exists(p[1]): p[0]['type'] = sym_tab.getAttri(p[1], 'type') p[0]['code'] = [''] if not p[1] in sym_tab.scope[len(sym_tab.scope)-1]: displayValue = sym_tab.getAttri(p[1], 'scopeLevel') offset = sym_tab.getAttri(p[1], 'offset') p[0]['place'] = sym_tab.newTemp((displayValue, offset), variable=p[1], loadFromMemory=True) sym_tab.addAttribute(p[1], sym_tab.getCurrentScope(), p[0]['place']) else: p[0]['place'] = sym_tab.getAttri(p[1],sym_tab.scope[len(sym_tab.scope)-1]['__scope__'] )
def p_ASGN_basic(p): '''ASGN : Identifier EQUALS EXPR ''' p[0] = {} place = None if sym_tab.exists(p[1]): sym_tab.add_attri(p[1], 'type', p[3]['type']) if p[1] in sym_tab.scope[len(sym_tab.scope) - 1]: place = sym_tab.getAttri( p[1], sym_tab.scope[len(sym_tab.scope) - 1]['__scope__']) else: disp_val = sym_tab.getAttri(p[1], 'level') offset = sym_tab.getAttri(p[1], 'offset') place = sym_tab.new_temp((disp_val, offset), variable=p[1]) sym_tab.add_attri(p[1], sym_tab.scope[len(self.scope) - 1]['__scope__'], p[1]) TAC.emit('=', place, str(p[3]['place']), '') # if p[1] == 'a' and p[3]['place'] == '3' : # print "HOLLO" #print p[3], "OKY" , p[1] p[0]['code'] = p[3]['code'] + [ '=' + ',' + str(place) + ',' + str(p[3]['place']) + ',' + '' ] else: sym_tab.addID(p[1], p[3]['type']) # Create a temporary for the current scope displayValue, offset = sym_tab.getAttri( p[1], 'scopeLevel'), sym_tab.getAttri(p[1], 'offset') place = sym_tab.new_temp((displayValue, offset), variable=p[1]) sym_tab.add_attri(p[1], sym_tab.scope[len(sym_tab.scope) - 1]['__scope__'], p[1]) TAC.emit('=', p[1], str(p[3]['place']), '')