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

Terence Parr parrt at cs.usfca.edu
Fri Aug 15 11:46:58 PDT 2008


On Aug 15, 2008, at 2:28 AM, Niemeijer, R.A. wrote:

> Right, I think I've localized all the data I need. All you need is a  
> bit of reflection. All the bitsets that determine the possible next  
> tokens are called FOLLOW_{0}_in_{1}{2}, where {0} is the previous  
> token (can be gotten from the Parser's state.following variable),  
> {1} is the name of the method the NoViableAltException is generated  
> in (use something like MethodBase.GetCurrentMethod().Name) and {2}  
> is un unimportant 3-digit number. So get the list of all Bitsets of  
> the Parser via reflection and choose the one that starts with  
> FOLLOW_{0}_in_{1}.
>
> However, in order to be able to use this I have to insert this code  
> at the point the NoViableAltException is thrown so I can dump the  
> list of tokens in its grammarDecisionDescription field. That means  
> overriding all the bits of code that look like this:
>
> NoViableAltException nvae_d1s2 =
>    new NoViableAltException("", 1, 2, input);
>
>    throw nvae_d1s2;
>
> Now obviously this can be done manually, but then you'd lose it  
> after every grammar generation. So my question: is there a way to  
> override this part of the generated grammar?

Set @rulecatch {...} to output the list or manually add a catch in  
each rule. would that work?

Ter



More information about the antlr-interest mailing list