Search code examples
compiler-constructiontreeabstract-syntax-treesemantic-analysis

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?


Solution

  • 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.