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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:02:39+00:00 2026-06-14T01:02:39+00:00

Consider the following simplified grammar: ID : (‘a’..’z’) (‘a’..’z’)*; TYPE : ‘int’ ‘[‘ ‘]’

  • 0

Consider the following simplified grammar:

ID  :   ('a'..'z') ('a'..'z')*;

TYPE    :   'int' '[' ']' |
        'boolean' |
        'int';

Now if I write boolean as input, it can be parsed as ID or as TYPE. I want it to be parsed as TYPE – how?

  • 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-14T01:02:40+00:00Added an answer on June 14, 2026 at 1:02 am

    Put TYPE before ID:

    TYPE : 'int' '[' ']' 
         | 'boolean' 
         | 'int'
         ;
    
    ID   : ('a'..'z') ('a'..'z')*
         ;
    

    ANTLR’s lexer rules work like this:

    1. match as much as possible
    2. if after rule #1, two or more rules match the same amount of characters, pick the rule defined first in the grammar

    Because of these rules, "boolean" is tokenized as TYPE, while "booleans" would be tokenized as ID 1


    1 "booleans" is not tokenized as two tokens: TYPE ("boolean") and an ID ("s"))

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

Sidebar

Related Questions

Consider the following simplified objects and relationships: public class Job{ int JobId; String name;
Consider the following (simplified) situation: class Foo { private: int evenA; int evenB; int
consider the following simplified example: public class Ticket { public int Id; public TicketState
Consider the following very simplified example. <n></n> <k></k> <m></m> <k></k> How can I search
Consider the following simplified demonstration: Class X contain Class Y . Class Y has
Let's consider following, simplified example: We have 2 tabs withing <rich:tabPanel switchType=ajax> , each
Consider the following two Java files that contain a simplified version of my issue
Consider following code: My problem is: 1) I can't seem to cast the errors
Consider following string Some string with quotes and \pre-slashed\ quotes Using regex, I want
Consider the following simplified version of my code. I have a template class A

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.