def p_FunMark1(p): ''' FunMark1 : epsilon ''' #if p[-2][1] in ST.SymbolTable[ST.currScope]["function"].keys(): # error("Error: function with same name and same number of arguments already defined.") # else: if (len(p[-2]) > 2): ST.addFunc(p[-2][1], p[-2][2:]) else: ST.addFunc(p[-2][1]) ST.setRType(p[-1]) for l in range(2, len(p[-2])): ST.addParamVar(p[-2][l][0], p[-2][l][0], p[-2][l][1]) if p[-2][l][1] is 'Array': ST.addAttribute(p[-2][l][0], 'typeArray', 'Int') ST.addAttribute(p[-2][l][0], 'isparam', True) printp(p)
def p_var_def(p): ''' var_def : id COLON type EQUALASGN val_var_init ''' #if('isArray' in p[5].keys() and p[5]['isArray']): if type(p[5]) == type({}) and 'isArray' in p[5] and p[5]['isArray']: ST.addVar(p[1], p[1], 'Array', p[3]['size'], p[3]['type']) ST.addAttribute(p[1], 'typeArray', p[3]['type']) size = 1 for x in p[3]["size"]: size *= x emit('array', p[1], size) i = 0 for d in p[5]['values']: emit('star', p[1], i, d['place']) i += 1 # emit('array',p[],'n') elif type(p[5]) == type({}) and 'isObject' in p[5] and p[5]['isObject']: l = {} emit("Object", p[1], p[3]['type']) off = ST.SymbolTable[p[3]['type']]['totalOffset'] ST.addVar(p[1], p[1], p[3]['type'], sizeObj=off) offset = 0 for i in ST.SymbolTable[p[3]['type']]['identifiers'].keys(): l[ST.SymbolTable[p[3]['type']]['identifiers'][i]['place']] = { 'place': p[1] + '.' + ST.SymbolTable[p[3]['type']]['identifiers'][i]['place'], 'type': ST.SymbolTable[p[3]['type']]['identifiers'][i]['type'], 'offset': ST.SymbolTable[p[3]['type']]["identifiers"][i]['offset'] } ST.addAttribute(p[1], 'list', l) #ST.printSymbolTable() else: #print(p[5]) p[5] = evalArray(p[5]) ST.addVar(p[1], p[1], p[3]['type']) emit('=', in1=p[5]['place'], out=p[1]) printp(p)