Antlr4, How to find the Index of a child node in the Token Stream??

20 views
Skip to first unread message

Ravi Shekhar

unread,
Jun 25, 2018, 7:36:48 AM6/25/18
to antlr-discussion
  I was trying to make a Control Flow Graph in ANTLR4 for Java. For a conditional statement e.g IF-Else, I am able to find out the Start and Stop Indexes:


int startIndex = ctx.start.getStartIndex();
int stopIndex = ctx.stop.getStopIndex();

  It does tell me the index from where the block starts and ends. However, I cannot do the same for its children, e.g. these are the children of an If-Else statement:


if
(x==5)
{System.out.println("one");}
else
{System.out.println("other one");}

How can I know the Index of "else", there is no getStartIndex() or it's equivalent

Reply all
Reply to author
Forward
0 new messages