[antlr-interest] How to get a list of all valid options for the next token?

Niemeijer, R.A. r.a.niemeijer at tue.nl
Tue Aug 12 02:56:41 PDT 2008


Hello everyone,

 

I'm making a program where users construct short sentences by combining
puzzle pieces. This series of puzzle pieces is then converted to text
and parsed by Antlr. Currently the user has access to all the different
pieces at any point in the sentence, even if the grammar would not be
able to parse this. I want to disable all the pieces that cannot come at
that point in the sentence.

My idea was to do this with the help of the exceptions the parser
generates. For example, when it throws a MismatchedTokenException I can
find the expected token through the Expecting property of the exception.
Unfortunately this only works when there's only one possibility. When
there are multiple it instead throws a NoViableAltException or a
MismatchedSetException. I haven't been able to find a list of valid
following tokens in their properties.

 

Can anyone tell me if there is any way of determining the list of valid
tokens after the current token in the sentence?

 

Thanks in advance.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080812/75342f6f/attachment.html 


More information about the antlr-interest mailing list