Cfg Solved Examples · Official & High-Quality

( L = a^n b^n \mid n \geq 1 )

Just chain the start symbols.

This is the classic "Dyck Language," used by compilers to check for matching brackets () or braces {} . Grammar: S→(S)cap S right arrow open paren cap S close paren S→SScap S right arrow cap S cap S S→ϵcap S right arrow epsilon cfg solved examples

Derivation for ( a^2 b^1 c^3 ): S ⇒ aSc ⇒ aaScc ⇒ aaTcc ⇒ aabTccc ⇒ aabεccc = aabccc.

That means m=3 not reachable for n=2 in this grammar? Correct — known property: this grammar gives m = n + k where k is number of times you used aSbb. For n=2, k can be 0 or 1 or 2 → m=2,3,4 possible. Yes, so m=3 possible: n=2,k=1 → S → aSbb → a(aεbb)bb? Let’s do stepwise: ( L = a^n b^n \mid n \geq 1 ) Just chain the start symbols

P → m P m → ma P am → mad P adam → madam

: ( a^n b^m \mid n \ge 0, m \ge n, m \le 2n ) That means m=3 not reachable for n=2 in this grammar

: This grammar allows you to wrap a string in identical characters ('a' or 'b') recursively, ending with an empty string ( ) to ensure it is a palindrome. Simple Repetitive Language : Generating strings like a to the n-th power (any number of 'a's). cap S right arrow a cap S divides epsilon : The symbol

cap S right arrow a cap S a divides b cap S b divides epsilon

New start ( S_0 \to E ). Step 2: Terminals: Introduce ( P \to + ), ( M \to * ), ( L \to ( ), ( R \to ) ), ( V \to x ). Step 3: Break rules:

: [ S \to aS \mid bS \mid \varepsilon ] Wait — that gives any length. Let's fix: