1

I see the Rule Indexes in JavaParser.java, but there is another integer value i.e. invoking state. Is this invoking state related to the getStartToken or how is it different from rule indexes?

1 Answers1

2

The invoking state is the ATN state which was used to reach the rule which is represented by that rule context. The comment in the source code explains this pretty well:

/** 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. */

Here's an example:

enter image description here

This is the ATN for the rule start: e EOF; where e represents a subrule. State 4 is the invoking state for e and 5 is the return (or follow) state. Keep in mind a rule can be invoked from many places, hence you cannot use the transitions from the rule end state to return to the calling rule (hence the need for a followState member). That return state is stored in the rule transition that goes out from the invocation state (state 4 in this example) to the rule start state of e.

Mike Lischke
  • 48,925
  • 16
  • 119
  • 181