英文:
What does visitChildren() in antlr4 actually does ? (Java)
问题
visitChildren()
在antlr4(用于Java)中实际上是做什么的?这是基本访问者中针对所有内容的默认函数,它似乎做了很多我不太了解的事情。例如,它如何处理这些解析器规则?
a: b | c | d;
e: F g H;
i: j k l+;
m: N O P?;
你是否有其他示例来展示它的作用?
(Note: The code portions have been omitted as per your request.)
英文:
What does visitChildren()
in antlr4 (for Java) actually does ? It's the default function for everything in the base visitor and it seems to do a lot that I don't know. For example, what does it do with these parser rules?
1)
a: b | c | d;
2)
e: F g H;
3)
i: j k l+;
4)
m: N O P?;
And do you have other examples to show what it does ?
答案1
得分: 1
visitChildren
遍历给定节点的所有子节点,并为每个子节点触发 accept
方法。查看您生成的解析器以了解 accept
方法的作用。通常情况下,它调用链中下一个子节点的访问函数,或者通过再次调用 visitChildren
来访问其自己的子节点(从根本上说,效果是相同的,只是以一种更通用的方式)。请参阅类 AbstractParseTreeVisitor
,了解 visitChildren
的默认实现以及您可以重写以自定义访问者行为的其他方法。
英文:
visitChildren
iterates over all child nodes of a given node and triggeres the accept
method for each of them. Look in your generated parser to see what the accept
method does. Normally it calls the visit function of the next child in the chain or simply visits over its own children by calling again visitChildren
(which has basically the same effect, just in a more general way). See the class AbstractParseTreeVisitor
for the default implementation of visitChildren
and other methods you can override to customize the visitor behavior.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论