def AssembleStrict(o, opds): n = len(opds) if n == 2: return (pio.Popliteral('[vpop0 "%s eval "%s eval %s]' % (opds[0], opds[1], o))) if n == 1: return pio.Popliteral('[vpop0 "%s eval %s]' % (opds[0], o)) if n == 0: return pio.Popliteral('[vpop0 %s]' % o) code = '[vpop0 ' for opd in opds: code = code + ' "%s eval ' % opd code = code + ('%s %s]' % (str(n), o)) #print(code);exit() return pio.Popliteral(code)
def AssembleActual(opds): s = '' for opd in opds: s = s + ' ' + opd return pio.Popliteral( '[ savevar setvar waresearch [restorevar] breakc [ %s] saveplace popplace select eval restoreplace waresave restorevar ]' % s)
def Reserve(l): s = set() while not pop.EmptyP(l): s.add(pop.Head(l)) l = pop.Tail(l) return s LparenWord = pop.WordC("(") RparenWord = pop.WordC(')') CommaWord = pop.WordC(',') WVRWord = pop.WordC("wvr") UPNWord = pop.WordC("upn") SWVRWord = pop.WordC("swvr") WHILEWord = pop.WordC("while") INTERMWord = pop.WordC("interm") reservedwords = Reserve(pio.Popliteral("[if then else fi where whereloop end valof]")) definables = {WVRWord,SWVRWord,WHILEWord,UPNWord} #binary ops that have definitions as udfs funstants = {pop.FBY2Word,pop.ATTIME2Word,pop.APPLYWord} #operation constants called like functions eg fby2(a,b1,b2) defined = set() #definables that were actually encountered def ParseFile(fname): f = open(fname,"r") sourceprog = f.read() f.close() ig = pio.ItemGenStringC(sourceprog) return Expr(ig) if __name__ == "__main__": prog = '' while True:
def Reserve(l): s = set() while not EmptyP(l): s.add(Head(l)) l = Tail(l) return s lpd = {} rpd = {} prefixes =set() infixes = set() postfixes = set() nullfixes = set() reservedwords = Reserve(pio.Popliteral("[if then else fi where whereloop end valof]")) NewFixes(pio.Popliteral("[[100 sin 65][100 cos 65][100 tan 65][100 exp 65][100 abs 44][100 log 65][100 log2 65][100 sqrt 65][100 pi 100][100 phi 100]]")) NewFixes(pio.Popliteral("[[100 tl 65][100 not 65][100 isatom 65][100 islist 65][100 isnumber 65][100 isnil 65][100 iseod 65][100 isstring 65][100 isword 65][100 iserror 65]]")); NewFixes(pio.Popliteral("[[100 first 65][100 First 65][100 init 65][100 id 65][100 current 65][100 succ 65][100 # 65][100 $ 65][100 next 65][100 Next 65][100 pre 65][100 contemp 65][100 active 65][10 fby 9][100 Fby 65][10 sby 9][10 & 9][9 ybf 10][10 wvr 11][10 while 11][10 swvr 11][10 asa 11][10 attime 11][10 atspace 11]]")) NewFixes(pio.Popliteral("[[20 :: 19][25 or 24][30 and 29][40 <> 39][40 < 39][40 <= 39][40 eq 39][40 ne 39][40 >= 39][40 > 39][45 - 44][45 + 44][50 * 49][50 / 49][50 div 49][50 mod 49][55 ** 54][55 ^ 54][100 hd 65][100 input 100][100 index 100][100 sindex 100][100 eod 100][100 eos 100][100 true 100][100 false 100]]")); opsymbols = prefixes.union(infixes).union(prefixes).union(postfixes).union(nullfixes) opsymbols.add(YCALLWord) opsymbols.add(IFWord) opsymbols.add(LLISTPARENWord) opsymbols.add(ACTUALWord) opsymbols.add(GLOBALWord) opsymbols.add(EODWord) opsymbols.add(EOSWord)
def AssembleOr(opds): return pio.Popliteral('[vpop0 "%s eval ["true] breakc "%s eval ]' % (opds[0], opds[1]))
def AssembleSindex(): return pio.Popliteral('[vpop0 space]')
def AssembleAnd(opds): return pio.Popliteral('[vpop0 "%s eval not ["false] breakc "%s eval ]' % (opds[0], opds[1]))
def AssembleIf(opds): return pio.Popliteral( '[ savevar setvar waresearch [restorevar] breakc ["%s eval]["%s eval]"%s eval if waresave restorevar ]' % (opds[1], opds[2], opds[0]))
def AssembleIndex(): return pio.Popliteral('[vpop0 time]')
def AssembleAtspace(opds): return pio.Popliteral( '[ savevar setvar waresearch [restorevar] breakc "%s eval savespace setspace "%s eval restorespace waresave restorevar ]' % (opds[1], opds[0]))
def AssembleYcall(opds): return pio.Popliteral( '[ savevar setvar waresearch [restorevar] breakc "%s eval pushplace "%s eval popplace vpop0 waresave restorevar]' % (opds[1], opds[0]))
def AssembleInit(opds): return pio.Popliteral( '[ vpop0 savespace 0 setspace "%s eval restorespace ]' % opds[0])
def AssembleFirst(opds): return pio.Popliteral('[ vpop0 savetime 0 settime "%s eval restoretime ]' % opds[0])
def AssembleSby(opds): return pio.Popliteral( '[ savevar setvar waresearch [restorevar] breakc ["%s eval] [decspace "%s eval incspace] space 0 eq if waresave restorevar]' % (opds[0], opds[1]))
def AssembleSucc(opds): return pio.Popliteral('[ vpop0 incspace "%s eval decspace ]' % opds[0])
def AssembleNext(opds): return pio.Popliteral('[ vpop0 inctime "%s eval dectime ]' % opds[0])