I guess you mean convert it to a formal grammar with rules of the form V->w, where V is a nonterminal and w is a string of terminals/nonterminals. To start, you can simply say (mixing CFG and regex syntax):
S -> 01+10(11)*
Where S is the start symbol. Now let's break it up a bit (and add whitespace for clarity):
S -> 0 A 1 0 B
A -> 1+
B -> (11)*
The key is to convert *
es and +
es to recursion. First, we'll convert the Kleene star to a plus by inserting an intermediate rule that accepts the empty string:
S -> 0 A 1 0 B
A -> 1+
B -> (empty)
B -> C
C -> (11)+
Finally, we'll convert +
notation to recursion:
S -> 0 A 1 0 B
A -> 1
A -> A 1
B -> (empty)
B -> C
C -> 11
C -> C 11
To handle x?
, simply split it into a rule producing empty and a rule producing x .