Example #1
0
File: util.py Project: nrc/N
def idClone(c, symbols):
    if isinstance(c, symbol.Id):
        return c
    if isinstance(c, symbol.Id):
        ast = ast.Ast(ast.ID)
        ast.val = c.name
        ast.mod = ""
        result = symbol.Id(ast, c)
        return result
    if isinstance(c, symbol.Case):
        result = symbol.Seq(None)
        result.case = c
        result.caseMatch = result.isSuperType(c.type(symbols), symbols)
        for s in c.syntax:
            result.syntax.append(idClone(s, symbols))
        return result
    if isinstance(c, symbol.Seq):
        result = symbol.Seq(None)
        result.case = c.case
        result.caseMatch = c.caseMatch
        for s in c.syntax:
            result.syntax.append(idClone(s, symbols))
        return result
    if isinstance(c, symbol.List):
        result = symbol.List(None)
        result.arg = idClone(c.arg, symbols)
        return result

    return c
Example #2
0
File: env.py Project: nrc/N
    def canJudge(self, defn, nt, envs, args):
        #make the key and close it
        key = symbol.Seq(None)
        key.syntax = envs + args
        ke = [key]
        self.envClosure(ke)
        #check if we have the key and for the right defn and nt
        for k in ke:
            if k in self and self[k]:
                for c in self[k]:
                    if c.nt == nt and c.defn == defn:
                        return True

        return False
Example #3
0
File: env.py Project: nrc/N
 def freshOld(self, clone):
     if not util.interestingRoot(clone):
         return clone
     if isinstance(clone, symbol.Id):
         result = symbol.FreshId(clone.symbol, self.getFreshNum(clone.name))
         result.name = clone.name
         return result
     elif isinstance(clone, symbol.List):
         result = symbol.List(None)
         result.arg = self.freshOld(clone.arg)
         return result
     elif isinstance(clone, symbol.Symbol):
         return symbol.FreshId(clone, self.getFreshNum(clone.shortString()))
     elif isinstance(clone, symbol.Seq):
         result = symbol.Seq(None)
         result.syntax = map(lambda x: self.freshOld(x), clone.syntax)
         return result
     else:
         print "Error: can't clone " + str(clone)
         return symbol.ErrSym()
Example #4
0
File: util.py Project: nrc/N
def rename(s, old, new):
    if isinstance(s, symbol.Id):
        if s == old:
            return new
        else:
            return s
    elif isinstance(s, symbol.List):
        if isinstance(old, symbol.List):
            result = symbol.List(None)
            result.arg = rename(s.arg, old.arg, new.arg)
            result.repr = s.repr
            return result
        else:
            return s
    elif isinstance(s, symbol.Seq):
        result = symbol.Seq(None)
        result.syntax = map(lambda x: rename(x, old, new), s.syntax)
        result.repr = s.repr
        return result

    print "Internal error, could not handle " + str(s) + " in rename."
    return s
Example #5
0
File: env.py Project: nrc/N
    def fresh(self, clone, listDepth=0):
        if not util.interestingRoot(clone):
            return clone
        if isinstance(clone, symbol.Id):
            result = symbol.Id(None, clone.symbol)
            result.name = clone.name
            result = self.makeFresh(result, listDepth)
        elif isinstance(clone, symbol.Symbol):
            result = self.makeFresh(symbol.Id(None, clone), listDepth)
        elif isinstance(clone, symbol.List):
            result = symbol.List(None)
            result.arg = self.fresh(clone.arg, listDepth + 1)
        elif isinstance(clone, symbol.Seq):
            result = symbol.Seq(None)
            result.syntax = map(lambda x: self.fresh(x, listDepth),
                                clone.syntax)
        else:
            print "Error: can't clone " + str(clone)
            return symbol.ErrSym()

        if listDepth == 0:
            self.regVars.add(result)
        return result
Example #6
0
File: env.py Project: nrc/N
 def makeSeq(x):
     result = symbol.Seq(None)
     result.syntax = x
     return result