AST trees semantic analyzer
The last nodes of an AST tree must have the information of the traduction of 开发者_JAVA百科the semantic analyzer or the non-last nodes also can have this information?
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.
If I understand your question correctly, in an AST, interior nodes can also carry semantic information, as well as the leaf nodes.
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".
精彩评论