Can we combine two non-terminals and use this as one non-terminal in CFG?

Let's consider this CFG-

S->AB [Here, **S** is the starting variable]
A->C
CB->Cb
C->a



Now, the question is- Check if ab is a valid string for the given string or not?

I thought an answer. And that is-

S->AB
->CB [A->C]
->Cb [CB->Cb]
->ab [C->a]


My question is, Can we generate string ab from this CFG in this way?

• The grammar that you included is not a context-free grammar. The left side of the production rules of a context-free grammar must consist of exactly one non-terminal, but the rule $CB \to CB$ has two non-terminals on the left side. (This is why it's "context free" – the context of a non-terminal does not affect its expansions) Sep 26 at 8:00
• @CurtisF what it should be? Sep 26 at 18:11