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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:15:41+00:00 2026-06-10T05:15:41+00:00

I am designing a declarative language. In my language are definitions of nodes that

  • 0

I am designing a declarative language. In my language are definitions of “nodes” that can be reused later. Think of them like prototypes or templates. You can create copies of them as needed. I have a version of the interpreter that generates the appropriate Java objects during the definition phase. Up until recently I have been using a deep copy library to create copies of the Java representation of the nodes to create instances of the node. Due to the limitations of most of the deep copying libraries I have found and my lack of desire to write a copy constructor for every object in my system, I want to take a different approach. Part of my language specifies GUI Java Swing objects which cause issues with the deep copy libraries.

Is there a way I can save the AST subgraph for my object declaration and reprocess it when I want to create an instance of the node? I am asking the question in terms of ANTLR ASTs, but if you have a language implementation advice I welcome that too.

  • 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-10T05:15:43+00:00Added an answer on June 10, 2026 at 5:15 am

    In an ANTLR parser/lexer grammar, you have access to a $ruleName.tree. This rule attribute is the reference to AST subtree generated during parsing. Using the @after field and the @members field, you can store the subtree. Let me show you.

    @members{
    private List<CommonTree> defs = new ArrayList<CommonTree>();
    
    public List<CommonTree> getDefs(){
        return defs;
    }
    
    }
    

    below in your grammar

    ruleName 
    @after{
        defs.add($ruleName.tree);
    }
    : IDENT ;
    

    This will create a list of all the ruleName AST subtrees. These trees can be turned into CommonTreeNodeStream and used with your tree grammar code.

    CommonTree defTree = Parser.getDefs().get(0); // just getting the first tree for example
    CommonTreeNodeStream defStream = new CommonTreeNodeStream(defTree);
    TreeWalker walker = new TreeWalker(defStream);
    //assuming that I have a tree grammar that has been defined to return a list of nodes
    

    See this question for more info on returning data from an ANTLR grammar rule.

    List<Node> nodes = walker.topRule() 
    

    This will allow you to create node instances by reprocessing saved AST subgraphs. You can create the TreeNodeStream and call the walker whenever you need to create an instance.

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

Sidebar

Related Questions

I'm designing a declarative language for defining signal networks. I want to use variable
If I am making a grammar for a c-like language that has a sequence
Designing forms has always been fun, but getting them to send email on the
When designing a form in the IDE, non-visual components (eg TMainMenus, TDatamodules) can be
while designing my user control, i encountered the following problem: i would like to
Im designing my school's website and I kind of want to do like a
It seems like a bit of an omission that there's no easy way to
I am currently designing a portfolio website with wordpress. The idea is that it's
In android, we can design user interfaces by two methods: Procedural and declarative .
How can I define the term Declarative Security in context of web programming? Is

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.