Beispiel #1
0
def Awhere(wc):
    """ atomize subject and rhs of where clause adding generated defs to body """
    subject, wk,body = exp.WhereD(wc)
    atomicsubject, atomicdefs = Aexpr(subject)
    assert pop.ListP(atomicdefs), 'oops'
    while body != pop.Empty:
        mdef ,body = pop.DeCons(body)
        newdef, eqns = Adefinition(mdef); 
        assert pop.ListP(eqns), 'arg'
        atomicdefs = pop.Append(atomicdefs,eqns)
        atomicdefs = pop.Cons(newdef,atomicdefs)
    return exp.WhereC(atomicsubject,wk,atomicdefs),pop.Empty
Beispiel #2
0
def Items(i):      #pop item i as a python string
    if i=='': return '' #eod
    if pop.ListP(i):   return Lists(i)
    if pop.NumP(i):    return Nums(i)
    if pop.WordP(i):   return Words(i)
    if pop.StringP(i): return Strings(i)
    if pop.SetP(i):    return Sets(i)
    assert False, 'Items given non item '+str(i)
Beispiel #3
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+']'
Beispiel #4
0
def ActualTable(e, atab, ftab):
    """ collects a table of actuals in the order of appearance
        returns table and yaghified program"""
    if LiteralP(e): return atab, ftab, e
    if VarP(e): return atab, ftab, e
    if OperationP(e):
        o, opds = OperationD(e)
        if pop.ListP(o):
            print(e)
            print(o)
            exit()
        tab, ftab, yopds = ActualTableList(opds, atab, ftab)
        return tab, ftab, OperationC(o, yopds)
    if WhereP(e):
        subj, wk, body = WhereD(e)
        atab, ftab, ysubj = ActualTable(subj, atab, ftab)
        atab, ftab, ybody = ActualTableList(body, atab, ftab)
        return atab, ftab, WhereC(ysubj, wk, ybody)
    if VarDefinitionP(e):
        v, es, rhs = VarDefinitionD(e)
        atab, ftab, yrhs = ActualTable(rhs, atab, ftab)
        return atab, ftab, DefinitionC(VarC(v), es, yrhs)
    if FunDefinitionP(e):
        f, formals, es, rhs = FunDefinitionD(e)
        atab, ftab, yrhs = ActualTable(rhs, atab, ftab)
        ftab = map.Extend(ftab, f, formals)
        return atab, ftab, DefinitionC(VarC(f), es, yrhs)
    if CallP(e):
        fun, actuals = CallD(e)
        funvar = Var(fun)
        atab, ftab, yactuals = ActualTableList(actuals, atab, ftab)
        ok, actlist = map.Apply(atab, funvar)
        if not ok: actlist = pop.Empty
        newactlist = pop.Append(actlist, pop.List1(yactuals))
        atab = map.MapS(atab, funvar, newactlist)
        return atab, ftab, OperationC(
            YCALLWord,
            pop.List2(fun, LiteralC(pop.NumC(pop.Length(newactlist) - 1))))
Beispiel #5
0
def Factor(g):
    """ return next factor - smallest initial sub expression """
    lex = pio.CurrentItem(g)
    if lex == '': return ''
    if lex == pop.QUOTEWord: return Word(g)
    if lex == pop.IFWord: return IfExpr(g)
    if lex == pop.VALOFWord: return Valof(g)
    if lex == pop.LLISTPARENWord: return Listexpression(g)
    if lex == pop.LSETPARENWord: return Setexpression(g)
    if(exp.PrefixP(lex)): return Complete('',g); # prefix operator
    if exp.NullfixP(lex): pio.NextItem(g);return exp.Operation0C(lex)
    if(pop.NumP(lex) or pop.StringP(lex) or pop.ListP(lex)):  
        pio.NextItem(g);return exp.LiteralC(lex) #a literal
    if lex in reservedwords: return ''
    if(pio.IdentP(lex)):
        pio.NextItem(g);
        if pio.CurrentItem(g) == LparenWord: #function call
            return Call(exp.VarC(lex),g)
        return exp.VarC(lex)
    if exp.NullfixP(lex): pio.NextItem(g);return Operation0C(lex)
    if lex==LparenWord : return ParenExpr(g) #parenthesized expression
    print('Expected factor, found')
    pio.Dump5(g);print()
    exit()