All pastes #271591 Raw Edit

Anonymous

public python v1 · immutable
·published 2006-12-08 08:50 UTC
rendered paste body
>>> class CodeGeneratorVisitor(object):    @dispatch.on('node')    def visit(self, node):        """This is the generic method"""    @visit.when(ASTNode)    def visit(self, node):        map(self.visit, node.children)    @visit.when(EchoStatement)    def visit(self, node):        self.visit(node.children)        print "print"    @visit.when(BinaryExpression)    def visit(self, node):        map(self.visit, node.children)        print node.props['operator']    @visit.when(Constant)    def visit(self, node):        print "push %d" % node.props['value']>>> CodeGeneratingVisitor().visit(tree)push 1printpush 2push 4push 3multiplyplusprint