def Operation(t): s = exp.OperationSymbol(t) al = exp.OperationOperandL(t) n = pop.Length(al) if (n == 0): printf(" ") pio.WriteItem(exp.OperationSymbol(t)) printf(" ") return if (exp.PrefixP(s)): Prefix(t) return if (exp.InfixP(s)): Infix(t) return if (s == exp.LLISTPARENWord): printf("[% ") Termlist(al) printf(" %]") return if s == exp.LSETPARENWord: printf("{% ") Termlist(al) printf(" %}") return pio.WriteItem(exp.OperationSymbol(t)) printf("(") Termlist(al) printf(")")
def TermLprecedence(t): # the force with which term t binds from the left (to its right operands) */ if (exp.VarP(t) or exp.LiteralP(t)): return 100 if (exp.OperationP(t)): s = exp.OperationSymbol(t) if (exp.InfixP(s) or exp.PrefixP(s)): return exp.Lprecedence(exp.OperationSymbol(t)) return 100 return 100
def Complete(e,ig): # current item is an infix operator # return longest initial subexpression q = pio.NextItem(ig) # q is the infix operator f = Factor(ig) if f=='': if e == '': return Operation1C(q,unterm) return exp.Operation2C(q,e,exp.Unterm) while pio.CurrentItem(ig) != '' and exp.InfixP(pio.CurrentItem(ig)) and YieldsP(q,pio.CurrentItem(ig)): f = Complete(f,ig) if e == '': return exp.Operation1C(q,f) #if q == WVRWord or q==WHILEWord or q==SWVRWord: return exp.CallC(exp.VarC(q),exp.List2(e,f)) if q in definables: defined.add(q) return exp.CallC(exp.VarC(q),exp.List2(e,f)) return exp.Operation2C(q,e,f)
def Expr(ig): """Parse the next expression in item generator ig""" # leave ig pointing to following item or eod f = Factor(ig) #pickup lefthand factor if f=='': return '' #nothing there ci = pio.CurrentItem(ig) if ci=='': return f #nothing more to parse while pio.CurrentItem(ig)!='' and exp.InfixP(pio.CurrentItem(ig)): f=Complete(f,ig) w = pio.CurrentItem(ig) if w!= exp.WHEREWord and w != exp.WHERELOOPWord: return f if w == exp.WHEREWord: e1 = Where(f,ig) else: e1 = Whereloop(f,ig) return e1