CAP/TP03/tree/MyTreeVisitor.py
2024-09-30 14:32:46 +02:00

20 lines
486 B
Python

from TreeParser import TreeParser
from TreeVisitor import TreeVisitor
class MyTreeVisitor(TreeVisitor):
def visitTop(self, ctx:TreeParser.TopContext):
return self.visit(ctx.int_tree())
def visitLeaf(self, ctx:TreeParser.LeafContext):
return True
def visitNode(self, ctx:TreeParser.NodeContext):
return (
len(ctx.int_tree()) == 2
and all([self.visit(it) for it in ctx.int_tree()])
)
del TreeVisitor
del TreeParser