w such that contains at most two 1s, CFG idea

220 Views Asked by At

this is my first time that I did a CFG and I ask if it's correct or not. My idea is the follow:

 A -> 0A | 1B
 B -> 0B | 1C
 C -> 0C

As the CFG has to contains AT MOST two 1s I think it could be right but I'm not sure. Thanks to all

1

There are 1 best solutions below

0
On

Almost OK, but add a production that will get rid of a final $C$. And explicitly state which is the starting symbol (or axiom) of the grammar.

As a matter of fact you are building a finite state automaton in disguise. With states $A$, $B$ and $C$. When you did you had a clear idea in your mind about the meaning of these variables/states: $A,B,C$ mean "seen 0,1,2 $1$'s" (respectively). With such an idea in mind you have almost answered your own question.