Example #1
0
 def let(self, ast):
     if isinstance(ast.c, pi.Cmd):
         return pi.Blk(ast.d, ast.c)
     elif isinstance(ast.c, list):
         cmd = ast.c[0]
         for i in range(1, len(ast.c)):
             cmd = pi.CSeq(cmd, ast.c[i])
         return pi.Blk(ast.d, cmd)
Example #2
0
 def blk(self, ast):
     if ast.ds:
         if ast.cs:
             return self.__blk(ast.ds, ast.cs)
         else:
             return self.__blk(ast.ds, pi.Nop())
     else:
         if ast.cs:
             return pi.Blk(ast.cs)
         else:
             return pi.Blk(pi.Nop())
 def __blk(self, ds, cs):
     if isinstance(ds, pi.Bind):
         return pi.Blk(ds, cs)
     elif isinstance(ds, pi.DSeq):
         return self.__blk_aux(ds.operands(), cs)
     else:
         raise Exception("Block parse error: " + str(ds) + " "  + str(cs) + ".")
Example #4
0
 def __makeAbs(self, f, c):
     assert (isinstance(f, list))
     if isinstance(c, pi.Blk):
         body = c
     else:
         body = pi.Blk(c)
     if f == []:
         return pi.Abs(pi.Formals(), body)
     else:
         formals = [e for e in f if e != ',']
         return pi.Abs(formals, body)
Example #5
0
 def __makeAbs(self, f, c):
     assert (isinstance(f, list))
     if isinstance(c, pi.Blk):
         body = c
     else:
         body = pi.Blk(c)
     if f == []:
         return pi.Abs(pi.Formals(), body)
     else:
         # Tatsu roduces list of identifiers and commas from
         # formals = ','%{ identifiers }
         formals = [e for e in f if e != ',']
         return pi.Abs(formals, body)
Example #6
0
    def __makeAbs(self, f, c):
        if isinstance(c, pi.Blk):
            body = c
        else:
            body = pi.Blk(c)

        if f == []:
            return pi.Abs(pi.Formals(), body)
        else:
            formals = []
            for k, v in f.items():
                if not v == None:
                    formals.append(v)
            return pi.Abs(formals, body)
Example #7
0
 def let(self, ast):
     return pi.Blk(ast.ds, ast.c)
Example #8
0
 def __blk_aux(self, ds, cs):
     if len(ds) > 1:
         return pi.Blk(ds[0], self.__blk_aux(ds[1:], cs))
     else:
         return pi.Blk(ds[0], cs)
Example #9
0
 def start(self, ast):
     decs = ast.ds.copy()
     blk = pi.Blk(decs.pop(), ast.cs)
     for d in reversed(decs):
         blk = pi.Blk(d, blk)
     return blk