regular expressions and languages pdf

25
Topic - Regular Expressions Topic - Regular Expressions and Languages and Languages Dilouar Hossain [email protected]

Upload: dilouar-hossain

Post on 14-Apr-2017

91 views

Category:

Engineering


2 download

TRANSCRIPT

Page 1: Regular expressions and languages pdf

Topic - Regular Expressions and Topic - Regular Expressions and LanguagesLanguages

Dilouar [email protected]

Page 2: Regular expressions and languages pdf

Topic ContentsTopic Contents

Regular ExpressionsRegular Expressions

Finite Automata and Regular ExpressionsFinite Automata and Regular Expressions

Applications of Regular ExpressionsApplications of Regular Expressions

Algebraic Laws for Regular ExpressionsAlgebraic Laws for Regular Expressions

Page 3: Regular expressions and languages pdf

Regular Expressions

Md. Tarek Habib3

Regular expressions are language-defining notation

Regular expressions are useful in applications such as text-search applications and compiler components

Page 4: Regular expressions and languages pdf

Regular Expressions…

Md. Tarek Habib4

A FA (NFA or DFA) is a “blueprint" for constructing a machine recognizing regular language.

A regular expression is a “user-friendly," declarative way of describing a regular language.

Example: 01* + 10*Regular expressions are used in

1. UNIX grep command2. UNIX Lex (Lexical analyzer generator) . . .

Page 5: Regular expressions and languages pdf

Operations

5

Page 6: Regular expressions and languages pdf

Building Regular Expressions (regex’s)

6

Page 7: Regular expressions and languages pdf

Example

7

Page 8: Regular expressions and languages pdf

Equivalence of FA’s and regex’s

Md. Tarek Habib8

Page 9: Regular expressions and languages pdf

FA to regex

9

For each accepting state q, apply a reduction process to produce an equivalent automaton with regular-expression labels on the arcs. Eliminate all states except q and the start state q0.

If q ≠ q0, then we shall be left with a two-state automaton that looks like:

Page 10: Regular expressions and languages pdf

FA to regex…

Md. Tarek Habib10

If the start state is also an accepting state, then we must also perform a state-elimination from the original FA that gets rid of every state except the start state. Then we are left with a one-state automaton:

Page 11: Regular expressions and languages pdf

FA to regex…

Md. Tarek Habib11

If there is more than one final state in the original FA, then we must union all the Eq to obtain the final regular expression.

Page 12: Regular expressions and languages pdf

FA to regex Example

Md. Tarek Habib12

Page 13: Regular expressions and languages pdf

FA to regex Example…

13

Page 14: Regular expressions and languages pdf

FA to regex Example…

14

Page 15: Regular expressions and languages pdf

regex to FA

Md. Tarek Habib15

Suppose L = L(R) for a regex R. Then we can design a ε-NFA E such that L(R) = L(E).

E will have:• Exactly one accepting state• No arcs into the initial state• No arcs out of the accepting state

Page 16: Regular expressions and languages pdf

regex to FA…

Md. Tarek Habib16

Page 17: Regular expressions and languages pdf

regex to FA…

17

Page 18: Regular expressions and languages pdf

regex to FA Example

18

Page 19: Regular expressions and languages pdf

Algebraic Laws for Regular Expressions: Commutativity and Associativity

Md. Tarek Habib19

Page 20: Regular expressions and languages pdf

Algebraic Laws for Regular Expressions: Identities and Annihilators

Md. Tarek Habib20

Page 21: Regular expressions and languages pdf

Algebraic Laws for Regular Expressions: Distributive Laws

Md. Tarek Habib21

Page 22: Regular expressions and languages pdf

Algebraic Laws for Regular Expressions: Distributive Laws

Md. Tarek Habib22

Page 23: Regular expressions and languages pdf

Algebraic Laws for Regular Expressions: The Idempotent Law

Md. Tarek Habib23

Page 24: Regular expressions and languages pdf

Algebraic Laws for Regular Expressions: Laws Involving Closures

Md. Tarek Habib24

Page 25: Regular expressions and languages pdf

The End