`visitChildren()` 方法在 antlr4 中实际上做了什么?(Java)

huangapple go评论96阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年8月27日 01:16:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/63602641.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定