Hi, 

 

I was wondering whether it is possible to get a list of expected
(possible) tokens at a NoViableAltException. 

Consider this small example grammar: 

 

grammar NoViableAltGrammar;

 

statement 

                :    statementA

                |   statementB

                ; 

                

statementA 

                :   ID Min ID Semi

                ;

                

statementB

                :   ID Plus ID Semi

                ;               

 

fragment

CHAR :  'a'..'z' ;

 

ID : CHAR+;

Semi :    ';'    ;

Plus:    '+'    ; 

Min :    '-'    ;          

Assign:    '='    ;  

 

WS:        (' '|'\t'|'\n'|'\r')+ {$channel=HIDDEN;}    ;

 

 

Starting with "statement"  and  this input:

 monkey = banana

 

I get a NoViableAlt  at token '=' . 

In a user error message I would like to tell that  "a  '-' or '+'  was
expected" .

The information is available in the generated parser code of the rule
statement, but as it seems, I cannot access this information through the
noViableAltException.

 

Best regards, 

 

Floor

 

 

 


CONFIDENTIALITY: This e-mail and any attachments are confidential and may be 
privileged. If you are not a named recipient, please notify the sender 
immediately and do not disclose the contents to another person, use it for any 
purpose or store or copy the information in any medium.




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

Reply via email to