[antlr-interest] next possible tokens

Kirill Tchimerine zaebis at telus.net
Mon Jan 17 18:50:50 PST 2011


Folks,
 
I have been struggling with trying to get a list of next possible tokens for
a bit now and may use some help.
 
A page here
http://www.antlr.org/wiki/pages/viewpage.action?pageId=11567208
 
talks about how to retrieve a list of possible options but it doesnt seem to
cover all bases so to speak. According to my observations ANTLR has two
places where next tokens can be obtained (Match function whose parameter
indicates next options and PushFollow that preceeds rule invocation and
places possibilities in a state follow stack). Also a rule may have optional
token (TOKEN1 TOKEN2* for example)  in which case TOKEN2 may or may not be
present but no mismatch errors are triggered. ANTLR however knows that
TOKEN2 may be expected.
 
Another case is when predicates are used in a rule. Only 1 alternative is
possible given rule semantics but all possible rule starts are reported as
expected tokens in push follow stack.
 
So what is the best strategy to get a list of next expected tokens that is
a/ generic (so I dont have to weave code all over parser to make it happen)
and b/ reliable (gives me next expected possible tokens only)
 
Rgds.
!!!
 


More information about the antlr-interest mailing list