8.4 Abstract Syntax Tree

Remember that a parse tree corresponds to the derivation of a sentence from the start symbol, where each internal node of the tree represents a non-terminal (NT) in the grammar and each leaf-node represents a Terminal (T). It is generated by the analysis phases – Scanner and Parser – of the compiler.

On the other hand, a syntax tree has as each node either some operator or some operand in the target language. A syntax tree represents a particular construct in the source language, but from the viewpoint of the target language. It is one possible output of the semantic phase, useful for optimization and Code Generation.

Sometimes we want to talk about a syntax tree having a particular structure, but in a general way, without ...

Get Compilers: Principles and Practice now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.