Lecture 4

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Formal Languages and Compiler

Automata Theory, Abstract Machines,


Finite Automata

Ziaurahman Hikmat

ziaurahman.hikmat1@gmail.com
Nangarhar University Computer Science Faculty

18 October 2023

1 NANGARHAR UNIVERSITY COMPUTER SCIENCE FACULTY


LECTURE OVERVIEW
֎ Automata Theory
֎ Abstract machines
֎ Turing machine
֎ Finite automata
֎ Deterministic Finite Automata
֎ Introduction
֎ Representation of DFA’s
֎ Languages of DFA

NANGARHAR UNIVERSITY COMPUTER SCIENCE FACULTY


WHAT IS AUTOMATA THEORY?
֎ Automata theory also called Theory of computation.
֎ Automata Theory is the study of abstract computing devices or
machines.
֎ An Abstract machine is a theoretical model that allows for a
detailed and precise analysis of how a computer system works.
֎ Alan Turing in 1930’s studied an abstract machine that had all the
capabilities of today’s computers.
֎ Finite automata and certain kinds of formal grammars, are used in
the design and construction of important kinds of software.
֎ Turing machine, helps in understanding what we can expect form
our software.

3 NANGARHAR UNIVERSITY COMPUTER SCIENCE FACULTY


TURING MACHINE

Abstract Turing Machine


Working prototype

4 NANGARHAR UNIVERSITY COMPUTER SCIENCE FACULTY


AUTOMATA EXAMPLE
֎ Simplest finite automation is an on/off switch.
֎ Device remembers whether it is in the ‘on’ state or the ‘off’ state.
֎ It allows user to press a button whose effect is different, depending
on the state of the switch as:
֎ The switch is in the off state, pressing the button changes it to
the on state.
֎ If the switch is in the on state, pressing the same button turns
it to the off state.

5 NANGARHAR UNIVERSITY COMPUTER SCIENCE FACULTY


FINITE AUTOMATA
֎ Finite Automat: automation having a set of states, and controls which
moves from state to state in response to some external input.
֎ Regular languages are described using finite automata Classified
based on the determinism of the control movement
֎ Deterministic (DFA): the automaton cannot be in more than one
state at any one time.
֎ Non-Deterministic (NFA): it may be in several states at once.

6 NANGARHAR UNIVERSITY COMPUTER SCIENCE FACULTY


DFA AND NFA

DFA Start S0 S2
S1

S1 S2

NFA Start
S0

S3 S4

7 NANGARHAR UNIVERSITY COMPUTER SCIENCE FACULTY


DETERMINISTIC FINITE AUTOMATA
֎ In DFA no two edges leaving from same state are labeled with the
same symbol.
֎ It follows:
֎ Starting from the start state, automation follows exactly one
path (edge) to get to the next state.
֎ The edge has to be labeled with the input character After making
n transitions for n long character string, if the automaton is in the
final state, it accepts the string otherwise rejects.

8 NANGARHAR UNIVERSITY COMPUTER SCIENCE FACULTY


FORMAL DEFINITION OF DFA
A Deterministic Finite Automata, DFA for short, is a tuple:
A = (S, V, δ, s0, F):
֎ S is a finite non empty set of states;
֎ V is the input symbol alphabet;
֎ δ : S × V → S is a total function called the Transition Function;
֎ s0 ∈ S is the initial state;
֎ F ⊆ S is the set of final states.

9 NANGARHAR UNIVERSITY COMPUTER SCIENCE FACULTY


TRANSITION FUNCTION
֎ Takes two arguments: a state and an input symbol.
֎ δ( q ,a ) = the state that the DFA goes to when it is in state q and an
input a is received.

Representation of DFA
֎ Graph representaiton
֎ Transition table

10 NANGARHAR UNIVERSITY COMPUTER SCIENCE FACULTY


GRAPH REPRESENTATION OF DFA
֎ Nodes = states
֎ Arcs represent transition function
֎ Arc from state p to state q labeled by all those input symbols
that have transitions from p to q
֎ Arrow labeled ‘Start’ to the start state
֎ Final states indicated by double circles

11 NANGARHAR UNIVERSITY COMPUTER SCIENCE FACULTY


DFA REPRESENTATION USING TRANSITION TABLE
֎ Let us consider D1 = (S ={q1,q2,q3},V ={0,1},δ, SS = q1, FS ={q1,q2})
then:

0 1
*q1 q1 q2
*q2 q1 q3
q3 q3 q3

12 NANGARHAR UNIVERSITY COMPUTER SCIENCE FACULTY


EXAMPLE: GRAPH OF DFA
String 101 is in the language of the DFA below
Start at q1

13 NANGARHAR UNIVERSITY COMPUTER SCIENCE FACULTY


EXAMPLE: GRAPH OF DFA
String 101 is in the language of the DFA below
Follow arc labeled 1

14 NANGARHAR UNIVERSITY COMPUTER SCIENCE FACULTY


EXAMPLE: GRAPH OF DFA
String 101 is in the language of the DFA below
Then arc labeled 0 from current state q2

15 NANGARHAR UNIVERSITY COMPUTER SCIENCE FACULTY


EXAMPLE: GRAPH OF DFA
String 101 is in the language of the DFA below
Then arc labeled 1 from current state q1

Finally arc labeled 1 from current state (q1). Result is an accepting state (q2),
so 101 is in the language.

16 NANGARHAR UNIVERSITY COMPUTER SCIENCE FACULTY


LANGUAGES OF DFA
֎ The language of our example DFA is:
{w | w is in {0,1} and w does not have two consecutive 1’s}

17 NANGARHAR UNIVERSITY COMPUTER SCIENCE FACULTY


REFERENCES
Alfred V. Aho, Monica S. Lam, Ravi Sethi and Jeff Ullman. (2007)
Compilers: Principles, Techniques, and Tools , 2nd Edition
J.E. Hopcroft, R. Motwani, J.D. Ullman. (2007)
Introduction to Automata Theory, Languages, and Computation, 3rd
Edition

18 NANGARHAR UNIVERSITY COMPUTER SCIENCE FACULTY


THIS IS ENOUGH!
Any questions?
Suggestions?

19 NANGARHAR UNIVERSITY COMPUTER SCIENCE FACULTY

You might also like