Polish
Polish

Reputation: 466

What is difference between Parse Tree, Annotated Parse Tree and Activation Tree ?(compiler)

I know what is a Parse Tree and what is an Abstract Tree but I after reading some about Annotated Parse Tree(as we draw detailed tree which is same as Parse Tree), I feel that they are same as Parse Tree.

Can anyone please explain differences among these three in detail ?

Thanks.

Upvotes: 6

Views: 24855

Answers (3)

user8610338
user8610338

Reputation:

An annotated parse tree lets you intergrate the entire compilation into the parse tree structure. CM Modula-3 does that if im not mistaken.

To build an APT, simply declare an abstract base class of nodes, subclass each production on it and declare the child nodes as field variables.

Upvotes: 0

Ira Baxter
Ira Baxter

Reputation: 95354

A parse tree is a representation of how a source text (of a program) has been decomposed to demonstate it matches a grammar for a language. Interior nodes in the tree are language grammar nonterminals (BNF rule left hand side tokens), while leaves of the tree are grammar terminals (all the other tokens) in the order required by grammar rules.

An annotated parse tree is one in which various facts about the program have been attached to parse tree nodes. For example, one might compute the set of identifiers that each subtree mentions, and attach that set to the subtree. Compilers have to store information they have collected about the program somewhere; this is a convenient place to store information which is derivable form the tree.

An activation tree is conceptual snapshot of the result of a set of procedures calling one another at runtime. Node in such a tree represent procedures which have run; childen represent procedures called by their parent.

So a key difference between (annotated) parse trees and activation trees is what they are used to represent: compile time properties vs. runtime properties.

Upvotes: 3

MANSI RAJPARA
MANSI RAJPARA

Reputation: 71

AN ANNOTATED PARSE TREE is a parse tree showing the values of the attributes at each node. The process of computing the attribute values at the nodes is called annotating or decorating the parse tree.

For example: Refer link below, it is annotated parse tree for 3*5+4n

https://i.sstatic.net/WAwdZ.png

Upvotes: 7

Related Questions