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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:47:45+00:00 2026-06-02T20:47:45+00:00

In ANTLR, I have a MismatchedTokenException with the following definition: type : IDENTIFIER (‘<‘

  • 0

In ANTLR, I have a MismatchedTokenException with the following definition:

type : IDENTIFIER ('<' (type (',' type)*) '>')?;

And the following test:

A<B,C<D>>

The exception occurs when parsing the first >. ANTLR tries parsing both ‘>>’ at once, and fails.

With a silent whitespace channel, the following test does work:

A<B,C<D> >

In which ANTLR is clearly instructed to treat each token separately.

How can I fix that?

  • 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-02T20:47:48+00:00Added an answer on June 2, 2026 at 8:47 pm

    I could not reproduce that. The parser generated by:

    grammar T;
    
    type       : IDENTIFIER ('<' (type (',' type)*) '>')?;
    IDENTIFIER : 'A'..'Z';
    

    parses the input A<B,C<D>> (without spaces) into the following parse tree:

    enter image description here

    You’ll need to provide the grammar that causes this input to produce a MismatchedTokenException.

    Perhaps you’re using ANTLRWorks’ interpreter (or Eclipse’s ANTLR-IDE, which uses the same interpreter)? In that case, that is probably the problem: it’s notoriously buggy. Don’t use it, but use ANTLRWorks’ debugger: it’s great (the image posted above comes from the debugger).

    Lazlo Bonin wrote:

    Got it. I had a << token defined. Quickly, is there a way to priorize token recognition over another?

    No, the lexer simply tries to match as much as possible. So if it can create a token matching << (or >>), it will do so in favor of two single < (or >) tokens. Only when two (or more) lexer rules match the same amount of characters, a prioritization is made: the rule defined first will then “win” over the one(s) defined later in the grammar.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following language i wish to parse using antlr 1.2.2. TEST <name>
I have started to learn ANTLR and have both the 2007 book The Definitive
I have the following Antlr grammar: grammar MyGrammar; doc : intro planet; intro :
If I have an ANTLR grammar as follows: grammar Test; options { language =
I have been tried to make my first Hibernate project. I added following libraries
I have the following ANTLR grammar which is given as an example by Terrence
I have looked at the following software tools: Ragel ANTLR BNF Converter Boost::Spirit Coco/R
I have the following production in my ANTLR grammar: rich_newick_string : str=(.*';') { stack.pushRichNewickString($str.text);
I have the following ANTLR grammar: grammar Tasks; options { language = Java; }
I have written an ANTLR 3 grammar for parsing TaskJuggler III bookings files (see

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.