Exemple #1
0
 def Start(self, nt, *kids):
     '''
     The production action for all productions in the grammar. The AST
     which is built is actually the same as the Parse Tree. Therefore,
     it is easy to have a generic action for all of the grammar rules.
     '''
     n = Node(nt.sym)
     for kid in kids:
         if isinstance(kid, Node): n.addkid(kid)
         elif kid is None: continue
         else: n.addkid(Node(kid.type).addkid(Node(kid.value)))
     return n
Exemple #2
0
    def __create(self, t):
        #print type(t), help(t)

        doc = self.__getattribute__(traceback.extract_stack()[-2][2]).__doc__
        name = doc.split(':', 1)[0].strip()
        node = Node(name)
        for i, x in enumerate(t[1:]):
            if isinstance(x, Node):
                node.addkid(x)
            else:
                node.addkid(t.get(i+1).type)
        return node