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 8133587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:39:34+00:00 2026-06-06T09:39:34+00:00

I am using ANTLR 3 , I have a question is that How can

  • 0

I am using ANTLR 3 , I have a question is that How can i find the next expected token if any error is occurred in input . I have tried to override getErrorMessage(RecognitionException e, String[] tokenNames) of the Parser, I can get the error but i am not able to get What is next expected token . If anyone can help .
Thanks in Advance.

  • 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-06-06T09:39:38+00:00Added an answer on June 6, 2026 at 9:39 am

    That’s not as easy as it sounds. And quite often, such information is not available.

    For example, your grammar can match parenthesized expressions like this: (1+2).

    If your parser now tries to parse "(1+2", a MismatchedTokenException would be thrown, whose expecting attribute would be the type of ')'. So, that’s an easy one.

    However, when it tries to parse "1+2)", a MismatchedTokenException would again be thrown, but now the parser would complain that it expects the EOF, because it expects to just parse an expression like 1+2. It will not tell you that somewhere in the “past”, you forgot an '('.

    So, there will only be a couple of occasions that will let you extract an expected token from an exception raised by the parser. In the bulk of the cases, you will need to do (a lot of hard) work to extract this info yourself. Creating meaningful error messages in your parser is not a trivial task! (at least, not compared to simply writing a grammar for a not too complicated language)

    I recommend going through ANTLR’s API docs to see which exceptions are being thrown by ANTLR and feed your parser invalid input by purpose, and overriding reportError(...) in your parser to see which exception gets thrown:

    @parser::members {
    
      @Override
      public void reportError(RecognitionException e) {
        // inspect 'e' and handle/report it
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to replace a token using ANTLR. I tried with TokenRewriteStream and replace,
I am using ANTLR to create lexer/parser. Expressions can have the format like this
By default, a parser generated using ANTLR-3 extends from org.antlr.runtime.Parser. How do I have
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
I'm using the antlr-3.4-complete-no-antlrv2.jar version of ANTLR on Eclipse Indigo. I have installed the
I currently have a working, simple language implemented in Java using ANTLR. What I
I have been successfully using my code with the javascript library in the ANTLR
I have the following language i wish to parse using antlr 1.2.2. TEST <name>
I'm using ANTLR 3 to create an AST. I want to have two AST
I am using ANTLR to create an and/or parser+evaluator. Expressions will have the format

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.