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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:47:37+00:00 2026-06-16T05:47:37+00:00

After the problem about AST rewrite rule with devide group technique at AST rewrite

  • 0

After the problem about AST rewrite rule with devide group technique at AST rewrite rule with " * +" in antlr.

I have a trouble with AST generating in ANTLR, again :).Here is my antlr code :

start   :   noun1+=n (prep noun2+=n (COMMA noun3+=n)*)*
        ->  ^(NOUN $noun1) (^(PREP prep) ^(NOUN $noun2) ^(NOUN $noun3)*)*
    ;
n       :    'noun1'|'noun2'|'noun3'|'noun4'|'noun5';
prep    :    'and'|'in';
COMMA   :     ',';

Now, with input : “noun1 and noun2, noun3 in noun4, noun5”, i got following unexpected AST:

enter image description here

Compare with the “Parse Tree” in ANLRwork:

enter image description here

I think the $noun3 variable holding the list of all “n” in “COMMA noun3+=n”. Consequently, AST parser ^(NOUN $noun3)* will draw all “n” without sperating which “n” actually belongs to the “prep”s.

Are there any way that can make the sepration in “(^(PREP prep) ^(NOUN $noun2) ^(NOUN $noun3))“. All I want to do is AST must draw exactly, without token COMMA, with “Parse Tree” in ANTLRwork.

Thanks for help !

  • 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-16T05:47:38+00:00Added an answer on June 16, 2026 at 5:47 am

    Getting the separation that you want is easiest if you break up the start rule. Here’s an example (without writing COMMAs to the AST):

    start   :   prepphrase             //one prepphrase is required.
                (COMMA! prepphrase)*   //"COMMA!" means "match a COMMA but don't write it to the AST"
            ;
    
    prepphrase: noun1=n                //You can use "noun1=n" instead of "noun1+=n" when you're only using it to store one value
                (prep noun2=n)? 
                -> ^(NOUN $noun1) ^(PREP prep)? ^(NOUN $noun2)?
            ;
    

    A prepphrase is a noun that may be followed by a preposition with another noun. The start rule looks for comma-separated prepphrases.

    The output appears like the parse tree image, but without the commas.


    If you prefer explicitly writing out ASTs with -> or if you don’t like syntax like COMMA!, you can write the start rule like this instead. The two different forms are functionally equivalent.

    start   :   prepphrase             //one prepphrase is required.
                (COMMA prepphrase)*
                -> prepphrase+         //write each prepphrase, which doesn't include commas
            ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem about group in cluster analysis(hierarchical cluster). As example, this is the
After reading about the problem of passing empty std::string objects between DLLs and EXEs,
UPDATE: After searching a bit I don't seem to be alone about this problem:
I seem to stumble on problem after problem giving my entities behaviour. I have
I have a problem after i setup windows 7 all old projects in c#
I have odd problem: After starting server I got this error: undefined local variable
I have this problem: After instantiating this Window, open all nested expanders on the
Let me explain about my problem: I have a wpf form with few controls.
Hi I'm wondering how I can go about this problem I have a DB
I'm running into problem about redirect stdout of multi process. Assuming I have process

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.