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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:25:36+00:00 2026-06-15T19:25:36+00:00

I just met a something headache .. I try to split statement into different

  • 0

I just met a something headache ..

I try to split statement into different functions ,like i have an example statement

start
 n turnTo 's'.
 n terminate.
end

both of statement start with ‘n’ , currently I am writing

statement 
    :
    (turnTo_statment|terminate_statment)*
    ;

turnTo_statment
    :
    variable 'turnTo' '\'' value '\'' '.'
    ;

terminate_statment
    :
    variable 'terminate' '.'
    ;

but when lexer running , it cannot determined which one is which because both of the substatemts are start with same thing ‘n’, compiler have alternative choice to use the rules . if next string is not matching the first rule compiler uses then it will automatically throw a no matching error .

how can I identify and told ANTLR if i met ‘x turnTo y’ then use the rule turnTo_statment , if i met ‘x terminated .’ then use the rule terminate_statment..

i.e. is there any function in antlr do this..

statement 
    :
    ((if statement contain_keywords 'turnTO') -> turnTo_statment
    |
    (if statement contain_keywords 'terminate') ->terminate_statment)*
    ;

thanks..

  • 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-15T19:25:37+00:00Added an answer on June 15, 2026 at 7:25 pm

    First, don’t use ‘literals’ in your parser rules. Without a lot of experience in ANTLR, this will get you in to trouble. Create real lexer rules:

    TURNTO: 'turnTo';
    

    Now, you probably need to read through the tutorials on the ANTLR wiki and study the downloadable examples and make sure you understand them. Writing good grammars seems easy because the grammar language is trivial to learn, but in fact it requires quite a lot of knowledge. The first thing to realize though, is that the lexer has no knowledge of the parser – it merely tokenizes the input stream and passes those tokens to the parser – so the lexer patterns cannot be ambiguous – the parser rules can deal with potential differences.

    ANTLR can probably handle your grammar without transforming it to LL(1) as ANTLR can handle LL(k) and usually works out what k is without your help. Is this your entire grammar? However, it is always best to left factor anyway:

    statement: var ( TURNTO {etc} | TERMINATE DOT )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just a knowledge question which I would like to ask: For example, I have
I have a table with something like a dozen different columns. Is there a
I'm applying UnitTest just for a while, and today I met something very strange.
I'm trying to repeat an animation until a certain condition is met. Something like
I just met something really strange of Python: >>> out=[[0]*3]*3 >>> out [[0, 0,
Just checking my JS and I have an error, but I cannot see where.
Just learning the world of jquery, and all my googling gives examples like this:
I have a requirement in my application that I think can be met by
Let me start here. At w3cshools.com - http://www.w3schools.com/jsref/met_win_setinterval.asp - they have a snippet demo-ing
I have code like this, and I find it a bit hard to read:

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.