Exemple #1
0
def plus_exp(node):

    (PLUS,c1,c2) = node

    t1 = walk(c1)
    t2 = walk(c2)

    return promote(t1,t2)
Exemple #2
0
def mul_exp(node):

    (MUL, c1, c2) = node

    (t1, v1) = walk(c1)
    (t2, v2) = walk(c2)

    t = promote(t1, t2)

    return (t, coerce(t, t1)(v1) * coerce(t, t2)(v2))
Exemple #3
0
def minus_exp(node):

    (MINUS, c1, c2) = node

    (t1, v1) = walk(c1)
    (t2, v2) = walk(c2)

    t = promote(t1, t2)

    return (t, coerce(t, t1)(v1) - coerce(t, t2)(v2))
Exemple #4
0
def plus_exp(node):

    (PLUS, c1, c2) = node

    (t1, v1) = walk(c1)
    (t2, v2) = walk(c2)

    t = promote(t1, t2)

    return (t, coerce(t, t1)(v1) + coerce(t, t2)(v2))
Exemple #5
0
def le_exp(node):

    (LE,c1,c2) = node

    t1 = walk(c1)
    t2 = walk(c2)
    if promote(t1,t2)[0] == 'VOID_TYPE':
        raise ValueError("Illegal type in relational operator.")

    return ('INTEGER_TYPE',)
Exemple #6
0
def div_exp(node):

    (DIV,c1,c2) = node

    t1 = walk(c1)
    t2 = walk(c2)
    tr = promote(t1,t2)
    if tr[0] not in ['INTEGER_TYPE','FLOAT_TYPE']:
        raise ValueError("operation on type {} not supported"
                        .format(tr[0]))
    return tr
Exemple #7
0
def le_exp(node):

    (LE, c1, c2) = node

    (t1, v1) = walk(c1)
    (t2, v2) = walk(c2)
    t = promote(t1, t2)

    if coerce(t, t1)(v1) <= coerce(t, t2)(v2):
        return ('INTEGER_TYPE', 1)
    else:
        return ('INTEGER_TYPE', 0)
Exemple #8
0
def div_exp(node):

    (DIV, c1, c2) = node

    (t1, v1) = walk(c1)
    (t2, v2) = walk(c2)

    t = promote(t1, t2)

    if t == 'INTEGER_TYPE':
        return ('INTEGER_TYPE', v1 // v2)
    else:
        return (t, coerce(t, t1)(v1) / coerce(t, t2)(v2))