0% found this document useful (0 votes)
19 views

Language of Grammars

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Language of Grammars

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

LANGUAGE OF GRAMMARS

1
Language of Grammar:

 Language of Grammar ‘ G ’ is the set of all strings that can


be generated from the grammar G.

 If the language generated by the grammar consists of finite


number of strings, then the language is called as a finite
language otherwise an infinite language.

2
Example: Consider a grammar G = (V , T , P , S) where-
V={S}
T={a,b}
P = { S → aSbS , S → bSaS , S → ∈ }
S={S}

This grammar generates the strings having equal number of


a’s and b’s.

So, language of this grammar is :


L(G) = { ∈ , ab , ba , aabb , bbaa , abab , baba , …… } 

Since language of the given grammar consists of infinite


number of strings, therefore language of the given grammar is
infinite.

3
Example: Consider a grammar G = (V , T , P , S) where-
V={S,A,B,C}
T={a,b,c}
P = { S → ABC , A → a , B → b , C → c }
S={S}
 This grammar generates only one string “abc”.
 So, language of this grammar is - L(G) = { abc } 

Since language of the given grammar consists of finite number of strings,


therefore language of the given grammar is finite.

4
Important Concept:
 For any given grammar, the language generated by it is

always unique.
 However for any given language, we may have more than

grammar generating the given language.

5
Grammar G1-
S → AB
A → a
B → b
The language generated by this grammar is- L(G1) = { ab }
 
Grammar G2-
S → AB
A → ∈
B → ab
The language generated by this grammar is- L(G2) = { ab }

Note:
 Here, both the grammars generate a unique language and given a
language L(G) = { ab }, we have two different grammars generating the
same language.
 This justifies that for any given language, we may have more than
grammar generating the given language.
6
7
Regular Expressions
Regular Expressions are used to denote regular
languages.

Regular Expressions can be represented using meta


characters such as +, *, . , / , ( )
Examples:
1) a*
2) (a/b)*
3) (0* + 1)
4) (x+y+z)+
5) (0+1)*0(0+1)*0(0+1)*
6) (1*0)*1*
7) (0 + 1)* 10(0 + 1)*

8
Regular Sets:
A set that represents the value of the regular expression is
called a regular set.

a) 0 represents the set {0}


b) 1 represents the set {1}
c) ε represents the set {ε}
d) ∅ represents the empty set { }

If α and β are regular expressions representing the sets A


and B, then:

e) (αβ) represents the set { AB }


f) (α + β) represents the set { A∪B }
g) (α)* represents the set { A* }
9
10
Regular Grammar : 

A grammar is regular if it has rules of any one of the


following forms
A -> a
A -> aB
A -> ɛ ( Where ɛ is a special symbol called NULL )
 
Then that grammar is called regular grammar.

11
Regular Languages : 
A language is regular if it can be expressed in terms of
regular expressions.
( or )
A regular language can be generated from regular grammar

Ex:

If a* is a regular expression, then

L(a*) = { ϵ , a, aa, aaa,……}


L(a+) = { a, aa, aaa,……}

12
Definition of Non-Regular Languages
A language that cannot be defined by a regular expression is
called a non-regular language.
Notes:
– By Kleene’s theorem, a non-regular language can also not
be accepted by any FA.
– All languages are either regular or non-regular; none are
both.

13
Properties of Regular Sets

14
Property 1. The union of two regular set is regular.
Proof −
Let us take two regular expressions
RE1 = a(aa)* L1 = {a, aaa, aaaaa,.....}
RE2 = (aa)* L2 ={ ε, aa, aaaa, aaaaaa,.......}

L1 ∪ L2  = { ε, a, aa, aaa, aaaa, aaaaa, aaaaaa,.......}

Therefore

RE (L1 ∪ L2) = a*  (which is a regular expression itself)

