printable version
Exam 2 Review A
[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]
Problem X2rA.1.
Consider the following context-free grammar.
Give a derivation of the string
aabbab using this grammar.
| S | ⇒ | aSbS |
| ⇒ | aaSbSbS |
| ⇒ | aabSbS |
| ⇒ | aabbS |
| ⇒ | aabbaSbS |
| ⇒ | aabbabS |
| ⇒ | aabbab
|
[Note that it is important in a derivation to replace exactly one
symbol in each step. Do not combine steps.]
Problem X2rA.2.
Give the derivation or syntax tree for
yyx+yx+z using the below context-free grammar.
| S | ⇒ |
A + S |
| ⇒ |
A + A + S
| | ⇒ |
y A + A + S
| | ⇒ |
y y A + A + S
| | ⇒ |
y y x + A + S
| | ⇒ |
y y x + A + z
| | ⇒ |
y y x + y A + z
| | ⇒ |
y y x + y z + z
|
|
|
Problem X2rA.3.
Consider the following context-free grammar.
| S | → |
T + S | T |
| T | → |
F T | F |
| F | → |
x | y | ( S )
|
Draw a syntax tree for the sentence
x ( x + y ).
Problem X2rA.4.
Consider the following context-free grammar.
| S | → |
V V | V |
| V | → | ( S )
| x | y | z
|
Each of the following sentences is either described by this
grammar or not. If it is, give either a syntax tree with
S
at its root or a derivation from
S.
If it is not, simply say so.
a. x ( y )
b. x y z
c. x ( y z )
| a. | x ( y ) |
It is described by the grammar.
 |
| b. | x y z |
It is not described by the grammar |
| c. | x ( y z ) |
It is described by the grammar.
 |
Problem X2rA.5.
Write a context-free grammar describing each of the following
languages.
| a. |
the set of strings of a's and b's beginning and ending
with the letter a |
| b. |
the set of strings containing
either only a's or only b's |
| a. | |
| b. |
| S | → | A | B |
| A | → | a A | λ |
| B | → | b B | λ |
|
Problem X2rA.6.
Write a context-free grammar describing each of the following
languages.
| a. |
the set of strings containing only a's and b's consisting
entirely of repetitions of the same letter, except the final letter, which
must be different.
Examples include aaaab, bbbbbba, and
ab. |
| b. |
the set of strings containing a's, b's, and c's
where no a's appear after the first b |
| a. |
S → a X | b Y
X → a X | b
Y → b Y | a
|
| b. |
S → X Y
X → a X | c X | λ
Y → b Y | c Y | λ
|
Problem X2rA.7.
Write a context-free grammar describing
the set of strings
containing only a's and b's with at least one a and
at least one b.
| S | → | a T b T | b T a T |
| T | → | a T | b T | λ |
Problem X2rA.8.
Write a context-free grammar that describes the strings of
a's and b's containing exactly three a's.
Examples in the language include
aaa,
abaab, and
babbbabba,
but not baaaab.
X → Y a Y a Y a Y
Y → b Y | λ
Problem X2rA.9.
Write a context-free grammar describing the language containing
all strings of a's and b's for which the number of
a's is even. Examples include aa, abbababa,
and bbbb (since 0 is an even number).
S → T a T a S | λ
T → b T | λ