theory of computation (fall 2014): regular expressions, compiling regular expressions into nfas...

Post on 28-Nov-2014

129 Views

Category:

Science

9 Downloads

Preview:

Click to see full reader

DESCRIPTION

 

TRANSCRIPT

Theory of Computation

Regular Expressions, Compiling Regular Expressions to NFAs & DFAs to Regular Expressions

Vladimir Kulyukin

http://www.vkedco.blogspot.com/

Regular Expressions

Atomic & Compound Regular Expressions

● Regular expressions (RegExps) can be atomic and compound

● Atomic regular expressions consists of one symbol● Compound regular expressions are constructed from atomic

and other compound regular expression with three operations: concatenation, selection (+ or |), Kleene * (zero or more occurrences), and Kleene + (one or more occurrences)

Three Language Operations: Concatenation, Kleene*, Kleene+

.,1|... is then language, a is If

.,0|... is of closure Kleene thelanguage, a is If

. and | languages, theare and If

121

021*

221212121

LxnxxxLL

LxnxxxLLL

LxLxxxLLLL

nin

nin

Four RegExp Operations

● Concatenation: if r1 and r

2 are regular expressions, then r

1r

2 is a concatenation

of two regular expressions such that L(r1r

2) = L(r

1)L(r

2)

● Selection (OR): if r1 and r

2 are regular expressions, then r

1 + r

2 is a regular

expression that denotes the inclusive-OR of two regular (aka known as pipe:

r1 | r

2) so that L( r

1+ r

2) = L(r

1) U L(r

2)

● Kleene*: if r is a regular expression, r* is a regular expression such that

L(r*) = (L(r))* ● Kleene+: If r is a regular expression, r+ is a regular expression such that

L(r+ ) = (L(r))+

Atomic Regular Expressions

L

L

aaLa

ΣrL

r

.3

.2

then , If 1.

:sexpressionregular atomic of typesThree

.alphabet someover

language thedenotes that string a is expressionregular A

Examples: RegExps & Languages

.0|

,...,,, ; expressionRegular

., ; expressionRegular

. ; expressionRegular

**

nba

baaabaababbaLba

cabcabLcab

ababLab

n

Examples: RegExps & Languages

.,...,,,,,,

.,...,,,

.,,,

.,

.,

Language | expressionRegular

****

**

***

aaababbbbaababaLba

abcabcabcabcabcabcabcLabc

bdbcadacdcba

ababLab

babaLba

Compiling Regular Expressions to NFAs

Atomic RegExps NFAs

aa

Generalization: for any symbol in the alphabet, an FA can be constructed that accepts just this symbol

Atomic RegExps NFAs

ε

This FA accepts just the epsilon (empty string)

Atomic Reg Exps NFAs

Here is an FA that accepts the empty set.

Compound RegExps NFAs

:follows as is toingcorrespondNFA then thes,expressionregular these

toingcorrespond NFAs are and wheres,expressionregular are , If

21

2121

rr

RRrr

ε

ε

ε

ε

R1

R2

Example

:follows as is toingcorrespondNFA then thes,expressionregular these

toingcorrespond NFAs are and wheres,expressionregular are , If ba

ba

RRba

ε

ε

ε

ε

a

b

Ra

Rb

Compound RegExps NFAs

:follows as dconstructe becan toingcorrespondNFA an then

NFA, ingcorrespond a is and expressionregular be Let

1

11

r

Rr

ε

ε

εR

1

Compound RegExps NFAs

:follows as testedbecan toingcorrespondNFA an then

, expressionregular a toingcorrespondNFA an be Let *

1

11

r

rR

ε

ε

εR

1

ε

Theorem: RegExps NFAs

languages. same with theNFAslarger into combined

becan sexpressionregular theseon,constructiBy languages. same with theNFAs are

there,hypothesis inductive by the Thus, operators. 1 fewer than have and ,,

that know We.,,, form theof becan Then operators. 1 has

that expressionregular aConsider .for trueisstatement that theAssume .0

for trueis case base .Thein operators ofnumber on theinduction use We:Proof

.such that NFA an is e then ther,expressionregular a is If :Theorem

21

2121*

krrr

rrrrrrqk

qkn

r

rLNLNr

Theorem: DFA RegExps

Theorem: If there is a DFA M then there is a regular expression R such that L(M) = L(R).

Basic Insight: Sweep M left to right and augment to build a regular expression incrementally.

Example

a

b

a | b

Example

a

b

a

b

a+ | b+

Equivalence Constructions

NFA with ε-trans

NFA w/0 ε-trans

DFA

Regular Exps

References

● Brooks Webber. Formal Language: A Practical Introduction, Franklin, Beedle & Associates, Inc

● Davis, Weyuker, Sigal. Computability, Complexity, and Languages, 2nd Edition, Academic Press

● Hopcroft and Ullman. Introduction to Automata Theory, Languages, and Computation, Narosa Publishing House

top related