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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:28:24+00:00 2026-06-12T15:28:24+00:00

I’m having trouble figuring, deciding on how will the Abstract Syntax Tree result in

  • 0

I’m having trouble figuring, deciding on how will the Abstract Syntax Tree result in memory, will it be a forest of trees for each statement?, or will it be a single rooted binary tree?.

Sample source:

P: 10
if A < 15:
    P: 9

Here’s the BNF-Grammar :

<Prog>       ::= <Stmts>
<Stmts>      ::= <Stmt> | <Stmt> <Stmt>
<Stmt>       ::= <IfStmt> NL | <AssignStmt> NL
<AssignStmt> ::= <Id> : <Aexp> | <Indents> <AssignStmt>
<IfStmt>     ::= if <Lexp> : NL <Stmts> | <Indents> <IfStmt>
<Aexp>       ::= <Id> | <Int> | <Aexp> <AOP> <Aexp>
<Lexp>       ::= <Aexp> <LOP> <Aexp>
<LOP>        ::= < | > | & 
<AOP>        ::= + | - | * | /
<Int>        ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | <Int> <Int>
<Id>         ::= A | B | C | D | E | F | P
<Indents>    ::= SPC | SPC <Indents>

Where SPC represents white-space and NL the newline character. Yes it only allows 7 identifiers. And positive integers.

It is easily lexed, however I’ve searched lot but most of the AST examples only use mathematical expressions which are quit easy to grasp. If you find that my grammar is incorrect please say so. Also note that the syntax is inspired in Python I’ve read the Lexical Analysis doc for it but it doesn’t even mention the word tree.

Thanks in advance.

  • 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-12T15:28:25+00:00Added an answer on June 12, 2026 at 3:28 pm

    Given the fact that there may be multiple “statements” in the program and under each “if statement”, you can arrange statements as lists/arrays in memory. If you really want to use trees, you can do that, but those trees will only formally be trees as they will be degenerated and will look and function as lists. Think about it, every statement has practically no relation to its neighbor statements other than the order in which they appear and execute. They do not form a recursive structure. P: 10 and if A < 15: don’t have any recursive relationship with each other.

    It doesn’t seem there’s a good reason for or a clear advantage of using trees to represent statements. You may choose to use trees to have a single uniform data structure, however.

    As for expressions, they fit into the tree idea nicely since many operators are binary, they take one or two inputs and produce an output, which can in turn be used as an input to some other operator. There’s a clear recursion here.

    I think it would be practical to arrange the entire program as a list of sublists (for statements) and trees (for expressions). But you can use degenerated trees instead of (sub)lists.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
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

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.