# Ullman (Compiler Design) Edition 2 Exercise 4.2 Question 2 (Page No. 206 - 207)

1 vote
68 views

Repeat Question $4.2.1$ for each of the following grammars and strings:

1. $S\rightarrow 0S1\mid 01$ with string $000111$.
2. $S\rightarrow +SS\mid \ast SS\mid a$ with string $+\ast aaa$.
3. $S\rightarrow S(S)S\mid \epsilon$ with string $(()())$.
4. $S\rightarrow S+S\mid SS\mid (S)\mid S\ast\mid a$ with string $(a+a)\ast a$.
5. $S\rightarrow (L)\mid a$ and $L\rightarrow L,S\mid S$ with string $((a,a),a,(a))$.
6. $S\rightarrow aSbS\mid bSaS\mid\epsilon$ with string $aabbab$.
7. The following grammar for boolean expressions:
• $bexpr\:\rightarrow\:bexpr\:or\:bterm\mid bterm$
• $bterm\:\rightarrow\:bterm\:and\:bfactor\mid bfactor$
• $bfactor\:\rightarrow\:not\:bfactor\mid (bexpr)\mid true\mid false$

## Related questions

1
413 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 derivation for the string. Give a parse tree for the string. Is the grammar ambiguous or unambiguous? Justify your answer. Describe the language generated by this grammar.
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 strings of $0's$ and $1's$ that are palindromes; that is, the string reads the same backward as forward. The set of all ... of all strings of $0's$ and $1's$ of the form $xy$, where $x\neq y$ and $x$ and $y$ are of the same length.
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 \epsilon$ $S\rightarrow a \mid S+S \mid SS \mid S^{\ast} \mid (S)$
The following grammar is proposed to remove the "danglingelse ambiguity" discussed in Section $4.3.2$: $stmt\rightarrow if\: expr\: then\: stmt\mid matchedstmt$ $matchedstmt \rightarrow if \:expr \:then \:matchedstmt\: else\: stmt\mid other$ Show that this grammar is still ambiguous.