a) { aibjck | i, j, k ≥ 0 and i = 2j + k }
The language contains strings like: ε, ac, aab, aacc, aaabc, aaaccc, aaaabcc, ...
The context free grammar shown below can generate the above
language.
S --> aSc / aAc / A / ε
A --> aaAb / aab / ε
For example, consider generating the word aaaabcc.
b)
{w ∈ {0, 1}* | the length of w is even, started by 1 and ended 01}
The language contains strings like 1001, 1101, 100001, 100101, 101001, 101101, 110001, ...
Clearly, every string in this language must start with 1 and end with 01.
So,
S --> 1A01
Here, the length of the string must be an even number. The length of prefix(1) + suffix(01) is odd. So, the middle term must be a string with odd number length. So,
A --> 0T / 1T
T --> 0A / 1A / ε
S --> 1A01
A --> 0T / 1T
T --> 0A / 1A / ε
For example, consider generating the string 1010 01
This way, we can generate CFG's for languages.
Hope you understood the answer. Please consider commenting if you don't understand anything.
Q6: (15 points) Give context-free grammar that generate the following language. a) abick ij,k 20 and...
Give a context-free-grammar describing the syntax of the following language. Thank you =) Give a context-free-grammar describing the syntax of the following language: L = { ww| we{a, b }" } is a context- free language, where w is a non-empty string from alphabet {a, b } and wt denotes the reversal of string w.
5. (5 points) Give context-free grammar that generate the following languages (1) (w is a binary string, and w starts and ends with the same symbol (2) the empty language (empty set)
Give a Context Free Grammar (CFG) for the following language: L = { w | the number of a’s and the number of b’s in w are equal, ∑= {a, b} }
Give a context-free grammar for the following language over = {0, 1}: L={w : w is not a palindrome}
2. (10 points) Use the pumping lemma for context free grammars to show the following languages are not context-free. (a) (5 points) . (b) (5 points) L = {w ◦ Reverse(w) ◦ w | w ∈ {0,1}∗}. I free grammar for this language L. lemma for context free grammars to show t 1. {OʻPOT<)} L = {w • Reverse(w) w we {0,1}*). DA+hattha follaurino lano
give context free grammer for this language 1. 35 Points] Give context-free grammars for the following languages: (c) wEfa, b, c}* : |w = 5na(w) +2n(w)}
Give a context free grammar for the language L where L = {a"bam I n>:O and there exists k>-o such that m=2"k+n) 3. Give a nondeterministic pushdown automata that recognizes the set of strings in L from question 3 above. Acceptance should be by accept state. 4. 5 Give a context-free grammar for the set (abc il j or j -k) ie, the set of strings of a's followed by b's followed by c's, such that there are either a...
Ambiguous Grammars Question 3 [10 points be an ambiguous context-free grammar. We know that the length of S Mwis not always the same as the length of S → M w. 15/10] Consider the string abba. Create a context-free grammar that proves this point, and show the 2 different derivations of different length. ·15/10 If a context-free grammar is not LL(1) can it then be LR(1) without changing anything? Explain and/or give an example. Ambiguous Grammars Question 3 [10 points...
Give a context-free grammar for the following language: L1 = {ww^R c^n : w ∈ {a, b}*, n >= 0}, i.e each string consists of a string w containing a’s and b’s, followed by the reverse of w, followed by 0 or more c’s.
Find the context free Grammar for the following language L = {w ∈ {a, b, c}* : na (w) + nb (w) ≠ nc (w)}.