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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:24:56+00:00 2026-06-07T05:24:56+00:00

I am printing out the type field and text field from an AST tree

  • 0

I am printing out the type field and text field from an AST tree based on my grammar and I get this

type=5 text=and
    type=14 text==
        type=4 text=ALIAS
            type=20 text=a
        type=7 text=ATTR_NAME
            type=20 text=column_b
        type=36 text=STR_VAL
            type=35 text="asdfds"
    type=14 text==
        type=4 text=ALIAS
            type=20 text=a
        type=7 text=ATTR_NAME
            type=20 text=yyyy
        type=12 text=DEC_VAL
            type=11 text=564.555

Valid type ints in my generated lexer are

public static final int EOF=-1;
public static final int ALIAS=4;
public static final int AND=5;
public static final int ATTR_NAME=7;
public static final int DECIMAL=11;
public static final int DEC_VAL=12;
public static final int EQ=14;
public static final int ID=20;
public static final int STR_VAL=36;

I would very much like to NOT have type=20 ever in the tree!!! and instead move the nodes with type 20 up one level so text would be the information(not the token name) and the type would be 4,7, or ALIAS or ATTR_NAME types. Is there a way to do this?

This part of my current grammar is using imaginary tokens ATTR_NAME and ALIAS right now like so(comment if I need to put more of my grammar up but I think this is enough to solve it)

primaryExpr
    :   compExpr
    |   inExpr
    |   parameterExpr
    |   attribute
    ;

parameterExpr
    :   attribute (EQ | NE | GT | LT | GE | LE)^ parameter
    |   aliasdAttribute (EQ | NE | GT | LT | GE | LE)^parameter
    ;

compExpr
    :   attribute (EQ | NE | GT | LT | GE | LE)^ value
    |     aliasdAttribute(EQ | NE | GT | LT | GE | LE)^value
    ;
alias
    :   ID
    ;
inExpr  :   attribute IN^ valueList
    ;

attribute: ID -> ^(ATTR_NAME ID);

aliasdAttribute
    :       alias(DOT)(ID) -> ^(ALIAS alias ) ^(ATTR_NAME ID)
    ;
  • 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-07T05:24:58+00:00Added an answer on June 7, 2026 at 5:24 am

    Is there a way to do this?

    Sure.

    The alias rule in grammar T:

    grammar T;
    
    options {
      output=AST;
    }
    
    tokens {
      ALIAS;
    }
    
    alias
     : ID -> ALIAS[$ID.text]
     ;
    
    ID : ('a'..'z' | 'A'..'Z')+;
    

    will always produce (rewrite) a token with type ALIAS, but with inner text the same as the ID token.

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

Sidebar

Related Questions

Why is this printing out 0 back in main but 6 when it is
I am having some issues printing out the subarray homemain=>image This is my JSON
I successfully inserted some data into my sqlite database(I confirmed this by printing out
i have the following search form <?php echo $this->Form->create('Order', array('action' => 'search','type'=>'get'));?> <?php echo
after executing this code, I get an infinite loop just printing zeros : (
The javascript is printing out the HTML onto the page example below, is it
I'm printing out the stack trace in my app at various points to debug
I'm building an XML document and printing out into an indented format using the
Like the title says I'm having some trouble printing out symbol codes and their
I'm just trying to quickly debug a webservice by printing out the contents of

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.