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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:05:22+00:00 2026-05-18T08:05:22+00:00

I’m a beginner using ANTLR. I’m just doing the following for test purposes and

  • 0

I’m a beginner using ANTLR. I’m just doing the following for test purposes and try to understand the way it works and produce errors:

INTEGER_NUMBER : ('0'..'9')+;
integer_number: INTEGER_NUMBER;
decimal_number: (integer_number '.' integer_number) | ('.' integer_number);
regular_number: decimal_number|integer_number;

I have the following warning on the “regular_number” rule : Decision can match input such as “INTEGER_NUMBER ‘.’ INTEGER_NUMBER” using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input.

What exactly does it means ?


Ok I have edited this post to include the code that reproduce this error

program :(price)*;

INTEGER_NUMBER : ('0'..'9')+;
INFO_PRICE : 'OLD PRICE';
FRACTION_NUMBER : '1/16'|'1/8'|'3/16'|'1/4'|'5/16'|'3/8'|'7/16'|'1/2'|'9/16'|'5/8'|'11/16'|'3/4'|'13/16'|'7/8'|'15/16';
CURRENCY : 'EUR'|'USD'|'GBP';

integer_number : INTEGER_NUMBER ;
decimal_number : (integer_number? '.') integer_number ;
fraction_number : (integer_number ((' ')+))? FRACTION_NUMBER;
regular_number : decimal_number|integer_number ;
numerical_number :regular_number|fraction_number;
non_numerical_number : INFO_PRICE ((' ')*) ('+'|'-') ((' ')*)(numerical_number)((' ')*) CURRENCY;

price : numerical_number |non_numerical_number;

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

and the error know is this one

error(201): /ANTLR – Tuto 1/src/Test.g:37:2: The following alternatives can never be matched: 2
|—> : decimal_number|integer_number ;

  • 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-18T08:05:23+00:00Added an answer on May 18, 2026 at 8:05 am

    As already mentioned in the comments, there’s nothing wrong with the grammar you posted.

    The error you mention occurs with the following grammar:

    grammar Test;
    
    regular_number
      :  decimal_number
      |  integer_number
      ;
    
    integer_number
      :  INTEGER_NUMBER
      ;
    
    decimal_number
      :  integer_number '.' integer_number
      |  '.' integer_number
      |  integer_number                      // <- I added this one
      ;
    
    INTEGER_NUMBER 
      :  '0'..'9'+ 
      ;
    

    When the parser tries to match a regular_number for the input string "123", it does not know which alternative to choose. Both decimal_number and integer_number match "123". Hence the error message:

    ... using multiple alternatives: 1, 2
    As a result, alternative(s) 2 were disabled for that input
    

    EDIT

    From within the regular_number rule, the string "123.456" could be parsed as:

    integer_number decimal_number
    123            .456
    

    or as:

    decimal_number
    123.456
    

    Why not define a DECIMAL_NUMBER in the lexer:

    DECIMAL_NUMBER
      :  INTEGER_NUMBER '.' INTEGER_NUMBER
      |  '.' INTEGER_NUMBER
      ;
    

    ?

    That should fix that problem.

    There are more issues though:

    numerical_number 
      :  fraction_number
      |  regular_number
      ;
    

    when the rule above tries to handle input like "2 1/8", the 2 from it could be a part of your fraction_number including the 1/8, but it could also be handled as a regular_number followed by a fraction_number.

    Also, you shouldn’t define spaces inside your parser rules, you’ve put them on the HIDDEN channel in the lexer, so they won’t be “seen” by the parser.

    Having said all that, this would be a possible alternative grammar that probably does what you want:

    program 
      :  price* EOF
      ;
    
    price 
      :  numerical_number 
      |  non_numerical_number
      ;
    
    numerical_number
      :  FRACTION_NUMBER
      |  DECIMAL_NUMBER
      |  INTEGER_NUMBER
      ;
    
    non_numerical_number 
      :  INFO_PRICE ('+' | '-') (INTEGER_NUMBER FRACTION_NUMBER | numerical_number) CURRENCY
      ;
    
    DECIMAL_NUMBER
      :  INTEGER_NUMBER '.' INTEGER_NUMBER
      |  '.' INTEGER_NUMBER
      ;
    
    FRACTION_NUMBER 
      :  '1/16' | '1/8' | '3/16' | '1/4' | '5/16' | '3/8' | '7/16' | '1/2' | 
         '9/16' | '5/8' | '11/16' | '3/4' | '13/16' | '7/8' | '15/16'
      ;
    
    INTEGER_NUMBER  
      :  '0'..'9'+
      ;
    
    INFO_PRICE
      : 'OLD PRICE'
      ;
    
    CURRENCY
      : 'EUR' | 'USD' | 'GBP'
      ;
    
    WS 
      :  (' ' | '\t' | '\f' | '\r' | '\n')+ {$channel=HIDDEN;}
      ;
    

    EDIT II

    Also, you shouldn’t define spaces inside your parser rules, you’ve
    put them on the HIDDEN channel in the lexer, so they won’t be “seen”
    by the parser.

    the thing being, how will the lexer make the difference
    beetween 1011 1/16 and 101 11/16 for example ?

    When encountering the (sub) string 1011 1/16, 1011 is tokenized as an INTEGER_NUMBER, the space is put on the HIDDEN channel (and is therefor not present in the token-stream that is being passed to the parser), and 1/16 is tokenized as a FRACTION_NUMBER.

    For 101 11/16 the same applies: 101 is a INTEGER_NUMBER and 11/16 a FRACTION_NUMBER.

    To emphasize: when you put spaces and line breaks on a different channel (like the HIDDEN channel), they are not present in the token stream that the parser operates on. So it makes no sense to use these tokens in parser rules: they’re never going to be matched.

    HTH

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into

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.