Aka. parse tree. Represents the hierarchical structure of a derivation from a CFG.
Structure:
- Root: start symbol
- Internal nodes: non-terminals
- Leaves: terminals or
Reading leaf nodes left-to-right gives the derived string (the yield of the tree).
Types of Derivations
Leftmost Derivation
Always replace the leftmost non-terminal first.
Rightmost Derivation
Always replace the rightmost non-terminal first.
Each derivation tree corresponds to exactly 1 leftmost derivation and exactly 1 rightmost derivation.
Example
Grammar:
Deriving leftmost:
The corresponding derivation tree has at the root, with children , , . The right has children , , .
Ambiguity
A grammar is ambiguous iff some string has 2 or more distinct derivation trees (equivalently, 2 distinct leftmost derivations).
For under the grammar above, a 2nd tree exists where the root splits as instead. Both trees are valid, so the grammar is ambiguous.