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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:22:31+00:00 2026-05-29T06:22:31+00:00

I have a custom made grammar for an interpreted language and I am looking

  • 0

I have a custom made grammar for an interpreted language and I am looking for advice on a parser which will create a tree which I can query. From the structure I would like to be able to generate code in the interpreted language. Most grammar parsers that I have seen validate already existing code. The second part of my question is should the grammar be abstracted to the point that the Python code will substitute symbols in the tree for actual code terminology? Ideally, I would love be be able to query a root symbol and have returned all the symbols which fall under that root and so forth all the way to a terminal symbol.

Any advice on this process or my vocabulary regarding it would be very helpful. Thank you.

  • 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-05-29T06:22:33+00:00Added an answer on May 29, 2026 at 6:22 am

    The vast majority of parser libraries will create an abstract syntax tree (AST) from whatever code it is you’re generating; you can use whatever, eg pyparsing. To go from the AST to code, you might have to write functions manually to do that, but it’s pretty easy to do that recursively. For example:

    def generate(ast):
        if ast[0] == '+':
            return generate(ast[1]) + " + " + generate(ast[2])
        elif ast[0] == 'for':
            return "for %s in %s:\n" % (ast[1], generate(ast[2])) + generate(ast[3])
        ...
    

    assuming an AST structure that’s just a list where the first element is a tag for the node name, followed by the trees for any arguments: [+, 4, [*, 'x', 5]]. Of course, you should use whatever your parser library uses, unless you’re writing the parser yourself.

    I don’t understand what you mean by Python code substituting symbols in the tree for actual code terminology.

    You could write an easy function to iterate over all the symbols under a root node:

    def traverse_preorder(ast):
        yield ast[0]
        for arg in ast[1:]:
            for x in traverse_preorder(arg):
                yield x
    

    On second thought, the variable name ast is maybe a poor choice because of the ast module.

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

Sidebar

Related Questions

I have made a custom UserControl i Vb.net (windows application). How can I add
I have a custom made class called Graph in which I use adjacency lists.
I have been looking for a easy way to add borders to custom made
I have made a plugin for the iphone which is working fine. I can
I have a custom-made site which I want to migrate to a commercial solution
I want to use C# to build a custom-made scripting language . It will
I have custom-made wizard system which so far has been quite suitable. For most
I have UIPageControl which I have made custom its dot color is not changing
have a custom made slider which I would like to stop on hover. I've
I have a custom made device with which I send/receive data trough the serial

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.