[antlr-interest] how to call the getErrorMessage method

Adam Connelly adam.rpconnelly at googlemail.com
Sat Apr 26 13:59:55 PDT 2008


The tokenNames array is stored in your generated parser as
public static string[] tokenNames = ...;

So if your parser class is called MyParser, you can do

MyParser parser = new MyParser();
parser.getErrorMessage(e, MyParser.tokenNames);

Or something like that.

Adam

2008/4/26 jabon <elekis at gmail.com>:

> hi all,
> always try to get error from the parser, I overided the reporterror like
> that
>
>
>    public void reportError (RecognitionException re){
>             throw new RuntimeException("Bailing out!",re);
>        }
>
>   other way, I have the follow catch
>
> catch(RuntimeException e){
>           System.err.println("runtimeException ERROR:\n");
>           System.exit(1);
>       }
>
> after a little research, I found that I have to override the followed
> méthod
> but how to call this method , I havent the tokenName.
>
> thanks
>
> a++
>
>        public String getErrorMessage(RecognitionException e,String[]
> tokenNames)
>   {
>       List stack = getRuleInvocationStack(e, this.getClass().getName());
>       String msg = null;
>       if ( e instanceof NoViableAltException ) {
>           NoViableAltException nvae = (NoViableAltException)e;
>           msg = " no viable alt; token="+e.token+
>           " (decision="+nvae.decisionNumber+
>           " state "+nvae.stateNumber+")"+
>           " decision=<<"+nvae.grammarDecisionDescription+">>";
>       }
>       else     {
>           msg = super.getErrorMessage(e, tokenNames);
>           }
>       return stack+" "+msg;
>   }
>     public String getTokenErrorDisplay(Token t) {
>       return t.toString();
>   }
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080426/b7bcf159/attachment.html 


More information about the antlr-interest mailing list