Monday Discount - Lifetime Access for $20!!!! - Click Here! |
: [ S \to aS \mid bS \mid \varepsilon ] Wait — that gives any length. Let's fix:
: [ S \to aSbS \mid bSaS \mid \varepsilon ]
: [ S \to SS \mid (S) \mid \varepsilon ] cfg solved examples
: [ E \to E + T \mid T ] [ T \to T \times F \mid F ] [ F \to (E) \mid a \mid b ]
So the sequence of rules: aSbb then aSb then ε. Good. So grammar works. Language : ( w \in a,b^* \mid w = w^R ) : [ S \to aS \mid bS \mid
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:
: [ S \Rightarrow aSb \Rightarrow aaSbb \Rightarrow aaaSbbb \Rightarrow aaabbb ] 5. Example 4 – ( a^n b^m ) with ( n \le m \le 2n ) Language : ( a^n b^m \mid n \ge 0, m \ge n, m \le 2n ) So grammar works
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, +, *, (, )
Know what an affiliate program is? You make money just by sharing links to our site! Win. Win.
Earn when you refer any buyer here! 30 day tracking. Commissions are 33%-50% and recur on subscription products!