Exemple #1
0
def p_var_dcl(p):
    '''var_dcl  :   id COLON type
    '''
    ST.addVar(p[1], p[1], p[3]['type'])
    #print p[1]
    p[0] = {}
    p[0]['place'] = p[1]
    p[0]['type'] = p[3]['type']
    printp(p)
Exemple #2
0
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)