You are on page 1of 10

Compiler

Noor wali Khan


UOCH
Types of FA.

• There are TWO types of FA.


• Non-Deterministic Finite Automata (NFA).
• Deterministic Finite Automata (DFA).

2
Non-Deterministic Finite Automata (NFA).
• Consider the FA.
• In this FA two edges
a 4
coming out of the same
state to have exactly the
3 same label.
•The two edges are leading
a 5 to the different states.

• Similarly its equivalent is: • This FA contains ε -


transition from state 3
to 2.
a 4
• ε - transition is
nothing but just a jump
3 form one state to
a another state.
ε 2 5

3
Non-Deterministic Finite Automata (NFA).

• When a state can make transition to more than one states on the
same input symbol, we say that this machine is nondeterministic.
• Because it cannot determine to which it should make the transition
next.
• But, a NFA (nondeterministic finite automata) is able to be in several
states at once.
• Another way to think of the NFA is that it travels all possible paths, and so it
remains in many states at once. As long as at least one of the paths results in
an accepting state, the NFA accepts the input.

4
NFA Example. 0,1

• This NFA accepts only 0 1


Start q0 q1 q2
those strings that end in 01

q0

1 q0

1
q0
0

• Running in “parallel q0 q1 - stuck


0

threads” for string 1


q0 q1

1100101 q0 q2 - stuck
0

q0 q1
1

q0 q2 - accept

5
Formal Definition of FA.

• Similar to FA a Nondeterministic Finite Automata (NFA) is a collection of the following


things:
• A finite set of states, typically Q.
• One state is the start/initial state, typically q0 such that:
q0  Q
• A subset of Q is called the final states.
FQ
• An finite set of alphabet ∑ = { x1, x2, x3, ----- xn }.
• A finite set of transitions that describes how to proceed from each state to other states along edges
labeled with letters of the alphabet.
• There is the possibility of more than one edges with the same label from any state.
• Some of the edges can be labeled with the ε – transition (empty).
• Therefore NFA can be represented as:
NFA = (Q, S, F, ∑ ,)
6
Example.
2
a
a 3
1
a
a 4

Is equivalent to.

2 3 4
a a a
ε ε ε a
1 6 7 8 5

7
NFA for Sequence.

• Sequence is a single alphabet “a” etc.


start a
1 2

start ε a ε
1 2 3 4

8
NFA for Alternation.

• Alternation is ( a | b ).
b

start
1 2

b
ε 2 4 ε

start 1
6

ε a ε
3 5

9
NFA for Kleene Closure.
• Keleen Closure is ( a | b )*.ε
b
start 1 2
a
ε ε

b
ε 2 4 ε

start 1
6

ε a ε
3 5

ε
10

You might also like