Objectives: o Symbol Used in Regular Expression o Rules To Build Regular Expression o Examples Regular Languages

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Tahir Naseem/Handout 7

-1-

Theory of Automata and Formal Languages

Lecture 7
Objectives
Regular Languages
Regular Expression
o Symbol Used in Regular Expression
o Rules to Build regular Expression
o Examples
Regular Languages

All those languages are regular for which we can write regular expression

Symbol Used in Regular Expression

Letter of alphabet

Symbol for Null string

Parenthesis ( )
o To concatenate multiple regular expressions

Star Operator *
o * operator is used to 0 to n times repetition.

Plus Operator +
o + operator is used to provide option to select from two choices.

Rules to Build Regular Expression


1. Every letter of can be made into regular expression by writing it in bold face;
2. If r1 and r2 are regular expressions then
a. (r1) also a regular expression

Tahir Naseem/Handout 7

-2-

Theory of Automata and Formal Languages

b. (r1)(r2) is also a regular expression


c. r1 + r2 is also a regular expression
d. r1* is also a regular expression
3. Nothing else is a regular expression
4. r1+ is not mentioned in rules because it can be converted into r1* as
a. r1+ = (r1)(r1)*
Example1:
Language having words of length 1 over = { a b}

There can be only two words ( a and b) of 1 length over given alphabet set then can be
generated occurrence of a or b.

So there is a choice between a and b.


o According to rule 1 a and b are regular expression (r1 and r2)

According to rule 2c we get the following regular expression


R.E = a+b

Example2:
Language having words {aa, bb} over = { a b}

aa can be generated occurrence of a twice and can be generated by using rule 1 and
2b.

Similarly for bb

Now there is a choice between aa and bb.

According to rule 2c we get the following regular expression


R.E = aa+bb

Example3:
Language
{, a, aa, aaa, aaaa }
over = { a b}

Tahir Naseem/Handout 7

-3-

Here a is repeating itself 0 to n times

So rule 1 and 2d will be executed

Theory of Automata and Formal Languages

R.E = a*
Example4:
Language
{, b, bb, bbb, bbbb }
over = { a b}

Here b is repeating itself 0 to n times

So rule 1 and 2d will be executed


R.E = b*

Example5:
Language
{b, ab, aab, aaab, aaaab, aaaaab, }
over = { a b}

Here a is repeating itself 0 to n times and then b appear at the and

So rule 1, 2b and 2d will be executed


R.E = a*b

Example6:
Language
{b, ab, aab, aaab, aaaab, aaaaab, }
over = { a b}

Here a is repeating itself 0 to n times and then b appear at the and

So rule 1, 2b and 2d will be executed


R.E = a*b

Tahir Naseem/Handout 7

-4-

Theory of Automata and Formal Languages

You might also like