Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7624693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:01:48+00:00 2026-05-31T05:01:48+00:00

I tried error reporting in following manner. @members{ public String getErrorMessage(RecognitionException e,String[] tokenNames) {

  • 0

I tried error reporting in following manner.

@members{
    public String getErrorMessage(RecognitionException e,String[] tokenNames)
    {
        List stack=getRuleInvocationStack(e,this.getClass().getName());
        String msg=null;
        if(e instanceof NoViableAltException){
            <some code>
        }
        else{
            msg=super.getErrorMessage(e,tokenNames);
        }
        String[] inputLines = e.input.toString().split("\r\n");
        String line = "";
        if(e.token.getCharPositionInLine()==0)
            line =  "at \"" + inputLines[e.token.getLine() - 2];
        else if(e.token.getCharPositionInLine()>0)
            line =  "at \"" + inputLines[e.token.getLine() - 1];
        return ": " + msg.split("at")[0] + line + "\" => [" + stack.get(stack.size() - 1) + "]";
    }

    public String getTokenErrorDisplay(Token t){
        return t.toString();
    }
}

And now errors are displayed as follows.

line 6:7 : missing CLOSSB at "int a[6;" => [var_declaration]
line 8:0 : missing SEMICOL at "int p" => [var_declaration]
line 8:5 : missing CLOSB at "get(2;" => [call]

I have 2 questions.

1) Is there a proper way to do the same thing I have done?

2) I want to replace CLOSSB, SEMICOL, CLOSB etc. with their real symbols. How can I do that using the map in .g file?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:01:50+00:00Added an answer on May 31, 2026 at 5:01 am

    Bhathiya wrote:

    *1) Is there a proper way to do the same thing I have done?

    There is no single way to do this. Note that proper error-handling and reporting is tricky. Terence Parr spends a whole chapter on this in The Definitive ANTLR Reference (chapter 10). I recommend you get hold of a copy and read it.

    Bhathiya wrote:

    2) I want to replace CLOSSB, SEMICOL, CLOSB etc. with their real symbols. How can I do that using the map in .g file?

    You can’t. For SEMICOL this may seem easy to do, but how would you get this information for a token like FOO:

    FOO : (X | Y)+;
    
    fragment X : '4'..'6';
    fragment Y : 'a' | 'bc' | . ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Error I tried this page to run on local, it is running perfectly fine
I got this error when I tried to compile an application that includes the
I tried this: ALTER TABLE My.Table DROP MyField and got this error: -MyField is
I received the following error when I tried to run a C# WinForms application
IE8 is reporting an Unexpected Quantifier error, with the following JS function, which I
The following error comes up: C:\gem>gem install sqlite3-ruby --local Building native extensions. This could
I received a Too many open files error when tried to do fopen (C++,
I tried to show an error message using the jquery effect fadeTo and tried
Fatal error: Allowed memory size of 31457280 bytes exhausted (tried to allocate 9828 bytes).
I've tried the below script but I am getting an error: dim cn, rs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.