Analysing a context-free grammar

46 Views Asked by At

Let:

$$S \to AC \mid BC\\ A \to aAb \mid aA \mid a\\ B \to aBb \mid Bb \mid b\\ C \to Cc \mid c$$

I need to find if:

  1. the word $aabbbcc $ is in the grammar, and if so to write a very left series, and the tree.

  2. what is the words that generated by grammar?

  3. to tell if the grammer is ambiguous


My try:

  1. Yes, $aabbbcc$ is in the grammar because $S\Longrightarrow BC\Longrightarrow aBbC \Longrightarrow aaBbbC\Longrightarrow aabbbC\Longrightarrow aabbbCc \Longrightarrow aabbbcc$

    enter image description here

  2. The laguage is $\mathscr{L}=\{a^ib^jc^*|i\neq j\}$

  3. I can't find a word that I can get from two diffrent derivations, so I think that the grammar isn't ambiguous

I'm not sure if my attempt is correct or not.

1

There are 1 best solutions below

4
On BEST ANSWER

You are right about 1.

In 2, $c^*$ is usually used to mean sequences of zero or more $c$s, but in this grammar there must be at least one $c$.

For 3, as $aa \Longleftarrow aA \Longleftarrow A$ and $aab \Longleftarrow aAb \Longleftarrow A$, $aaab$ can be parsed two ways as an $A$:

$$ aaab \Longleftarrow aAb \Longleftarrow A\\ aaab \Longleftarrow aA \Longleftarrow A. $$

and so $aabbc$ can be parsed two ways as an $AC$ and so as an $S$.