pablomarti
pablomarti

Reputation: 2107

AST trees semantic analyzer

The last nodes of an AST tree must have the information of the traduction of the semantic analyzer or the non-last nodes also can have this information?

Upvotes: 2

Views: 488

Answers (3)

umlcat
umlcat

Reputation: 4143

All AST trees have to store semantic information.

But, its true that the "leaf nodes", (nodes that reference variables, values, operands), may store some additional or different information than "branch-nodes" or "non leaf nodes".

Upvotes: 0

Ira Baxter
Ira Baxter

Reputation: 95306

Your question seems not quite well formed.

Under the assumption you mean "leaf nodes" where you wrote "last nodes", yes, you can associate semantic information not only with leaves but with interior nodes.

A simple example would be "the type of this expression". It is clear that leaf node containing the literal TRUE would have an expression type "boolean" associated with it. The expression "if e then 2.7 else 9.3 endif" has a corresponding AST, and the internal node corresponding to the if-expression would have an associated type of "float".

There are lots of "semantic" properties one could propose: "uses variables X, Y, Z", "side effect-free", "forks parallel subprocesses", etc. any of which might apply to interior tree nodes.

Upvotes: 3

Egdares Futch
Egdares Futch

Reputation: 1

If I understand your question correctly, in an AST, interior nodes can also carry semantic information, as well as the leaf nodes.

Upvotes: 0

Related Questions