Context-Free Languages: Questions
- Consider the following grammar with start symbol S:
S -> AA
A -> AAA
A -> a
A -> bA
A -> Ab
- What strings can be produced by derivations of four or fewer steps?
- Give at least four distinct derivations for the string babbab.
- Construct context-free grammars which generate each of the following languages:
- {wcwR | w Î {a,b}*}
- {wwR | w Î {a,b}*}
- {w Î {a,b}* | w = wR}
- Consider the following grammar with start symbol S:
S -> aB
S -> bA
A -> a
A -> aS
A -> BAA
B -> b
B -> bS
B -> ABB
- Show that the string ababba belongs to this language.
- Prove by induction that all strings in the language have equal numbers of a's and b's.
- Consider the following grammar with start symbol S:
S -> PVP
P -> N
P -> AP
N -> cheese
N -> Jim
V -> ate
A -> green
A -> big
Give a parse tree for the sentence "big Jim ate green cheese".
- Consider the following grammar with start symbol S:
S -> SS
S -> (S)
S -> e
Show that this grammar is ambiguous by generating two different parse trees for the sentence ()(). Give an equivalent unambiguous grammar.
- Consider the pushdown automaton with start state s, accepting state f and the following transitions:
((s,a,e),(s,a))
((s,b,e),(s,b))
((s,a,e),(f,e))
((f,a,a),(f,e))
((f,a,b),(f,e))
((f,b,a),(f,e))
((f,b,b),(f,e))
Indicate whether or not each of the following strings is accepted by this PDA:
- a
- b
- aa
- ab
- bb
- aab
- aaa
- baa
- bab
- bbb
- Construct a pushdown automaton to recognise the same language as that described by the grammar in question 5.
- Give a context-free grammar which describes the same language as that recognised by the pushdown automaton in question 6.
- Construct a pushdown automaton to recognise the following language:
{aibjck | i,j,k >=0 and i=j or j=k}
- Use the pumping lemma to show that the following languages are not context-free:
- {aibjck | i < j < k}
- {w Î {a,b,c}* | the number of a's is equal to the maximum of the number of b's and the number of c's}