Recent questions tagged context-free-grammar

0 0 votes
0 0 answers
353
353 views
Show how, having filled in the table as in Question $4.4.9$, we can in $O(n)$ time recover a parse tree for $a_{1}a_{2}\cdot\cdot\cdot a_{n}$. Hint: modify the table so i...
0 0 votes
0 0 answers
447
447 views
Every language that has a context-free grammar can be recognized in at most $O(n^{3})$ time for strings of length $n$. A simple way to do so,called the Cocke- Younger-Ka...
0 0 votes
0 0 answers
630
630 views
Design grammars for the following languages:The set of all strings of $0's$ and $1's$ such that every $0$ is immediately followed by at least one $1$.The set of all strin...
2 2 votes
0 0 answers
1.1k
1.1k views
Repeat Question $4.2.1$ for each of the following grammars and strings: $S\rightarrow 0S1\mid 01$ with string $000111$.$S\rightarrow +SS\mid \ast SS\mid a$ with string $+...
6 6 votes
1 1 answer
13.9k
13.9k views
Consider the context-free grammar:$$S\rightarrow SS + \mid SS {\ast} \mid a$$and the string $aa + a{\ast}$.Give a leftmost derivation for the string.Give a rightmost deri...
1 1 vote
0 0 answers
455
455 views
Construct a context-free grammar for roman numerals.
0 0 votes
0 0 answers
861
861 views
Construct unambiguous context-free grammars for each of the following languages. In each case show that your grammar is correct. Arithmetic expressions in postfix notatio...
1 1 vote
3 3 answers
1.7k
1.7k views
Which of the grammars are ambiguous? $S\rightarrow 0S1 \mid 01$$S\rightarrow +SS \mid -SS \mid a$$S\rightarrow S(S)S \mid \epsilon$$S\rightarrow aSbS \mid bSaS \mid \epsi...
0 0 votes
0 0 answers
484
484 views
What language is generated by the following grammars? In each case justify your answer. $S\rightarrow 0S1 \mid 01$$S\rightarrow +SS \mid -SS \mid a$$S\rightarrow S(S)S \m...
0 0 votes
0 0 answers
366
366 views
Consider the context-free grammar$S\rightarrow SS+\mid SS^{\ast}\mid a$Show how the string $aa+a^{\ast}$ can be generated by this grammar.Construct a parse tree for this ...
0 0 votes
0 0 answers
484
484 views
Let $L$ be the set of (codes for) context-free grammars $G$ such that $L(G)$ contains at least one palindrome. Show that $L$ is undecidable. Hint: Reduce PCP to $L$ by co...
0 0 votes
0 0 answers
621
621 views
Give LL grammars for the following languages, assuming $Σ =$ {$a,b, c$}.(i) $L=$ {$a^nb^mc^{n+m}:n\geq0,m\geq0$} .(ii) $L=$ {$a^{n+2}b^mc^{n+m}:n\geq0,m\geq0$} .(iii) $L=...
1 1 vote
1 1 answer
525
525 views
Let G be a context-free grammar in Greibach normal form. Describe an algorithm which, for anygiven k, determines whether or not G is an LL (k) grammar.
0 0 votes
0 0 answers
445
445 views
Show that if G is an LL (k) grammar, then L (G) is a deterministic context-free language.
0 0 votes
1 1 answer
519
519 views
0 0 votes
0 0 answers
329
329 views
0 0 votes
1 1 answer
585
585 views
Show that the grammar for L = {$w : n_a (w) = n_b (w)$} which is, $S\rightarrow SS,S\rightarrow \lambda,S\rightarrow aSb,S\rightarrow bSa$ is not an LL grammar.
0 0 votes
0 0 answers
361
361 views
Show that the grammar $S_0\rightarrow aSbS,S\rightarrow aSbS|\lambda$ is an LL grammar and that it is equivalent to the grammar $S\rightarrow SS|aSb|ab$.
1 1 vote
2 2 answers
1.4k
1.4k views
$L1 =\left \{ a^{m} b^{n} c^{p} | \left ( m \geq n \right )\text{or} \left ( n = p \right ) \right \}$ $L2 =\left \{ a^{m} b^{n} c^{p} | \left ( m \geq n \right )\text{a...
3 3 votes
2 answers 2 answers
1.2k
1.2k views
Let the valid moves along a staircase be $U$ (one step up) and $D$ (one step down). For example, the string $s = UUDU$ represents the sequence of moves as two steps up, t...
0 0 votes
1 1 answer
617
617 views
Give unambiguous $CFG's$ for the following languages$.$$\text{{$w\mid$ in every prefix of $w$ the number of $a’s$ is at least the number of $b’s$}}$$\text{{$w\mid$ the nu...
0 0 votes
1 1 answer
1.9k
1.9k views
$G$ is a natural-looking grammar for a fragment of a programming language, but $G$ is ambiguous$.$Show that $G$ is ambiguous$.$Give a new unambiguous grammar for the same...
1 1 vote
1 1 answer
841
841 views
Show that if $G$ is a $CFG$ in Chomsky normal form$,$ then for any string $w\in L(G)$ of length $n\geq 1,$ exactly $2n − 1$ steps are required for any derivation of $w.$
0 0 votes
1 1 answer
700
700 views
Let $C = \{x\#y \mid x, y\in\{0,1\}^{*}$ and $x\neq y\}.$ Show that $C$ is a context-free language$.$
0 0 votes
1 1 answer
591
591 views
Let $\Sigma = \{a,b\}.$ Give a $CFG$ generating the language of strings with twice as many $a’s$ as $b’s.$ Prove that your grammar is correct$.$
0 0 votes
0 0 answers
544
544 views
Let $CFG$ $G$ be the following grammar$.$ $S\rightarrow aSb \mid bY \mid Y a$$Y\rightarrow bY \mid aY \mid \epsilon$Give a simple description of $L(G)$ in English$.$ Us...
0 0 votes
0 0 answers
525
525 views
Give a counterexample to show that the following construction fails to prove that the class of context-free languages is closed under star. Let $A$ be a $\text{CFL}$ that...
0 0 votes
1 1 answer
2.6k
2.6k views
Convert the following $\text{CFG}$ into an equivalent $\text{CFG}$ in Chomsky normal form,using the procedure given in $\text{Theorem 2.9.}$$A\rightarrow BAB \mid B \mid ...
0 0 votes
1 1 answer
759
759 views
Let $G = (V, \Sigma, R, S)$ be the following grammar. $V = \{S, T, U\}; \Sigma = \{0, \#\};$ and $R$ is the set of rules$:$$S\rightarrow TT\mid U$$T\rightarrow 0T\mid T0\...