Toc Unit 1
Toc Unit 1
Presented By
Dr Saravanan S ME,Ph.D
School of Computing Science and Engineering
VIT Bhopal University, Bhopal
Theory of Automata
• ∑ = {A, B, C, D}
• ∑ = {0, 1, 2}
• ∑ = {0, 1, ....., 5]
• ∑ = {#, β, Δ}
String:
• It is a finite collection of symbols from the alphabet. The string is
denoted by w.
Example 1:
• If ∑ = {a, b}, various string that can be generated from ∑ are {ab,
aa, aaa, bb, bbb, ba, aba.....}.
• A string with zero occurrences of symbols is known as an empty
string. It is represented by ε.
• The number of symbols in a string w is called the length of a string.
It is denoted by |w|.
• Example 2:
w = 010
Number of Sting |w| = 3
Language:
• A language is a collection of appropriate
string. A language which is formed over Σ can
be Finite or Infinite.
• Example: 1
L1 = {Set of string of length 2} = {aa, bb, ba,
bb}
L2 = {Set of all strings starts with 'a'} = {a, aa,
aaa, abb, abbb, ababb}
Finite Automata
→q0 q1 q2
q1 q0 q2
*q2 q2 q2
Types of Automata
Deterministic Finite Automata(DFA)
• DFA refers to deterministic finite automata.
Deterministic refers to the uniqueness of the
computation. 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
Formal Definition of DFA
State 0 1
→q0 q0 q1
q1 q2 q1
*q2 q2 q2
Example 2
→q0 q0, q1 q1
q1 q2 q0
*q2 q2 q1, q2
Example 2
Present State 0 1
State 0 1
Error Message
Types of Compiler
3.semantic analysis
to ensure that the components of a
program fit together meaningfully.
Phases of a Compiler
Source Program
1
Lexical Analyzer
2
Syntax Analyzer
3
Semantic Analyzer
5
Code Optimizer
6
Code Generator
Target Program
Lexical Analysis
• Also called scanning
Scans Input & Identify tokens
Removes White spaces and comments
An Example
Position := initial + rate * 60 ;
The intermediate code should be easy to translate into the target program.
Code Generation
This phase generates the target code consisting of assembly code.
1. Memory locations are selected for each variable;
2. Instructions are translated into a sequence of assembly instructions;
3. Variables and intermediate results are assigned to memory registers.
The Structure of a Compiler
Code Generator
[Intermediate Code Generator]
Tokens
Code Optimizer
Parser
[Syntax Analyzer]
Optimized Intermediate Code
Parse tree
Code Optimizer
Semantic Process
[Semantic analyzer] Target machine code