0% found this document useful (0 votes)
52 views33 pages

Deterministic Finite Automata: - A Deterministic Finite Automata (DFA, For Short) Is A Special Case of NDFA in Which

This document discusses deterministic finite automata (DFAs) and how they are used to represent regular expressions and perform lexical analysis. It contains the following key points: - A DFA is a special type of finite automaton where each state has at most one transition for each input symbol. This makes DFAs easy to implement. - Nondeterministic finite automata (NFAs) can be converted to equivalent DFAs using the subset construction algorithm. This involves computing -closures of states to determine the new states. - Regular expressions can be represented by NFAs and converted to equivalent DFAs. This is useful for applications like lexical analysis in compilers. - The document provides examples of converting

Uploaded by

mdhuq1
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views33 pages

Deterministic Finite Automata: - A Deterministic Finite Automata (DFA, For Short) Is A Special Case of NDFA in Which

This document discusses deterministic finite automata (DFAs) and how they are used to represent regular expressions and perform lexical analysis. It contains the following key points: - A DFA is a special type of finite automaton where each state has at most one transition for each input symbol. This makes DFAs easy to implement. - Nondeterministic finite automata (NFAs) can be converted to equivalent DFAs using the subset construction algorithm. This involves computing -closures of states to determine the new states. - Regular expressions can be represented by NFAs and converted to equivalent DFAs. This is useful for applications like lexical analysis in compilers. - The document provides examples of converting

Uploaded by

mdhuq1
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Deterministic Finite Automata

A Deterministic finite automata (DFA, for short) is a special case of NDFA in which
No state has e transition For each state s and an input symbol a, there is at most one edge labeled a leaving s

Simulating a DFA:

DFA is easy to implement

Conversation of an NFA into A DFA

Example

Computation of Substates
e-closure A = {0,1,2,4,7} e-closure move(A,a)) e-closure({3,8}) B= { 1,2,3,4,6,7,8} ie Dtran[A,a] = B
Dtran[A,b] e-closure({5])= {1,2,4,5,6,7}=C Five different states are A = { 0,1,2,4,7 } D = { 1,2,4,5,6,7,9 } B = { 1,2,3,4,6,7,8 } E = { 1,2,4,5,6,7,10 } C = { 1,2,4,5,6,7 }

Translating Regular Expressions into Finite Automata


Regular expressions are equivalent to FAs The main job of a scanner generator
To transform a regular expression definition into an equivalent FA

A regular expression

Nondeterministic FA

Deterministic FA

minimize # of states Optimized Deterministic FA

Regular Exp to an NFA


Step1: parse r into its constituent subexpressions Step2: Use rules to construct NFAs

For the regular expression st

For the regular expression S*

Example
Construct an NFA for regular expression (a|b)*abb

For r1

For r2

NFA for r3 = r1 | r2

NFA for (r3)*

NFA for r5r6

Construct an NFA for Regular Expression 01*|1

01*|1 (0(1*))|1

1*

start

01*

start

1
0 1

01*|1 start

Another Example (D*\.D|D\.D*)


D
a 0 b 2 0 D 1


1 3

1 3

d 2 0 D

1 3

. 4

D 5

2 0 D 1 3 . 4 D 5

12

6
D

13

10

D
9

11

0 14

Converting an NFA to a DFA


-closure ({12})= {1,3,4,5,12} (new DFA State 0)

Move({1,3,4,5,12},D} = {2,8} (new DFA State 1)

Move({1,3,4,5,12},.} = {6}
DFA State 2 = {6}
-closure ({6})= {6}

(new DFA State2)

Move({6},.} =

Move({6},D} = {7}

(new DFA State3)

DFA State 1 = {2,8} -closure ({2,8})= {1,2,4,8}

Move({1,2,4,8},D} = {2} (new DFA State4)

Move({1,2,4,8},.} = {6,10}
DFA State 3 = {7} -closure ({7})= {7,13,14}

(new DFA State5)

Move({7,13,14},D} =

Move({7,13,14},.} =

DFA State 4 = {2}


-closure ({2})= {1,2,4}

Move({1,2,4},D} = {2} (Existing state 4)

Move({1,2,4},.} = {6} (Existing state 2)


DFA State 5 = {6,10} -closure ({6,10})= {6,9,10,13,14}
Move({6,9,10,13,14},.} =

Move({6,9,10,13,14},D} = {7,11} (New DFA

state 6)

DFA States 3 and 5 are accepting states because their e-closure sets contain the an accepting state (NFA state 14)

DFA State 6 = {7,11}


-closure ({7,11})= {7,9,11,13,14}

Move({7,9,11,13,14},.} =

Move({7,9,11,13,14},D} = {11} (new DFA state 7)


DFA State 7 = {11} -closure ({11})= {9,11,13,14} Move({9,11,13,14},.} =

Move({9,11,13,14},D} = {11}

(Existing DFA state 7)

DFA for NFA


D

2 . 4
D

D
D . D

D 5 6
D 7

2 . 4

Minimizing D
3

D
D .

D 5

Exercises:
1. Write a lexical analyzer that processes the PL/1 statement
if then then then = else ; else else else = then;

2. Write a regular expression that recognizes all possible integer constants in C 3. Write a regular expression that recognizes a C identifier. Construct an NFA to this expression, convert into DFA and minimize

Exercises:
Page 147 3.6 3.7 & 3.11

You might also like