Esempio n. 1
0
def ItemRead(g): 
    """read the next item from character generator g returning it and leaving g starting at the first unused char"""
    skipwhites(g)
    ch = CurrentChar(g)
    if ch == '': #end of input
        return '' #eod
    
    if ch=='[' and LookChar(g) == '%': #list builder open word
        NextChar(g);NextChar(g)
        return pop.WordC('[%')
    if ch=='%' and LookChar(g) == ']':
        NextChar(g);NextChar(g)
        return pop.WordC('%]')
    if ch=='{' and LookChar(g) == '%': #set builder open word
        NextChar(g);NextChar(g)
        return pop.WordC('{%')
    if ch=='%' and LookChar(g) == '}':
        NextChar(g);NextChar(g)
        return pop.WordC('%}')
        
    if ch in '~'+digits: return NumRead(g)           #should be a number
    if ch in letters: return IdentRead(g)            #should be an identifier word
    if ch in signchars: return SignRead(g)           #should be a sign word
    if ch in punctuations: return PunctuationRead(g) #should be a punctuation word
    if ch == "'": return StringRead(g)               #a string
    if ch == '[': return ListRead(g)  
    if ch == '{': return  SetRead(g)             #a set
    assert False, 'unexpected character:'+ch
Esempio n. 2
0
def SignRead(g):
    sign = '' 
    while CurrentChar(g) != '':
        if CurrentChar(g) not in signchars:
            break
        sign = sign + NextChar(g)
    return pop.WordC(sign)
Esempio n. 3
0
def IdentRead(g):
    ident = ''
    while CurrentChar(g) != '':
        if CurrentChar(g) not in letters+digits+'_':
            break
        ident = ident + NextChar(g)
    return pop.WordC(ident)
Esempio n. 4
0
def NewVar(v):
    global varcount
    ok, n = map.Apply(varcount, v)
    if not ok:
        map.Extend(varcount, v, 0)
        n = 0
    suffix = str(n)
    varcount = map.MapS(varcount, v, n + 1)
    if n != 0:
        rvname = pop.WordName(v) + '_' + suffix
    else:
        rvname = pop.WordName(v)
    return pop.WordC(rvname)
Esempio n. 5
0
import pio, prp, exp, gen, prs, atz, pop, pre, ali, ari, map, ren, glb, ewh, sys, asm, clc, elp
from clc import *
import profile

codetable = {}
head = {}
tail = {}
warehouse = {}
Pempty = 0
fetchedvars = set()

newcode = 0
vreg = pop.WordC("error")
treg = 0  #t0
htreg = []  #t1 t2 t3 etc
sreg = 0
preg = Pempty
evalcount = 0
actcount = 0
evaldepth = 0
wsaves = 0
wfinds = 0
nextindex = 0
endoffile = False
ig = pio.ItemGenStringC('')


def Pcons(i, t):
    """ the hashcons (code) for the place code with head i and tail code t """
    global newcode
    if (i, t) in codetable: return codetable[(i, t)]
Esempio n. 6
0
    if e==exp.Unterm: return exp.Unterm
    if Expect(RparenWord,g): return e
    return Interm(e)
 
def Interm(t):
    """ t wrapped up as an incomplete (unfinished) term"""
    return pop.List2(INTERMWord,t)
    
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()
Esempio n. 7
0
import pop

OPWord = pop.WordC('op')
VARWord = pop.WordC('var')
QUOTEWord = pop.WordC('"')
IFWord = pop.WordC("if")
THENWord = pop.WordC("then")
ELSEWord = pop.WordC("else")
FIWord = pop.WordC("fi")
CALLWord = pop.WordC("call")
YCALLWord = pop.WordC("ycall")
ACTUALWord = pop.WordC("actual")
GLOBALWord = pop.WordC("global")
WHEREWord = pop.WordC("where")
ENDWord = pop.WordC("end")
EQUALWord = pop.WordC("=")
SEMICOLONWord = pop.WordC(";")
VALOFWord = pop.WordC("valof")
LLISTPARENWord = pop.WordC("[%")
RLISTPARENWord = pop.WordC("%]")
LSETPARENWord = pop.WordC("{%")
RSETPARENWord = pop.WordC("%}")
OUTPUTWord = pop.WordC("output")
IDWord = pop.WordC("id")
EODWord = pop.WordC("eod")

TRUEWord = pop.WordC('true')
FALSEWord = pop.WordC('false')
Esempio n. 8
0
def PunctuationRead(g):
    return pop.WordC(NextChar(g))
Esempio n. 9
0
def AssembleLiteral(opds):
    return pop.List3(pop.WordC("vpop0"), pop.QUOTEWord, opds)
Esempio n. 10
0
def VarGen():
    global varcount
    s = str(varcount+100)
    varcount = varcount+1
    var = 'V'+s[1:]
    return exp.VarC(pop.WordC(var))