Example #1
0
def mult(cuad, i):
    dir1 = (cuad.dir1.split('['))
    dir2 = (cuad.dir2.split('['))
    len1 = len(dir1)
    len2 = len(dir2)
    if (len1 < 2 and len2 < 2):
        dir1 = apuntador(cuad.dir1)
        dir2 = apuntador(cuad.dir2)
        result = apuntador(cuad.result)
        if dir1 >= 8000 and dir1 < 13000:
            left_op = findCte(dir1)
        else:
            left_op = memo.get(glob, globTemp, local, localTemp, dir1)
        if dir2 >= 8000 and dir2 < 13000:
            right_op = findCte(dir2)
        else:
            right_op = memo.get(glob, globTemp, local, localTemp, dir2)
        res = left_op * right_op
        memo.assign(glob, globTemp, local, localTemp, result, res)
        return i + 1
    else:
        result = (cuad.result.split('['))
        if (len1 < 2):
            dir1 = apuntador(cuad.dir1)
            if dir1 >= 8000 and dir1 < 13000:
                left_op = findCte(dir1)
            else:
                left_op = memo.get(glob, globTemp, local, localTemp, dir1)
            mat2 = createMat(dir2)
            res = np.multiply(left_op, mat2)
            createMatRes(result, res)
        elif (len2 < 2):
            mat1 = createMat(dir1)
            dir2 = apuntador(cuad.dir2)
            if dir2 >= 8000 and dir2 < 13000:
                right_op = findCte(dir2)
            else:
                right_op = memo.get(glob, globTemp, local, localTemp, dir2)
            res = np.multiply(mat1, right_op)
            createMatRes(result, res)
        else:
            mat1 = createMat(dir1)
            mat2 = createMat(dir2)
            res = np.dot(mat1, mat2)
            if (str(res)[0] != '['):
                result = apuntador(cuad.result)
                memo.assign(glob, globTemp, local, localTemp, result, res)
            else:
                createMatRes(result, res)
    return i + 1
Example #2
0
def div(cuad, i):
    dir1 = apuntador(cuad.dir1)
    dir2 = apuntador(cuad.dir2)
    result = apuntador(cuad.result)
    if dir1 >= 8000 and dir1 < 13000:
        left_op = findCte(dir1)
    else:
        left_op = memo.get(glob, globTemp, local, localTemp, dir1)
    if dir2 >= 8000 and dir2 < 13000:
        right_op = findCte(dir2)
    else:
        right_op = memo.get(glob, globTemp, local, localTemp, dir2)
    res = left_op / right_op
    memo.assign(glob, globTemp, local, localTemp, result, res)
    return i + 1
Example #3
0
def param(cuad, i):
    global numParams
    global intP
    global floatP
    global charP
    dir1 = apuntador(cuad.dir1)
    space = int(cuad.result) - 1
    memT = memo.indentifyType(dir1)
    if numParams > 0:
        if funcParams[space] == 'i' and memT == 1:
            dir = 13000 + intP
            intP += 1
        elif funcParams[space] == 'f' and memT == 2:
            dir = 14000 + floatP
            floatP += 1
        elif funcParams[space] == 'c' and memT == 3:
            dir = 15000 + charP
            charP += 1
        else:
            print('Error: Parametros no compatibles')
            sys.exit()
        if dir1 >= 8000 and dir1 < 13000:
            left_op = findCte(dir1)
        else:
            left_op = memo.get(glob, globTemp, local, localTemp, dir1)
        memo.assign(glob, globTemp, local2, localTemp2, dir, left_op)
        numParams -= 1
        if numParams == 0:
            intP = 0
            floatP = 0
            charP = 0
        return i + 1
    else:
        print('Error: Se esperaban menos parametros')
        sys.exit()
Example #4
0
def gotofalse(cuad, i):
    dir1 = int(cuad.dir1)
    left_op = memo.get(glob, globTemp, local, localTemp, dir1)
    if (left_op):
        return i + 1
    else:
        return int(cuad.result)
