有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java什么是RuleContext类实现中的invokingState?

我在JavaParser中看到了规则索引。java,但还有另一个整数值,即调用状态。这个调用状态是否与getStartToken相关,或者与规则索引有什么不同


共 (1) 个答案

  1. # 1 楼答案

    调用状态是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. */

    下面是一个例子:

    enter image description here

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