Toc (Unit-I)
Toc (Unit-I)
Computation
UNIT-I
BY
V.SRAVANTHI
Theory of Computation
Theory: It includes capabilities ,how a
problem can solved and limitations of
machine
Automata Theory
In general Every machine there will be low
Pus
h
Traffic Light
Example 2 : 2 Level
Elevator
0 1
1
Star
G F
t
0
Example 3 :Word Search
t h e n
t th th then
e
Automata
An automaton (Automata in plural) is an
abstract self-propelled machine which
follows a predetermined sequence of
operations automatically.
Automata derived from Greek word ”Acting
DFA Moore
and
NFA Mealy
NFA with Epsilon Machines
SYLLABUS
UNIT - I
Fundamentals : Strings, Alphabet, Language, Operations, Finite state
machine, definitions, finite automaton model, acceptance of strings, and
languages, deterministic finite automaton (DFA) and non-deterministic
finite automaton (NFA), transition diagrams and Language recognizers.
Finite Automata: NFA to DFA conversion, minimization of FSM,
equivalence between two FSM's, Finite Automata with output- Moore and
Mealy machines.
UNIT - II
Regular Languages: Regular sets, regular expressions, identity rules,
Constructing finite Automata for a given regular expressions, Conversion
of Finite Automata to Regular expressions.
Context Free Grammars: Definition, Ambiguity in context free grammars.
Simplification of Context Free Grammars. Chomsky normal form,
Greibach normal form, Enumeration of properties of CFLs (proofs
omitted), Chomsky's hierarchy of languages.
UNIT - III
Push Down Automata: Push down automata, definition, model, acceptance
of CFL, by final state and by empty stack.
Turing Machine: Turing Machine, definition, model, design of TM, counter
machine, types of Turing machines (proofs not required).
Overview of Compilation: Phases of compilation-lexical analysis, regular
grammar and regular expression for common programming language
features, Pass and phases of translation, interpretation, bootstrapping, data
structures in compilation
UNIT - IV
Top Down Parsing: Back Tracking, LL(1), Recursive Descent Parsing,
Predictive Parsing, Pre-processing steps required for predictive parsing.
Bottom Up Parsing: Shift Reduce Parsing, LR and LALR Parsing, Error
Recovery in Parsing, Handling Ambiguous grammar.
Semantic Analysis: Intermediate forms of source programs-abstract syntax
tree, polish notation and three address codes, conversion of popular
programming languages language constructs into intermediate code forms.
UNIT - V
Code Optimization: Consideration for optimization, scope of
optimization, loop optimization, frequency reduction folding,
DAG representation, reduction in strengths.
Object Code Generation: Object code forms, machine
dependent code optimization, register allocation and
assignment generic code generation algorithms.
TEXT BOOK(S):
1. Introduction to Automata Theory Languages and
Computation, Hopcroft H.E. and Ullman J. D. Pearson
Education, 2002.
2. Principles of Compiler Design, A.V. Aho, J.D. Ullman,
Pearson Education, 1977.
Course Outcomes (COs)
At the end of the course, student would be able to
1. Design mathematical models that recognize different of
languages and carryout computations.
2.Build language generators.
3.Explain the functioning of phases of compilation process and
data structures used in this process.
4.Perform lexical and syntax analysis for high level programs.
5.Generate intermediate code and optimize to prepare the code for
absolute machine code generation.
6.Explain how machine code generation algorithm works and how
compiler efficiently uses various system resources in machine
code generation.
Applications
Design of Compiler
Pattern Matching
Spell Checker
Cryptography
Quantum calculation
Correcting errors in code etc.
UNIT-I
(Fundamentals and
Finite Automata)
Finite Automata
2. Tabular(Transition Table)
q0 is initial state
q1 is intermediate state
q2 is finial state
Transition Table
The transition table is basically a tabular
representation of the transition function. It takes
two arguments (a state and a symbol) and returns
a state (the "next state").
A transition table is represented by the following
things:
Columns correspond to input symbols.
Rows correspond to states.
Entries correspond to the next state.
The start state is denoted by an arrow with no
source.
The accept state is denoted by a star.
Example
→q0 q1 q2
q1 q0 q2
*q2 q2 q2
Language recognizers
A device that accepts valid strings is called the
Language recognizer. For example finite automata
are language recognizer.
Recognizers are Machines. The Machines take a
string as input. The Machines will accept the input if
when run, the Machine stops at an accept state.
Otherwise the input is rejected.
If a Machine M recognizes all strings in Language L,
and accepts input provided by a given string S, M is
said to accept S. Otherwise M is said to reject S. S is
in L if and only if M accepts S.
Another example for language recognizer are PDA’s
(Push Down Automaton)
Automata
DFA Moore
and
NFA Mealy
NFA with Epsilon Machines
DFA (Deterministic finite automata)
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
** Examples: **
Difference between DFA and
NFA
NFA to DFA conversion
There are two ways to convert NFA to DFA
1.Subset Construction
2. Lazy Evaluation
Steps:
Let, M = (Q, ∑, δ, q0, F) is an NFA which accepts the language L(M). There
should be equivalent DFA denoted by M' = (Q', ∑', q0', δ', F') such that
L(M) = L(M').
Steps for converting NFA to DFA:
Step 1: Initially Q' = ϕ
Step 2: Add q0 of NFA to Q'. Then find the transitions from this start
state.
Step 3: In Q', find the possible set of states for each input symbol. If this
set of states is not in Q', then add it to Q'.
Step 4: In DFA, the final state will be all the states which contain F(final
states of NFA)
**Example**
NFA (Non-Deterministic finite automata) with
Episilon
an NFA lambda.
Epsilon (ε) - closure
E closure( B) :{B,C}
E closure( C) : {C}
**Example**
Conversion of Epsilon-NFA to NFA
Step-1: Consider the two vertexes having the epsilon move. Here
in Fig.1 we have vertex v1 and vertex v2 having epsilon move from v1
to v2.
Step-2: Now find all the moves to any other vertex that start from
vertex v2 (other than the epsilon move that is considering). After
finding the moves, duplicate all the moves that start from vertex v2,
with the same input to start from vertex v1 and remove the epsilon
move from vertex v1 to vertex v2.
Step-3: See that if the vertex v1 is a start state or not. If vertex v1 is a
start state, then we will also make vertex v2 as a start state. If vertex
v1 is not a start state, then there will not be any change.
Step-4: See that if the vertex v2 is a final state or not. If vertex v2 is a
final state, then we will also make vertex v1 as a final state. If vertex v2
is not a final state, then there will not be any change. Repeat the
steps(from step 1 to step 4) until all the epsilon moves are removed
from the NFA.
Example
Step 1:
Final step
Step-2:
:**Example**
Conversion from NFA with ε to
DFA
Step 1: We will take the ε-closure for the starting state of NFA as a
starting state of DFA.
Step 2: Find the states for each input symbol that can be traversed
from the present. That means the union of transition value and their
closures for each state of NFA present in the current state of DFA.
Step 4: Repeat Step 2 and Step 3 until there is no new state present in
the transition table of DFA.
Step 5: Mark the states of DFA as a final state which contains the final
state of NFA.
**Examples**
Equivalence between two
FSM's
The two finite automata (FA) are said to be equivalent if both
the automata accept the same set of strings over an input set
Σ.
Let M and M1 be the two FA’s and Σ be a set of input strings.
Step 1 − Construct a transition table that has pairwise
Myhill-Nerode Theorem
Steps :
Create the pairs of all the states involved in the
given DFA.
Mark all the pairs (Q ,Q ) such a that Q is Final
a b a
state and Qb is Non-Final State.
If there is any unmarked pair (Qa,Qb) such a that
Moore machine
Moore machine
Moore machine is a finite state machine in which
the next state is decided by the current state
and current input symbol. The output symbol at
a given time depends only on the present state
of the machine. Moore machine can be
described by 6 tuples (Q, q0, ∑, O, δ, λ) where,
Q: finite set of states
q0: initial state of machine
∑: finite set of input symbols
O: output alphabet
δ: transition function where Q × ∑ → Q
λ: output function where Q → O
Example 1:
The state diagram and Transition Table for Moore
Machine is
Output: 1110(1 for q0, 1 for q1, again 1 for q1, 0 for q2)
2. Design a Moore machine to generate
1's complement of a given binary number .
To generate 1's complement of a given binary
number the simple logic is that if the input is
0 then the output will be 1 and if the input is
1 then the output will be 0. That means there
are three states. One state is start state. The
second state is for taking 0's as input and
produces output as 1. The third state is for
taking 1's as input and producing output as 0.
Hence the Moore machine will be,
**Examples**
Mealy Machine
**Examples**
Conversion from Mealy machine to
Moore Machine
In Moore machine, the output is associated with every state,
and in Mealy machine, the output is given along the edge with
input symbol. To convert Moore machine to Mealy machine,
state output symbols are distributed to input symbol paths. But
while converting the Mealy machine to Moore machine, we will
create a separate state for every new output symbol and
according to incoming and outgoing edges are distributed.
The following steps are used for converting Mealy machine to
the Moore machine:
Step 1: For each state(Qi), calculate the number of different