Example #5
0
def escribe(cuad, i):
    dir1 = apuntador(cuad.result)
    if dir1 >= 8000 and dir1 < 13000:
        left_op = findCte(dir1)
    else:
        left_op = memo.get(glob, globTemp, local, localTemp, dir1)
    print(left_op)
    return i + 1
Example #6
0
def orOp(cuad, i):
    dir1 = int(cuad.dir1)
    dir2 = int(cuad.dir2)
    if dir1 >= 8000 and dir1 < 13000:
        left_op = findCte(dir1)
    else:
        left_op = memo.get(glob, globTemp, local, localTemp, dir1)
    if dir2 >= 8000 and dir2 < 13000:
        right_op = findCte(dir2)
    else:
        right_op = memo.get(glob, globTemp, local, localTemp, dir2)
    if (left_op or right_op):
        res = True
    else:
        res = False
    memo.assign(glob, globTemp, local, localTemp, int(cuad.result), res)
    return i + 1
Example #7
0
def createMat(dir):
    dir1 = int(dir[0])
    lim1 = findCte(int(dir[1])) + 1
    matrix = []
    if (len(dir) == 2):
        for c in range(lim1):
            space = dir1 + c
            matrix.append(memo.get(glob, globTemp, local, localTemp, space))
        return matrix
    else:
        lim2 = findCte(int(dir[2])) + 1
        for r in range(0, lim1):
            a = []
            for c in range(0, lim2):
                space = (r * lim1) + c + dir1
                val = memo.get(glob, globTemp, local, localTemp, space)
                a.append(val)
            matrix.append(a)
        return matrix
Example #8
0
def ver(cuad, i):
    dir1 = apuntador(cuad.dir1)
    dir2 = int(cuad.dir2)
    dir3 = int(cuad.result)
    if dir1 >= 8000 and dir1 < 13000:
        val = findCte(dir1)
    else:
        val = memo.get(glob, globTemp, local, localTemp, dir1)
    if dir2 >= 8000 and dir2 < 13000:
        lim_inf = findCte(dir2)
    else:
        lim_inf = memo.get(glob, globTemp, local, localTemp, dir2)
    if dir3 >= 8000 and dir3 < 13000:
        lim_sup = findCte(dir3)
    else:
        lim_sup = memo.get(glob, globTemp, local, localTemp, dir3)
    if val >= lim_inf and val <= lim_sup:
        return i + 1
    else:
        print('Error: Varibale dimensionada fuera de rango')
Example #9
0
def apuntador(dir):
    if dir[0] == '(':
        dir = dir.rstrip(')')
        dir = dir.lstrip('(')
        dir = int(dir)
        return memo.get(glob, globTemp, local, localTemp, dir)
    else:
        if dir == None:
            return dir
        else:
            return int(dir)
Example #10
0
def regresa(cuad, i):
    global local
    global localTemp
    dir1 = apuntador(cuad.result)
    reQuad = returnQuad.pop()
    dir = funcId.pop()
    if dir != None:
        dir = int(dir)
    if dir1 >= 8000 and dir1 < 13000:
        left_op = findCte(dir1)
    else:
        left_op = memo.get(glob, globTemp, local, localTemp, dir1)
    memo.assign(glob, globTemp, local, localTemp, dir, left_op)
    local = memo.memStack.pop()
    localTemp = memo.memTStack.pop()
    return reQuad + 1
Example #11
0
def asigna(cuad, i):
    dir1 = (cuad.dir1.split('['))
    result = (cuad.result.split('['))
    len1 = len(dir1)
    len2 = len(result)
    if (len1 < 2 and len2 < 2):
        dir1 = apuntador(cuad.dir1)
        result = apuntador(cuad.result)
        if dir1 >= 8000 and dir1 < 13000:
            right_op = findCte(dir1)
        else:
            right_op = memo.get(glob, globTemp, local, localTemp, dir1)
        memo.assign(glob, globTemp, local, localTemp, result, right_op)
        return i + 1
    else:
        mat1 = createMat(dir1)
        createMatRes(result, mat1)
        return i + 1