Problem

1. Prove that the context-froe grammar below over the terminals $\{x,+, \times\}$ is ambiguous.
\[
\begin{array}{l}
S \rightarrow S+S \mid T \\
T \rightarrow S \times S|S| x
\end{array}
\]

Answer

Expert–verified
Hide Steps
Answer

\(\boxed{\text{The given context-free grammar is ambiguous because the string 'x+x*x' can be derived in two different ways: '(x+x)*x' and 'x+(x*x)'.}}\)

Steps

Step 1 :To prove that a context-free grammar is ambiguous, we need to find a string that can be derived in more than one way from the start symbol. This means we need to find a string that has more than one parse tree.

Step 2 :Looking at the given grammar, we can see that the string 'x+x*x' can be derived in two different ways.

Step 3 :One way is to derive it as '(x+x)*x', and the other way is to derive it as 'x+(x*x)'.

Step 4 :So, we can conclude that the given grammar is ambiguous.

Step 5 :\(\boxed{\text{The given context-free grammar is ambiguous because the string 'x+x*x' can be derived in two different ways: '(x+x)*x' and 'x+(x*x)'.}}\)

link_gpt