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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:13:14+00:00 2026-06-14T02:13:14+00:00

I want to be able to parse int [] or int tokens. Consider the

  • 0

I want to be able to parse int [] or int tokens.

Consider the following grammar:

TYPE    :   'int' AFTERINT;
AFTERINT:   '[' ']';

Of course it works, but only for int []. To make it work for int too, I changed AFTERINT to this (added an empty condition’:

AFTERINT:   '[' ']' |
              |;

But now I get this warning and error:

[13:34:08] warning(200): MiniJava.g:5:9: Decision can match input
such as “” using multiple alternatives: 2, 3

As a result, alternative(s) 3 were disabled for that input [13:34:08]
error(201): MiniJava.g:5:9: The following alternatives can never be
matched: 3

Why won’t empty condition work?

  • 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-14T02:13:15+00:00Added an answer on June 14, 2026 at 2:13 am

    The lexer cannot cope with tokens that match empty string. If you think about it for a moment, this is not surprising: after all, there are an infinite amount of empty strings in your input. The lexer would always produce an empty string as a valid token, resulting in an infinite loop.

    The recognition of types does not belong in the lexer, but in the parser:

    type
     : (INT | DOUBLE | BOOLEAN | ID) (OBR CBR)?
     ;
    
    OBR     : '[';
    CBR     : ']';
    INT     : 'int';
    DOUBLE  : 'double';
    BOOLEAN : 'boolean';
    ID      : ('a'..'z' | 'A'..'Z')+;
    

    Whenever you start combining different type of characters to create a (single) token, it’s usually better to create a parser rule for this. Think of lexer rules (tokens) as the smallest building block of your language. From these building blocks, you compose parser rules.

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

Sidebar

Related Questions

I want to be able to parse the following times using ParseExact() function: 01:02:03
I am able to parse the HTML but I want to extract the warning
I want to be able to parse file paths like this one: /var/www/index.(htm|html|php|shtml) into
I want to be able to parse a string to an object that I
I want to be able to replicate only the folder structure (not the contents)
I want to be able to do the following actions with a form submit
I want to be able to parse a a six digit number and take
I want to be able to use a RegEx to parse out ranges like
My insert function already handles collisions correctly but i want to be able to
I'm using LaTeX and BibTeX for an article, and I want to able to

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.