2. Regular expressions?
Connection between RE and regular languages
Regular grammar
Pumping lemma and non-regular language
grammars
3. A regular expression can also be described as a sequence of
pattern that defines a string.
Regular Expressions are used to denote regular languages.
The language accepted by FA can be easily described by simple
expressions called Regular Expressions.
Regular expressions are used to match character combinations in
strings.
Eg. In a regular expression, x* means zero or more occurrence of
x. It can generate {e, x, xx, xxx, xxxx, .....}
4. The languages accepted by some Regular expressions are referred
to as Regular languages.
A language is regular if it can be expressed in terms of regular
expression.
Eg. L = {a, aa, aaa, ....}
5. The various operations on regular language are:
Union: If L and M are two regular languages then
their union L U M is also a regular language.
1. L U M = {s | s is in L or s is in M}
Kleen closure: If L is a regular language then its
Kleen closure L1* will also be a regular language.
L* = Zero or more occurrence of language L.
6. Intersection: If L and M are two regular languages then their
intersection is also a regular.
Eg. . L ⋂ M = {st | s is in L and t is in M}
Example1:
Write the regular expression for the language accepting all combinations of
a's, over the set ∑ = {a}
Solution:
All combinations of a's means a may be zero, single, double and so on. If a
is appearing zero times, that means a null string. That is we expect the set of
{ε, a, aa, aaa, ....}. So we give a regular expression for this as:
R = a*
7. Example2:
Write the regular expression for the language accepting all the
string containing any number of a's and b's.
Solution:
The regular expression will be:
r.e. = (a + b)*
L = {ε, a, aa, b, bb, ab, ba, aba, bab, .....}
Example3:
Write the regular expression for the language accepting all
the string which are starting with 1 and ending with 0,
over ∑ = {0, 1}.
8. Solution:
In a regular expression, the first symbol should be 1,
and the last symbol should be 0.
The r.e. is as follows:
R = 1 (0+1)* 0
Exercise :
1. Write the regular expression for the language
starting and ending with a and having any having any
combination of b's in between.
9. 2. Write the regular expression for the language starting with
a but not having consecutive b's.
3. Write the regular expression for the language accepting all
the string in which any number of a's is followed by any
number of b's is followed by any number of c's.
10. Regular Expression
Regular Languages
set of vovels ( a ∪ e ∪ i ∪ o ∪ u ) {a, e, i, o, u}
a followed by 0 or more b (a.b*) {a, ab, abb, abbb, abbbb,….}
any no. of vowels followed by any
no. of consonants
v*.c* ( where v – vowels and c –
consonants)
{ ε , a ,aou, aiou, b, abcd…..}
where ε represent empty string
(in case 0 vowels and o
consonants )
11. Grammar is a finite set of formal rules for generating syntactically correct
sentences or meaningful correct sentences.
A Grammar can contain mainly two elements - Terminal and Non Terminal.
Terminal Symbols
It is a portion of the sentence generated by using a grammar.
It is denoted by using small letters, such as a, b, c, d, etc.
Non Terminal Symbols
It takes part in the formation of a sentence, but not part of it.
It is denoted by using capital letters, such as A, B, C, D, etc. It is also
called auxiliary symbols.
12. Grammars denote syntactical rules for conversation in natural
languages.
A grammar is regular if it has rules of form A -> a or A -> aB or A
-> ɛ where ɛ is a special symbol called NULL.
It is accepted by Finite State Automata.
The language it generates is called Regular Language.
Regular languages are closed under operations like Union,
Intersection, Complement etc.
They are the most restricted form of grammar.
13. A grammar G is a 4-tuple
G = (N,Σ,P,S)
N or VN is a set of variables or non-terminal symbols.
T or ∑ is a set of Terminal symbols.
S is a special variable called the Start symbol, S ∈ N
P is Production rules for Terminals and Non-terminals.
A production rule has the form α → β, where α and β are
strings on VN ∪ ∑ and least one symbol of α belongs to VN.
14. Example
Grammar G1 −({S, A, B}, {a, b}, S, {S → AB, A → a, B
→ b})
Here,
S, A, and B are Non-terminal symbols;
a and b are Terminal symbols
S is the Start symbol, S ∈ N
Productions, P : S → AB, A → a, B → b
15. Grammar G2 − (({S, A}, {a, b}, S,{S → aAb, aA →
aaAb, A → ε } )
Here,
S and A are Non-terminal symbols.
a and b are Terminal symbols.
ε is an empty string.
S is the Start symbol, S ∈ N
Production P : S → aAb, aA → aaAb, A → ε
16. Productions are in the form –
V –> VT / T (left-linear grammar) (or)
V –> TV /T (right-linear grammar)
Example:
1. S –> ab.
2. S -> aS | bS | ∊