Where  
L1 Strings of odd length excluding Null
L2 Strings of even length including Null
L1 ∪ L2  Strings of all possible lengths including Null
15
Property 2. The intersection of two regular set is regular.
Proof −
Let us take two regular expressions
RE1 = a(a*) L1 = { a,aa, aaa, aaaa, ....}
RE2 = (aa)* L2 = { ε, aa, aaaa, aaaaaa,.......}
So, 
L1 ∩ L2 = { aa, aaaa, aaaaaa,.......}

Therefore

RE (L1 ∩ L2) = aa(aa)* which is a regular expression itself

Where
L1  Strings of all possible lengths excluding Null
L2  Strings of even length including Null
L1 ∩ L2 Strings of even length excluding Null
.
16
Property 3. The complement of a regular set is regular.
Proof −
Let us take a regular expression −
RE = (aa)* L = {ε, aa, aaaa, aaaaaa, .......}

L’ = {a, aaa, aaaaa, .....}

Therefore

RE (L’) = a(aa)* which is a regular expression itself.

Where

L Strings of even length including Null


L’ All the strings that is not in L. So, 
(Strings of odd length excluding Null)

17
Property 4. The difference of two regular set is regular.
Proof −
Let us take two regular expressions −
RE1 = a (a*) L1 = {a, aa, aaa, aaaa, ....}
RE2 = (aa)* L2 = { ε, aa, aaaa, aaaaaa,.......}

L1 – L2 = {a, aaa, aaaaa, aaaaaaa, ....}

Therefore

RE (L1 – L2) = a (aa)* which is a regular expression.

Where
L1 =   Strings of all possible lengths excluding Null
L2 = Strings of even length including Null
L1 – L2 (Strings of all odd lengths excluding Null)
18
Property 5. The reversal of a regular set is regular.
Proof −
We have to prove LR is also regular if L is a regular set.
Let, 
L = {01, 10, 11, 10}
RE (L) = 01 + 10 + 11 + 10

LR  = {10, 01, 11, 01}

RE (LR) = 01 + 10 + 11 + 10

which is regular

19
Property 6: The closure of a regular set is regular.
Proof −
If L = {a, aaa, aaaaa, .......} 
(Strings of odd length excluding Null)

i.e.,  RE (L) = a (aa)*

L* = {a, aa, aaa, aaaa , aaaaa,……………} 


(Strings of all lengths excluding Null)

RE (L*) = a (a)*

20
Property 7. The concatenation of two regular sets is regular.
Proof −
Let  RE1 = (0+1)*0
RE2 = 01(0+1)*

Here,  L1 = {0, 00, 10, 000, 010, ......} 


(Set of strings ending in 0)
and  L2 = {01, 010,011,.....} 
(Set of strings beginning with 01)
Then, 

L1 L2 = { 001,0010,0011,0001,00010,00011,1001,10010,.....}
Set of strings containing 001 as a substring which can be
represented by

RE = (0 + 1)*001(0 + 1)*
21
Identities Rules of Regular Expressions :
Given R, P, L, Q as regular expressions, the following identities hold −
1. ∅* = ε
2. ε* = ε
3. RR* = R*R
4. R*R* = R*
5. (R*)* = R*
6. RR* = R*R
7. (PQ)*P =P(QP)*
8. (a+b)* = (a*b*)* = (a*+b*)* = (a+b*)* = a*(ba*)*
9. R + ∅ = ∅ + R = R (The identity for union)
10. R ε = ε R = R (The identity for concatenation)
22
11. ∅ L = L ∅ = ∅  (The annihilator for concatenation)
12. R + R = R  (Idempotent law)
13. L (M + N) = LM + LN  (Left distributive law)
14. (M + N) L = ML + NL  (Right distributive law)
15. ε + RR* = ε + R*R = R*

23
24
Regular Regular Language Regular set
Expression
ϵ L(ϵ) {ϵ}

Ø L(Ø) { }

x L(x) { x}

Y L(y) {y}

x+y L(x+y)=L(x) U L(y) { x,y }

xy L(xy)=L(x). L(y) {xy}

R* L(R*) = (L(R) )* {ϵ, R, RR,RRR,..}

25
26
27

You might also like