Exemple #1
0
def Varlist(m):
    if (pop.EmptyP(m)): return
    while True:
        pio.WriteItem(pop.Head(m))
        m = pop.Tail(m)
        if (pop.EmptyP(m)): return
        printf(",")
Exemple #2
0
def Definitions(dl):
    while not pop.EmptyP(dl):
        Definition(pop.Head(dl))
        printf(";")
        dl = pop.Tail(dl)
        if pop.EmptyP(dl): return
        NewLine()
Exemple #3
0
def Termlist(m):
    if (pop.EmptyP(m)): return
    while True:
        Term(pop.Head(m))
        m = pop.Tail(m)
        if pop.EmptyP(m): return
        printf(",")
Exemple #4
0
def Lists(l):      #pop list l as a python string
    assert pop.ListP(l), 'lists given a non list'
    m = l
    b = '['
    while not pop.EmptyP(m):
         b = b+ Items(pop.Head(m))
         m = pop.Tail(m)
         if  not pop.EmptyP(m): b=b+' '
    return b+']'
Exemple #5
0
def CurrentItem(ig):
    """The current item of item generator ig - does not advance"""
    [m,ci,r] = ig
    if m == 'l':
        if ci == '':
           if pop.EmptyP(r): return '' #end of data
           ig[1] = pop.Head(r)
           return ig[1]
        return ci
    if m == 'c':
        if ci == '':
            skipwhites(r)
            d = ItemRead(r)
            if d == '' : return ''
            ig[1] = d
            return d
        return ci
    assert False, 'unknown item generator type '+m
Exemple #6
0
def NextItem(ig):
    """return current item, advancing"""
    d  = CurrentItem(ig)
    if d=='': return ''
    [m,ci,r]  = ig
    if m == "l":
        if EmptyP(r):
            ig[1] = ''
        else:
            ig[2] = pop.Tail(r)
            if EmptyP(ig[2]):
                ig[1] =  ''
            else:
                ig[1] = pop.Head(ig[2])
        return d
    if m == "c":
        ig[1] = ItemRead(r)
        ig[2]=r
        return d
    assert False, 'unlnown generator type '+m
Exemple #7
0
def Aoperation(e):
    """ returns e1 dl where dl is the list of atomic definitions generated
        and e1 is the new atomic expression """
    o = exp.OperationSymbol(e)    #operator
    l = exp.OperationOperandL(e)  #operands
    vl = pop.Empty                #new variables introduced
    aeqs = pop.Empty              #list of equations generated
    while l != pop.Empty:          #iterate down operand list
        opd = pop.Head(l);l = pop.Tail(l)  #get next operand and advance
        if exp.VarP(opd):      #if it's a var nothing to do
            vl = pop.Cons(opd,vl)
            continue
        ae, dl = Aexpr(opd)         # process the operand
        aeqs = pop.Append(dl,aeqs)     # collect equations generated
        if not exp.VarP(ae):
            nv = VarGen()               # generate a new variable
            vl = pop.Cons(nv,vl)           # save it  
            d = exp.DefinitionC(nv,pop.EQUALWord,ae)      # generate new atomic definition
            aeqs = pop.Cons(d,aeqs) 
        else:
            vl = pop.Cons(ae,vl)
    vl = pop.Reverse(vl)               # variables accumulated in reverse order
    e1 = exp.OperationC(o,vl)           # new atomic expression
    return e1, aeqs                # return the atomic expression and equations generated
Exemple #8
0
def Reserve(l):
    s = set()
    while not pop.EmptyP(l):
        s.add(pop.Head(l))
        l = pop.Tail(l)
    return s
Exemple #9
0
            vl = pop.Cons(ae,vl)
    vl = pop.Reverse(vl)               # variables accumulated in reverse order
    e1 = exp.OperationC(o,vl)           # new atomic expression
    return e1, aeqs                # return the atomic expression and equations generated
    
varcount = 0

def VarGen():
    global varcount
    s = str(varcount+100)
    varcount = varcount+1
    var = 'V'+s[1:]
    return exp.VarC(pop.WordC(var))
    
if __name__ == "__main__":
    prog = ''
    while True:
        ln = input()
        if ln==';': break
        prog = prog + ' ' + ln
    cg = gen.CharStringC(prog)
    ig = pio.ItemGenChargenC(cg)
    e = prs.Expr(ig)
    pio.WriteItemln(e)
    prp.Term(e);print()
    e1,dl = Aexpr(e)
    prp.Term(e1);print(' where')
    while dl != pop.Empty:
        prp.Definition(pop.Head(dl));print()
        dl = pop.Tail(dl)