1

Here is a context free grammar that I have been given for practice: Grammar $G = (V,\Sigma,R,S)$ where $V$ is $\{S,A,B,a,b,c\}$ and $\Sigma$ is $\{a,b,c\}$. $R$ has the following rules:

$$\begin{align}S &\to A\\ A &\to BB\\ S &\to bS\\ S &\to cS\\ A &\to a\end{align}$$

I am fairly sure that it is not ambiguous, since for a grammar to be ambiguous there will be two ways to reach a result. In the grammar above, each $b$ comes from $S \to bS$, each $c$ comes from $S \to cS$, and each $a$ comes from $S \to A \to a$. It seems the $A \to BB$ is never used and $c=(b\cup c)^*a$. So there is only one derivative of each string in $L$.

My question is, is my thinking correct and would this suffice to prove that the grammar is not ambiguous?

Edit: We went over the problem in class a while back and the explanation above was accurate.

  • 2
    You already asked this question. I said the grammar was ill-defined because symbol B is used but has no definition. You deleted that question and re-asked a couple minutes later, but did not fix that error. Why? – orlp Mar 29 '17 at 06:42
  • I deleted this post earlier per the request of the other comment, but was then told that they recommended deleting the other duplicate rather than this one, hence the repost. As for symbol B, the question does not provide any other information than what is above. Since symbol B is not defined, could this be a reason as to why the grammar is unambiguous or would it just make it unsolvable? If it is the latter case, the question itself is flawed. – TweezerCube Mar 29 '17 at 06:47
  • 1
    Assuming you didn't miss a definition of B somewhere I'd argue that the question itself is indeed flawed. – orlp Mar 29 '17 at 06:50
  • This was a class question written by one of my professors on a presentation slide. I will have to speak with him or an assistant, but it might also be possible that he intended us to find a flaw in the problem. – TweezerCube Mar 29 '17 at 07:09
  • 3
    @orlp Having a non-terminal symbol that can't generate anything is not a problem, just like having states that aren't co-accessible in an automaton isn't a problem. They are just superfluous. – xavierm02 Mar 29 '17 at 09:16
  • @xavierm02 I believe those are not the same thing. Having unreachable states is akin to defining rule B but never referencing it. Referencing B but never defining it is aking to drawing a non-final state that can be accessed but has no exiting state transitions defined. – orlp Mar 29 '17 at 13:49
  • @orlp I didn't mention accessible states, only co-accessible states (meaning that they is a path from them to a final state). And yes, you can have states that are accessible, non-final but have no outgoing transitions and it's not a problem. You can just remove them. Of course, you often want to work with automata that are complete, and in which every state (except possibly one) is both accessible and co-accessible. And you often want to work with proper grammars. In both case, there is an easy simplification that allows you to simplify the object so there is no reason to restrict the def – xavierm02 Mar 29 '17 at 14:00
  • 1
    Your thinking is correct, and you can use your ideas to formally prove that the grammar is unambiguous. – Yuval Filmus Mar 29 '17 at 16:42

0 Answers0