
























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Some concept of Automata and Complexity Theory are Administrivia, Closure Properties, Context-Free Grammars, Decision Properties, Deterministic Finite Automata, Intractable Problems, More Undecidable Problems. Main points of this lecture are: Parse Trees, Relationship, Left-, Rightmost Derivations, Ambiguity in Grammars, Parse Trees, Leaves, Interior Nodes, Root, Labeled
Typology: Slides
1 / 32
This page cannot be seen from the preview
Don't miss anything!
1
Definitions
Relationship to Left- and
Rightmost Derivations
Ambiguity in Grammars
2
are trees labeled by
symbols of a particular CFG.
Leaves: labeled by a terminal or
ε
Interior nodes: labeled by a variable.
Children are labeled by the right side of aproduction for the parent.
Root: must be labeled by the start symbol.
4
The concatenation of the labels of the leaves in left-to-right order
That is, in the order of a preordertraversal.
is called the
of the parse tree.
Example: yield of
is (())()
S
S
S S
)
(
(
)
(
)
5
For every parse tree, there is a uniqueleftmost, and a unique rightmostderivation.
We’ll prove:
If there is a parse tree with root labeledA and yield w, then A =>*
lm
w.
If A =>*
lm
w, then there is a parse tree
with root A and yield w.
7
Assume (1) for trees of height < h, and let this tree have height h:
By IH, X
i
lm
w
i
Note: if X
i
is a terminal, then
X
i
= w
i
.
Thus, A =>
lm
1
n
lm
w
1
2
n
lm
w
1
w
2
3
n
lm
lm
w
1
…w
n
A
X
1
X
n
...
w
1
w
n
8
Given a leftmost derivation of a terminal string, we need to prove theexistence of a parse tree.
The proof is an induction on the length of the derivation.
10
Assume (2) for derivations of fewer than k > 1 steps, and let A =>*
lm
w be
a k-step derivation.
First step is A =>
lm
1
n
Key point: w can be divided so the first portion is derived from X
1
, the next is
derived from X
2
, and so on.
If X
i
is a terminal, then w
i
= X
i
.
11
That is, X
i
lm
w
i
for all i such that X
i
is a variable.
And the derivation takes fewer than ksteps.
By the IH, if X
i
is a variable, then there
is a parse tree with root X
i
and yield w
i
Thus, there is a parse tree
A
X
1
X
n
...
w
1
w
n
13
The proof that you can obtain a parse tree from a leftmost derivation doesn’treally depend on “leftmost.”
First step still has to be A => X
1
n
And w still can be divided so the first portion is derived from X
1
, the next is
derived from X
2
, and so on.
14
A CFG is
if there is a string
in the language that is the yield of twoor more parse trees.
Example: S -> SS | (S) | ()
Two parse trees for ()()() on next slide.
16
If there are two different parse trees, they must produce two differentleftmost derivations by the constructiongiven in the proof.
Conversely, two different leftmost derivations produce different parsetrees by the other part of the proof.
Likewise for rightmost derivations.
17
Thus, equivalent definitions of“ambiguous grammar’’ are:
There is a string in the language that hastwo different leftmost derivations.
There is a string in the language that hastwo different rightmost derivations.
19
ε
Construct a unique leftmost derivation for a given balanced string of parentheses byscanning the string from left to right.
If we need to expand B, then use B -> (RB ifthe next symbol is “(” and
ε
if at the end.
If we need to expand R, use R -> ) if the nextsymbol is “)” and (RR if it is “(”.
20
Remaining Input:(())()
Steps of leftmost
derivation:
Nextsymbol
ε