Tutorial 1 Discussion Document - Batch 03
Tutorial 1 Discussion Document - Batch 03
Tutorial 1 Discussion Document - Batch 03
Worked Example
S => aA => a
S => aS => aaA => aa
S => aS => aaS => aaaA => aaa
S → abb | aSbb
S => abb
1) For each of the following grammars, use set notation to define the language generated by the
grammar.
a) S → aaSB | λ
B → bB | b
L = {w ϵ {a^2i b^j | i ≥ 1, j ≥ 1 }} U λ
S => λ
S => aaSB => aaB => aab
S => aaSB => aaaaSBB => aaaaBB => aaaabB => aaaabb
S => aaSB => aaB => aab
S => aaSB => aaB => aabB => aabb
2
b) L = {w ϵ {a, b}* | w has odd length} //* can take a value 0 to ∞ In grammar, Upper case
letters are called as non-
Example valid strings: a, b, aaa, aab, aba, abb, baa, bab, bba, bbb, aaaaa, ababa etc.. terminals. Meaning, they can
be expanded.
S → a | b | SSS
Lower case letters are called
S => a as terminals. Meaning, they
S => b cannot be expanded. Always,
S => SSS => aSS => aaS => aaa alphabets will be terminals.
S => SSS => SSSSS
Left most derivation or right most derivation.
S → a | aA | b | bA
A → aS |bS
S => a
S => aA => aaS => aaa
S => aA => aaS => aaaA => aaaaS => aaaaa
S => b
S => bA => bbS => bbb
S = aA => abS => aba
S → λ | ab | aSb
S => aSb => aaSbb => aaabbb
S => aSb => ab
S => ab
S → λ | aSb
3. For each of the following Regular Expressions, write a regular grammar that defines the same
language.
b) L = (a υ b υ c)* a(a υ b υ c)* b(a υ b υ c)* υ (a υ b υ c)* b(a υ b υ c)* a(a υ b υ c)*
a b U ba
(a υ b υ c)*
w = e, a, b, c, aa, ab, ac, bb, cc, bc, cb, ca, ba, aaa, abc, cba, bac, cab, bbb, etc.
A = (a υ b υ c)*
S → AaAbA | AbAaA
A → e | aA | bA | cA
A => aA => a
A => aA => aaA => aa
A => bA => baA => bacA => bac
c) a(a υ b υ c)* b(a υ b υ c)*
S → aAbA
A → λ | aA | bA | cA