0% found this document useful (0 votes)
10 views23 pages

Lecture 4

The document discusses finite automata and their implementation for lexical specifications. It defines finite automata, describes their components and provides examples to recognize various regular languages. It also compares non-deterministic finite automata and deterministic finite automata, explaining how NFAs are converted to equivalent DFAs.

Uploaded by

Vedang Chavan
Copyright
© © All Rights Reserved
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)
10 views23 pages

Lecture 4

The document discusses finite automata and their implementation for lexical specifications. It defines finite automata, describes their components and provides examples to recognize various regular languages. It also compares non-deterministic finite automata and deterministic finite automata, explaining how NFAs are converted to equivalent DFAs.

Uploaded by

Vedang Chavan
Copyright
© © All Rights Reserved
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/ 23

CS327 - Compilers

Finite Automata

Abhishek Bichhawat 17/01/2024


Finite Automata
● Implementation of lexical specification (regular language)
● Is a five tuple consisting of:
○ Q - finite set of states inpu
○ Σ - finite set of input alphabet t
○ δ - set of transitions (state →input state)
○ q0 - initial (starting) state
○ F - set of final (accepting) states
Finite Automata
Automaton that accepts only “1” as input

s0 s1
Finite Automata
Automaton that accepts any number of “1”s followed by single “0”
as input 1 0

s0 s1
Finite Automata
Regular language that this automaton recognizes
1
0 0 0, 1

s0 s1 s2

(0|1)*00(0|1)*
Finite Automata
Regular language that this automaton recognizes
1
0 0 0

s0 s1 s2

1
1

(0|1)*00
Finite Automata - ε
● Automata may accept “ε” as input
● Can move from one state to another without consuming input

s0 s1

1
Finite Automata - NFA
● Non-deterministic Finite Automata
○ Multiple transitions from one state for the same input character
○ Can be in set of states after every input
○ Can have ε moves 1

s0 s1 s2

1
Finite Automata - DFA
● Deterministic Finite Automata
○ One transition from one state for an input character
○ Cannot have ε moves
1

s0 s1 s2

0
DFA vs. NFA
● DFA takes only one path per input through the automaton while
NFA can choose out of multiple paths
● NFA accepts if one or more of the multiple paths lead to an
accepting state
● Every DFA is also an NFA (but not vice-versa)
● Both recognize the same set of languages but DFAs are faster
● NFAs may be simpler/smaller than the DFAs
● Space-time tradeoff!
DFA vs. NFA
1
0 0

s0 s1 s2

0
DFA vs. NFA
1
0 0

s0 s1 s2

1
0 0 0
0
s0 s1 s2

1
1
Implementing
Lexical
Specifications
Steps in Conversion

Lexical Regular
Specification Expressions

Non-deterministic
Finite Automata

Lookup Deterministic
Table Finite Automata
NFA for RE

ε ε

c c
NFA for RE

ε ε

c c

R1R2
R1 ε R2
NFA for RE

R1
ε ε
R1 | R2
ε R2 ε
NFA for RE

R1
ε ε
R1 | R2
ε R2 ε

* ε R ε
R
ε
NFA for RE

((ab)*|c)*
NFA for RE
((ab)*|c)*

a ε b

c
NFA for RE
((ab)*|c)*
ε

ε a ε b ε

c
NFA for RE
((ab)*|c)*
ε

ε a ε b ε

ε ε
ε
ε ε
c
NFA for RE
((ab)*|c)*
ε

ε a ε b ε

ε ε
ε
ε ε ε
c

ε
ε

You might also like