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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:21:47+00:00 2026-06-13T14:21:47+00:00

I’m still a little new to C++ so bear with me. I’m implementing an

  • 0

I’m still a little new to C++ so bear with me. I’m implementing an interpreter for a hypothetical language called Core thats described by a BNF grammar. So far I’ve implemented a tokenizer that gives me a nice queue of tokens representing a Core program. I’m now in the process of writing the Parser/Executer which takes the output from the tokenizer and uses it to populate an object of the ParseTree class (which I have to design) using recursive descent parsing. I understand the fundamentals of how to do this but am having trouble implementing the ParseTree class. Productions described by the Core BNF usually have 2-5 terminal/nonterminal symbols but some may have up to 20 so I need an n-ary tree where each node can have a different number of children.

I suppose the ParseTree class doesn’t necessarily need to use a tree for its implementation but that seems to make the most sense (Is there a different data structure that might be better/easier?). Im not aware of any container in STL that fits the bill for what I need. I’ve looked at the Boost property tree but from what I can tell that won’t work either. I’d prefer not to reinvent the wheel and implement a tree from scratch if at all possible. Also, I’m limited by not being able to use any external libraries aside from Boost. What is the best way to implement my ParseTree? Are there any good pre-made tree implementations I could use?

  • 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-13T14:21:49+00:00Added an answer on June 13, 2026 at 2:21 pm

    I suggest using ‘left child, right sibling’ binary tree for representing the parse tree. It is a replacement of an n-ary tree. Any n-ary tree can be represented using the ‘first child, next sibling’ BINARY tree.

    The concept is as follows:
    if A has three children: B, C and D and C has 2 children E and F as follows

                  A
                / | \
               B  C  D
                  /\
                 E  F
    

    this can be represented as

                  A
                 /
                 B
                  \
                   C
                  / \
                 E   D
                  \
                   F
    

    i.e. the children always go to the left node and the siblings to the right node. It is easy to build too and the pre-order traversal of this tree is same as the pre-order traversal of an n-ary tree.

    n-ary tree pre-order traversal:

    display (node, level) {
        if (!node) return;
        print node;
        display (node->left, level+1);
        display (node->right, level+1);
    }
    

    child sibling binary tree pre-order travesal

    display (node, level) {
        if (!node) return;
        print node;
        display (node->left, level+1);
        display (node->right, level);
    }
    

    How to build this tree:

    1. Throw your terminals and non-terminals in a Stack.
    2. When you want to combine n nodes under parent node 'p', pop 'n' elements from stack, making the last pop as the right child of the current pop.
    3. Finally make the nth pop the left child of node 'p'.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.