RuleContext class 实现中的 invokingState 是什么?

What is invokingState in RuleContext class implementations?

我在 JavaParser.java 中看到规则索引,但还有另一个整数值,即调用状态。这个调用状态是和getStartToken相关的还是和规则索引有什么区别?

调用状态是用于到达由该规则上下文表示的规则的 ATN 状态。 comment in the source code 很好地解释了这一点:

/** What state invoked the rule associated with this context? * The "return address" is the followState of invokingState * If parent is null, this should be -1 this context object represents * the start rule. */

这是一个例子:

这是规则 start: e EOF; 的 ATN,其中 e 表示子规则。状态 4 是 e 的调用状态,状态 5 是 return(或跟随)状态。请记住,可以从许多地方调用规则,因此您不能使用从规则结束状态到 return 再到调用规则的转换(因此需要 followState 成员)。 return 状态存储在 rule transition 中,从调用状态(本例中的状态 4)到规则开始状态 e