1

I have this language

$L = \{a^{n}b^{3n}c^{2m} : m,n \ge 1\}$.

I have to determine a free context grammar that generates L. Looks easy BUT i have a question about the grammar I found. First things first, this is my grammar:

$S \Rightarrow BC$

$ B \Rightarrow aBbbb\ \backslash \ abbb $

$ C \Rightarrow Ccc \ \backslash \ cc$

Looks easy and clean to me. I already tested it with strings of different lengths and seems working just fine. Also it does indeed create only strings contained in L and no other strings.

My question is:

This is the first time I generate a grammar without any production containing $S$ itself (An example would be adding $S \Rightarrow B$ and I would solve my problem, because B generates only $a$'s and $b$'s and the number of this chars is dipendent between one another but indipendent with the number of $c$'s inside the string).

Recursively speaking, this works just fine but using $S$ would induce me to create a noncontracting language (because I'd be forced to invert some Non Terminals in order to produce both $a$'s and $b$'s correctly if something is wrong in my grammar). Is this way of creating grammars correct? Can I describe what I wrote as an actual "grammar"? Is it context free?

Also, can I actually derivate $a$ through $B$ without a nonterminal $A$ and without generating it with the $S$ production?

vonbrand
  • 14,204
  • 3
  • 42
  • 52
Nope
  • 13
  • 4

2 Answers2

1

Your context-free grammar is just fine. It is not actually necessary for the grammar to have a production with $S$ in its right-hand side. In fact, a context-free grammar need not have any recursive productions or mutually-recursive productions, though the generated language in that case may be quite limited. It is also not necessary to use any particular names for your nonterminals (e.g there is no need for $A$ to appear anywhere).

PMar
  • 46
  • 1
0

Check your definitions. Mine says there is an alphabet of nonterminals $N$, an alphabet of terminals $\Sigma$ (where $N \cap \Sigma = \varnothing$, essentially "you can tell what is what"), a finite set of productions of the form $A \to \alpha$, where the left hand side $A \in N$ (a single non-terminal) and the right hand side $\alpha \in (N \cup \Sigma)^+$ (terminals and non-terminals in any order, at least one; you can allow empty right hand sides as an extension), one of the nonterminals is designated as starting symbol.

That's it. Note that this allows "nonsense" like no productions at all, no productions for the start symbol, symbols that are never used, unconnected pieces. No restriction on how/where a symbol is used. The reason is simple: less restrictions make the definition easier to check and to use. So you can construct something (like it is done for example when building a grammar from a PDA) and it is easy to check it is a CFG, even if it contains lots of useless junk (that wold be messy to eliminate in general). Any "nonsense" is either filtered out because it leads nowhere, or can be eliminated if you are really so inclined. You will see the same in much of mathematics, and this is a branch of mathematics. Take a look at other definitions (like the ones of the different automata), you'll see similar allowance for "nonsense" if you look closely.

vonbrand
  • 14,204
  • 3
  • 42
  • 52