Cfg Solved Examples May 2026

S → aSbb → a(aSbb)bb → aa(ε)bbbb → aabbbb (wrong). So that’s 4 b’s, not 3.

: [ S \to SS \mid (S) \mid \varepsilon ] cfg solved examples

Derivation for abba : [ S \Rightarrow aSbS \Rightarrow a\varepsilon bS \Rightarrow abS \Rightarrow abbSaS \Rightarrow abb\varepsilon a\varepsilon = abba ] Language : Valid arithmetic expressions with a, b, +, *, (, ) S → aSbb → a(aSbb)bb → aa(ε)bbbb → aabbbb (wrong)

So the sequence of rules: aSbb then aSb then ε. Good. So grammar works. Language : ( w \in a,b^* \mid w = w^R ) b^* \mid w = w^R )