Hey guys,
I am facing a problem with one of my homeworks, it states:

The various analyses implemented in the program analysis module will
make use of a number of general data structures and algorithms and in
this exercise we shall focus on those.

The parser provides a representation of the abstract syntax tree;
specify this data structure in your implementation language

I have no idea what are they asking me to do, perhaps one of you had any experience with this and can help me out
Well, is it to explain what AST is or how is it implemented in Java? or idk =D

Recommended Answers

All 4 Replies

An abstract syntax tree is a tree where each node represents a syntactical element and each child of a node represents a sub-element of that element.

For example for the statement set x := y + 42; the AST would consist of an assignment node whose left child node would be an identifier node with the value "x" and whose right child would be an addition node. The addition node's left child would be an identifier node with the value "y" and its right child would be an integer literal node with the value 42.

To represent an AST in Java you'd define a class for each type of syntactical element that your language contains, using abstract base classes and inheritance to allow for the fact that multiple types of elements can be used as child nodes for some nodes (for example the child nodes of most expressions are themselves arbitrary expressions, so you'd have an abstract base class called Expression from which classes like Addition and IntegerLiteral inherit, so if a node has a member of type Expression, either an Addition or an IntegerLiteral (or any other type of expression that you implement) can be used there).

Hey there sepp2k,
Thank you for your response!
I am pretty happy that you wrote that example, because I am sure that other members will find it useful as well, but I was just wondering what exactly my question was. I wrote an email to my lecturer but no response back still ;(
Do you think the question means that I have to explain what ABS in general is?:o

Oh, I seem to have misread the last sentence of your question (I thought you wanted us to explain what an AST is and how to implement it in Java).

To answer your actual question: I think by "specify" the assignment simply means "define". That is it wants you to define the classes that make up the AST.

I see, well I'll get busy and implement it I guess, thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.