pt3 2
pt3 2
• In a parse tree, the points are called nodes. Each node has a label on
it.
• The topmost node is called the root. The bottom nodes are called
leaves.
• The yield of a parse tree is the concatenation of the labels of the leaves,
from left to right. The yield of the tree above is ()().
1
1.1 Leftmost and Rightmost Derivations
• In a leftmost derivation, at each step the leftmost nonterminal is re-
placed. In a rightmost derivation, at each step the rightmost nonter-
minal is replaced.
L R
• Such replacements are indicated by ⇒ and ⇒, respectively.
L∗ R∗
• Their transitive closures are ⇒ and ⇒ , respectively.
It is possible to obtain a derivation from a parse tree and vice versa. Here
is an example of obtaining a derivation from a parse tree, going from left to
right:
( s ) ( s ) e e e e
e e
• Using the same diagram, going from right to left, starting with only an
arbitrary derivation, we can obtain a parse tree:
2
s => s s => (s) s => () s => () ( s ) => () ()
s s (s) (s ) e (s) (s ) e
( s ) ( s ) e e e e
e e
1. A ⇒∗ w
Proof:
3
1.2 Ambiguity
Some sentences in English are ambiguous:
E →E+E E→a
E →E∗E E→b
E → (E) E→c
4
E E
E + E E * E
a E * E E + E c
b c a b
{an bn cm dm : n ≥ 1, m ≥ 1} ∪ {an bm cm dn : n ≥ 1, m ≥ 1}
5
S → SS
S→a
S→A
A → AA
A→a
S → AA
A→S
A→a
S → SbS
S→a
S → AbA
A→S
A→a