Copyright © 2006 Gradiance Corporation.
Grammatical Derivations and Parse Trees
Leftmost, rightmost derivations and their relationship to parse trees of a CFG.
1.
Here is a grammar for postfix expressions using the common four binary arithmetic operators:
S → SS+ | SS- | SS* | SS/ | a
Find a leftmost derivation for the terminal string aa+a/a*. Then, identify one of the steps (left-sentential forms) in the derivation from the list below.
a)
SS+S/S*
b)
Sa*
c)
aS/a*
d)
aa+S*
2.
The parse tree below represents a rightmost derivation according to the grammar S → AB, A → aS|a, B → bA.
Which of the following is a right-sentential form in this derivation?
aSB
aABba
aabAba
abaAbA
3.
Here is a parse tree that uses some unknown grammar G.
Which of the following productions is surely one of those for grammar G?
S → AB
B → AS
S → AbA
A → SB
4.
The parse tree below represents a leftmost derivation according to the grammar S → AB, A → aS|a, B → bA.
Which of the following is a left-sentential form in this derivation?
aaABBB
aSbA
aaBB
5.
Find a rightmost derivation for the terminal string aa/a+a-. Then, identify one of the steps (right-sentential forms) in the derivation from the list below.
aS/a+a-
aS/a+S-
SS+a-
aa/S+S-
6.
Find a leftmost derivation for the terminal string aa-aa/+. Then, identify one of the steps (left-sentential forms) in the derivation from the list below.
SSa/+
aa-SS+
aS-S+
aS-aS/+
7.
Find a rightmost derivation for the terminal string aa*aa-+. Then, identify one of the steps (right-sentential forms) in the derivation from the list below.
SSa-+
aa*SS-+
aS+
SaS-+