Unit 1 Part 1_compiler
Unit 1 Part 1_compiler
Unit I – Part 1
1. Finite automation – deterministic
2. Finite automation - non deterministic
3. Conversion of NFA to DFA
4. Minimization of DFA
Reference Book:
Finite Automata
• Finite automata are used to recognize patterns.
• It takes the string of symbol as input and changes its state
accordingly. When the desired symbol is found, then the transition
occurs.
• At the time of transition, the automata can either move to the next
state or stay in the same state.
• Finite automata have two states, Accept state or Reject state. When
the input string is processed successfully, and the automata reached
its final state, then it will accept.
A finite automaton is a collection of 5-tuple (Q, ∑, δ, q0, F), where:
1. DFA
• DFA refers to deterministic finite automata. Deterministic refers to
the uniqueness of the computation. In the DFA, the machine goes to
one state only for a particular input character. DFA does not accept
the null move.
2. NFA
• NFA stands for non-deterministic finite automata. It is used to
transmit any number of states for a particular input. It can accept the
null move.
• Every DFA is NFA, but NFA is not DFA.
• There can be multiple final states in both NFA and DFA.
• DFA is used in Lexical Analysis in Compiler.
• NFA is more of a theoretical concept.
Deterministic Finite Automata (DFA)
• The finite automata are called deterministic finite automata if the
machine is read an input string one symbol at a time.
• In DFA, there is only one path for specific input from the current state
to the next state.
• DFA does not accept the null move, i.e., the DFA cannot change state
without any input character.
• DFA can contain multiple final states. It is used in Lexical Analysis in
Compiler.
A DFA is a collection of 5-tuples same as we described in the definition
of FA.
• Q: finite set of states
• ∑: finite set of the input symbol
• q0: initial state
• F: final state
• δ: Transition function
→q0 q0 q1
q1 q2 q1
*q2 q2 q2
Example 2:
• DFA with ∑ = {0, 1} accepts all starting with 0.
Example 3:
• DFA with ∑ = {0, 1} accepts all ending with 0.
• Example 4:
→q0 q0, q1 q1
q1 q2 q0
*q2 q2 q1, q2
Example:
• NFA with ∑ = {0, 1} accepts all strings with 01.
→q0 q1 ε
q1 ε q2
*q2 q2 q2
Example:
• NFA with ∑ = {0, 1} and accept all string of length atleast 2.
→q0 q1 q1
q1 q2 q2
*q2 ε ε
Design a NFA for the transition table as given below
:
Present State 0 1
State 0 1
→q0 q0 q1
q1 {q1, q2} q1
State 0 1
Step-06: All those states which belong to the same set are equivalent.
The equivalent states are merged to form a single state in the minimal
DFA.
Example 1:
Step-01:
a b
→q0 *q1 q0
*q1 *q2 *q1
*q2 *q1 *q2
Step 3: P0 = { q0 } { q1 , q2 }
Step 4: P1 = { q0 } { q1 , q2 }
a b
Step-01: →q0 q1 q2
The given DFA contains no dead states and inaccessible states. q1 q1 q3
Step-02: q2 q1 q2
Draw a state transition table- q3 q1 *q4
*q4 q1 q2
Step-03: