SlideShare a Scribd company logo
1 of 89
1
AUTOMATA THEORY- GRAMMAR,
LANGUAGES
&
FINITE STATE MACHINES
2
• Terminologies of TOC
• Languages
• Grammar
• Noam Chomsky hierarchy
• Parse Tree
• BNF Notation
• Finite automation
• Regular Expressions
• Theory of Automata
• DFA & NFA
• Pumping lemma
• Languages which are not Regular
• FSM with Output
• Turing Machine
3
Terminologies of TOC
• Alphabet – finite set of symbols
– denoted by Σ.
Examples :
Σ = {a,b, c,…, z}
Σ = {0, 1}
Σ = {a}
Σ = {ε}
Σ = ø
4
Terminologies of TOC
• String (word) – Finite sequence of symbols from an
alphabet., usually denoted by w.
Ex: English is a string from Σ = {a,b, c,…, z}
01110 is a string from Σ = {0,1}
• Empty string – String with no symbols
ε or e
5
Terminologies of TOC
• Length of a string w, denoted by |w| - is the number of
symbols in a string.
Eg:
|abc| = 3
|b| = 1
|ε| = 0
|ababxyz| = 7
6
Terminologies of TOC
• Substring – string contained in a string
Eg: a,ab,abc, ε are substrings of string abc
• A string may have many occurrences of the same substring, Ex:
abababc contains the substring ab three times
• If w is a string then
– W 0
= ε
– W 1
= w
– W 2
= w w …
– W i+1
= w i
w
7
String Operations
1. Concatenation:
- binary operator
- concatenation of x and y, denoted by xy or x y∘ , is the string x followed by y
- Eg: dog house∘ => doghouse
abc ε => abc∘
2. Reversal:
- unary in nature
- denoted by w R
, is the string w spelled backwards
- Eg: (top) R
= pot
8
Terminologies of TOC
• (Formal) Language – set of strings over an alphabet, Σ, ie. any subset of Σ *
is
called a language.
Eg: If Σ = {0,1}, then
- L1= {0, 1, 00, 11} is a language
- L2= set of palindromes is a language, ie
- L2= {ε, 0, 1, 00, 11, 010, 101,…}
- Σ *
, {ε}, Ø
• A language may be finite or infinite
• Infinite language is written as L = { w Є Σ *
: w has property P}
Eg: L = { w Є {0,1} *
; w has equal number of 1’s and 0’s}
9
Operations on Languages
If L, L1, L2are languages over Σ
1. Union
L = L1U L2
1. Intersection
L = L1∩ L2
1. Complement
Lc=
Σ* - L
1. Concatenation
L = L1.L2 = {w : w = x.y, for some x Є L1 and y Є L2}
1. Closure (Kleen closure)
L* = L0
U L1
U L2
U…
1. Positive closure
L+
= L* - ε, L+
= L L*
10
Regular Expressions
A Regular Expression is a string that is used to describe or match a
set of strings, according to certain syntax rules.
Eg: 0* = {ε, 0, 00, 000,…}
0+1 = {0, 1}
01 = {01}
ab(a+b) = {aba, abb}
a(c+ d) b = {acb, adb}
a*b = {ε, a, aa, aaa, …} b = {b, ab, aab, aaab, …}
Regular Language – Language generated by a regular expression.
11
Regular Expressions
Operation Symbol Example Regular Expression
concatenation ab ab
[a-c][AB] aA aB bA bB cA CB∪ ∪ ∪ ∪ ∪
Kleene star * [ab]* (a b)*∪
disjunction | [ab]*|A (a b)* A∪ ∪
zero or more + a? (a λ)∪
one character . a.a a(a b)a if Σ={a,b}∪
n times {n} a{4} aaaa=a⁴
n or more times {n,} a{4,} aaaaa*
n to m times {n,m} a{4,6} aaaa aaaaa aaaaaa∪ ∪
#> man grep
12
Regular Expressions
• Describe the following sets by regular expression
(1) {ε, a, aa, aaa, …}
a*
(2) {01,10}
01+10
(3) {01,011,0101}
01+011+0101 = 01(ε+1+01)
(4) Strings that end with a over Σ ={a, b}
(a+b)*a
(5) Strings of 0’s and 1’s containing 00 as substring
(0+1)*00(0+1)*
(6) Strings of 0’s and 1’s beginning with 0 and ending with 1
0(0+1)*1
(7) L= {ε, 11, 1111, 111111, …}
(11)*`
13
Noam Chomsky described the languages into
four classes, namely
• Type 0 Language (Recursively Enumerable
Language)
• Type 1 Language (Context Sensitive Language)
• Type 2 Language (Context Free language)
• Type 3 Language (Regular Language)
14
Grammar
Generates strings in language by a process of replacing symbols
• Similar to regular expressions.
Four elements.
• Terminal symbols:
characters in alphabet – denote by 0 or 1 for binary alphabet.
• Nonterminal symbols:
local variables for internal use – denote by <name>.
• Start Symbol: one special nonterminal.
(analogous to start state in FSA)
• Production rules:
replacement rules – denote by <A> c => <D> b <B>
A Familiar Example
Terminals: horse, dog, cat, saw, heard, the
Nonterminals: <sentence>, <subject>, <verb>, <object>
Start Symbol: <sentence>
Production rules: <sentence> => <subject> <verb><object>
<subject> => the horse
<subject> => the dog
<subject> => the cat
<object> => the horse
<object> => the dog
<object> => the cat
<verb> => saw
<verb> => heard
Some Strings: the horse saw the dog
the dog heard the cat
the cat saw the horse
Generating a String in Language
Start with the start Symbol.
<sentence>
Generating a string in language:
<sentence>
Generating a String in Language
Start with the start Symbol.
Use any applicable production rule.
<sentence> => <subject> <verb> <object>
Generating a string in language:
<sentence> => <subject> <verb> <object>
Generating a String in Language
Start with the start Symbol.
Use any applicable production rule.
<sentence> => <subject> <verb> <object>
Generating a string in language:
<sentence> => <subject> <verb> <object>
=> the horse saw the dog
the horse saw the dog
The C Language Grammar
Terminals:
if do while for switch break continue typedef struct return main int
long char float double void static ; ( ) a b c A B C 0 1 2 + * - / _
# include += ++ …
Nonterminals:
<statement> <expression> <C source file> <identifier> <digit> <nondigit>
<identifier> <selection-statement> <loop-statement>
Start symbol:
<C source file>
A String:
#include <stdio.h>
int main(void) {
printf(“Hello World!n”);
return 0;
}
The C Language: Identifier
Production Rules:
<identifier> => <nondigit>
=> <identifier> <nondigit>
=> <identifier> <digit>
<nondigit> => a | b | … | Y | Z | _
<digit> => 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
Some identifiers:
x
f
temp
temp1
done
_CanStartWithUnderscoreButNor7
The C Language: Expressions
Production rules:
<expression> => <identifier>
=> <constant>
=> <cond-expression>
=> <assign-expression>
<cond-expression> => <expression> > <expression>
=> <expression> != <expression>
<assign-expression> => <expression> = <expression>
=> <expression> += <expression>
Some expression:
• x
• x > 4
• done != 1
• x = y = z = 0
• x += 2.0
This grammar also considers 4 = x a
valid expression
The C Language: Statements
Production rules:
<statement> => <select-statement>
=> <loop-statement>
=> <compound-statement>
=> <express-statement>
<select-statement> => if (<expression>)
=> if (<expression>) <statement>
else <statement>
<loop-statement> => while (<expression>) <statement>
=> do <statement> while (<expression>)
<express-statement> => <expression>;
A Statement:
while (done != 1)
if(f(x) > 4.0)
done = 1;
else
x += 2.0;
Grammar
In practice, need to write out grammar for C.
• Compiler check to see if your program is a
valid “string” in the C language.
• The C Standard formalizes what it means to
be a valid ANSI C program using grammar
• Compiler implementation: simulate FSA and
PDA machine to recognize valid C
programs.
Type III Grammar (Regular)
Limit production rules to have exactly one nonterminal on LHS and at most
one nonterminal and terminal on RHS.
<A> => <B> a
<A> => <A> b
<B> => c
<C> => ϵ
Example:
<A> => <B> 0 Start = <A>
<B> => <A> 1
<A> => ϵ
String generated:
ϵ, 10, 1010, 101010, 10101010, …
Grammar GENERATES language = set of all strings derivable from
applying production rules.
Type II Grammar (Context Free)
Limit production rules to have exactly one
nonterminal on LHS, but anything on RHS.
<A> => b <B> <C> a <C>
<A> => <A> b c a <A>
Example:
<PAL> => 0 <PAL> 0 Start = <PAL>
=> 1 <PAL> 1
=> 0
=> 1
=> ϵ
String generated:
ϵ, 1, 0, 101, 001100, 111010010111, …
Type II Grammar (Context Free)
Example:
<S> => ( <S> ) Start = <S>
=> { <S> }
=> [ <S> ]
=> <S> <S>
=> ϵ
String generated:
ϵ, (), ()[()], (([]{()})[](())), …
Type I Grammar (Context Sensitive)
Add production rules of the type:
[A] <B> [C] => [A] a [C]
where [A] and [C] represent some fixed
sequence of nonterminals and terminals.
<A> <B> <C> => <A> b <C>
<A> hi <B> <C> => <A> hib <C> <D>
Type 0 Grammar (Recursive)
No limit on production rules: at least one nonterminal on LHS.
Example:
Start = <S>
<S> => <S> <S> <A><B> => <B><A>
<S> => <A> <B> <C> <B><A> => <A><B>
<A> => a <A><C> => <C><A>
<B> => b <C><A> => <A><C>
<C> => c <B><C> => <C><B>
<S> => ϵ
Strings Generated:
ϵ, abc, aabbcc, cabcab, acacacacacabbbbbb, …
Chomsky Hierarchy
Type Machin
e
Gramm
ar
III Finite State
Automata
Regular
II Push Down
Automata
Context Free
I Least Bound
Automata
Context
Sensitive
0 Turing
Machine
Recursive
Powerful
Machines
Expressive
Languages
Essential one-to-one correspondence between machine and languages.
30
All Languages
Chomsky Hierarchy
Regular Language
Context Free Language
Context Sensitive Language
Recursively Enumerable Language
FSA and Type III Equivalence
FSA’s and Type III grammar are equally powerful.
• Given an FSA, can construct Type III grammar to generate same
language.
• Given Type III language, can construct FSA that accepts same language.
Proof Idea:
FSA Type III Grammar
Start state Start symbol
States Nonterminals
Transition arcs Production rules:
<A> => <B> a
Accept state Production rules: <A> => a
Compilers and Grammar
Compiler: translates program from high-language to native
machine language.
Three basic phases.
• Lexical analysis (tokenizing).
– convert input into “tokens” or terminal symbols
– # include <stdio.h> int main ( void ) { printf ( “Hello
World!n” ) ; return 0 ; }
– implement with FSA
– Unix program lex
Compilers and Grammar
Compiler: translates program from high-language to native
machine language.
Three basic phases.
• Lexical analysis (tokenizing).
• Syntax analysis (parsing).
– implemented using pushdown automata since C language is (almost)
completely described with context-free grammar
– Unix program yacc
Compilers and Grammar
Compiler: translates program from high-language to native
machine language.
Three basic phases.
• Lexical analysis (tokenizing).
• Syntax analysis (parsing).
• Code generation.
– parse tree gives structure of computation
– traverse tree in postorder and create native code
-
*
a d
+
+
cb
e
Parse tree for expression:
(a * (b + c)) – (d + e)
35
Theory of Automata
• Dictionary defines Automaton as a machine/mechanism that
operates as per encoded instructions.
• Theory of Automata deals with the study of automata (machines),
their states, and state transitions with respect to functions, without
human intervention ie., as per encoded instructions.
36
Major Automata categories:
• Finite Automata
– Deterministic Finite Automata (DFA)
– Non-Deterministic Finite Automata (NFA)
• Pushdown Automata
– Deterministic Pushdown Automata
– Nondeterministic Pushdown Automata
• Turing Machine
Increasing
order of
functions
37
Deterministic Finite Automata(DFA)
• A DFA consists of a finite set of states and a set of
transitions from state to state that occur on input symbols
chosen from an alphabet ∑.
38
DFA
• Formal Definition:
DFA A= (Q, ∑,δ, q0, F), where
Q is a finite set of states,
∑ is a finite input alphabet
q0 Є Q is the initial state
F Є Q is the set of final states
δ is the transition function mapping Q X ∑ to Q
39
DFA
Draw the DFA for ,D= (Q, ∑,δ,S, F), when Q = {q0,q1}, ∑ = {a,b}, S =
q0,F = {q1} and δ is given by
a b
q0
*q1
q0 q1
q1 q0
δ
a
q0 q1
b
b
a
Start
40
DFA
Draw DFA for {w : w is of the form x01y, for some x,y Є {0,1}}
So,
Q = {q0,q1,q2}
∑ = {0,1}
S = q0
F = {q2}
0 1
q0
q1
* q2
q1 q0
q0
q2
q2
q2
δ
1
0
0,1
q0 q20 q
1
1Start
41
DFA
Give DFA for the set of all strings ending in 00, over the alphabet
∑ = {0,1}
So,
Q = {q0,q1,q2}
∑ = {0,1}
S = q0
F = {q2}
0 1
q0
q1
* q2
q1 q0
q2
q2
q0
q0
δ
q0 q2
1
q
1
0
1
0
Start
1
42
DFA
• Language accepted by a DFA is called Regular language.
• DFA is an FA with determinism.
• Determinism means for any DFA there will be one and
only one transition from every state for every symbol of ∑
43
NonDeterministic Finite Automata(NFA)
• NFA is an FA showing Nondeterminism.
• A NFA can be different from a DFA in that
– for any input symbol, nondeterministic one can transit
to more than one states.
– for any input symbol, nondeterministic one may not
transit to another state
44
NFA
• Formal Definition:
NFA A = (Q, ∑,δ, q0, F), where
Q is a finite set of states,
∑ is a finite input alphabet
q0 Є Q is the initial state
F ⊂ Q is the set of final states
δ is the transition function mapping Q X ∑* -> Q
45
NFA
This diagram represents an NFA which accepts strings
ending in 01, ie., (0+1)*01
q0 q2
0,1
0
q
1
1
Start
0 1
46
NFA
• Corresponding Transition Diagram
{q0}
{q0,q1}
{q0,q2*}
{q0,q1} {q0}
{q0,q1} {q0,q2}
{q0,q1} {q0}
0 1
47
Equivalence of DFA and NFA
• For every NFA there exists a DFA which simulates the
behavior of NFA
• Language accepted by NFA will be equal to that
accepted by DFA.
• Language accepted by NFA is regular language.
48
How to construct Equivalent DFA for an NFA
(1) Construct a DFA which accepts strings ending
in 01
NFA
q0 q20 q
1
1
0,1
49
Transition Diagram
• Q = {q0,q1,q2}
• ∑ = {0,1}
• S = {q0}
• F = {q2}
{q0}
{q0,q1}
{q0,q2*}
{q0,q1} {q0}
{q0,q1} {q0,q2}
{q0,q1} {q0}
0 1
B
A
C
50
DFA
A C0 B 1
1
1 0 0
51
How to construct Equivalent DFA for an NFA
• (2) Construct an NFA which accepts 0(0+1)*1 and then
convert it into corresponding DFA
NFA:
q0 q20 q
1
1
0,1
52
Transition Diagram ( for 0(0+1)*1 )
• Q = {q0,q1,q2}
• ∑ = {0,1}
• S = {q0}
• F = {q2}
{q0}
{q1}
{ }
{q1,q2*}
{q1} { }
{q1} {q1,q2}
{ } { }
{q1} {q1,q2}
0 1
B
A
C
D
53
DFA
A D0 B 1
C
0,1
0
1
0
1
54
Finite Automata with Epsilon transitions
• NFAs are sometimes allowed to have a transition accepting
ε string.
• Such NFAs are called FA with ε transition.
q1q0
εStart
55
Equivalence relations
DFA NFA with ε
RE
NFA
56
Equivalence of RE and FA
• Every language defined by a regular expression is also
defined by a finite automaton.
• In other words, there exists a finite automaton for every
regular expression.
57
Equivalence of RE and FA
(trivial cases)
Let R be a regular expression, L(R) be the language generated by R, then
• L(R) = {ε}, R = ε
• L(R) = Ø
• L(R) = L(a) = {a}, R= a
ε
a
Start
Start
Start
58
Equivalence of RE and FA
Let R and S be regular expressions, then:
1. Let M = R+S, then L(M) =L(R) U L(S)
ε
ε
ε
ε
S
R
Start
59
Equivalence of RE and FA
1. Let M = R.S, then L(M) =L(R)L(S)
R Sε
Start
60
Equivalence of RE and FA
R
3. Let M = R*, then L(M) =L(R)UL(R)UL(R)UL(R)…
ε ε
ε
ε
Start
61
Example
Convert the RE = (0+1)*1(0+1) to an ε-NFA
ε0
ε
ε
ε
1
ε
ε
ε
ε
ε ε
εε
1
0
1ε
ε
62
Algebraic laws for Regular Expressions
If L, M, N are 3 regular expressions, then
1. Commutative Law for Union – L +M = M + L
1. Associative Law for Union – (L+M) + N = L + (M + N)
1. Associative Law for concatenation – (LM)N = L(MN)
63
Algebraic laws for Regular Expressions
 Ø + L = L + Ø = L, Ø is the identity for union.
 εL = L ε = L , ε is the identity for concatenation.
 ØL = LØ = Ø, Ø is the annihilator for concatenation.
64
Algebraic laws for Regular Expressions
1. Distributive Law –
L(M+N) = LM + LN
(M+N) L = ML + NL
1. Idempotent law -
L + L = L
1. Laws involving closures –
(L*)* = L*
Ø* = ε
ε* = ε
65
Common Regular Expression Rules
If P, Q ,R are regular expressions, then
(1) (PQ)*P = P(QP)*
(2) R*R* = R*
(3)If R = Q + PR, then R = QP* (Arden’s theorem)
(4) (P+Q)* = (P*Q*)*
66
Pumping Lemma (for Regular Languages)
• Not every language is a regular language
Eg: L01 = {0n
1n
| n>= 1}
• L01is a language that consists of the strings comprising n number of
zeroes followed by n number of ones.
• If there is an FA which accepts L01then it should,
- accept n number of zeroes from start state
- remember n, so that it can accept exactly n number of ones
- accept n number of ones and reach the final state.
• But FA lacks the capability to remember value n (lacks memory), so
cannot accept L01.
• L01cannot be accepted by any FA => L01is not regular => there exists
languages which are not regular.
67
Pumping Lemma (for Regular Languages)
(The pumping lemma for regular languages) Let L be a
regular language. Then there exists a constant n (which
depends on L) such that for every string w in L such that
|w | ≥ n, we can break w into three strings, w=xyz, such that
1) y != ϵ
2) |xy | < n.
3) For all k ≥ 0, the string xyk
z is also in L.
68
Pumping Lemma (for Regular Languages)
Say, w = a1a2…am
let, x= a1a2…ai
y = ai+1ai+2…aj
z = aj+1aj+2…am
Then the FA can be viewed as,
a1a2…ai
ai+1ai+2…aj
aj+1aj+2…am
69
Pumping Lemma (for Regular Languages)
Prove that L01 = {0n
1n
| n>= 1} is not regular.
Assume that L01 is regular.
So by Pumping lemma, we can have n ≥ 0, such that
w Є L01, |w | = n and we can break w into three sub strings x, y , z such that,
w = xyz such that, y != ϵ , |xy | ≤ n and xyk
z Є L01.
Assume, xy=0n
and z=1n
.
So FA can be drawn as,
a1a2…ai
ai+1ai+2…aj
aj+1aj+2…am
70
Pumping Lemma (for Regular Languages)
Here length of y is k, k ≥ 0.
When k=0, xz Є L01, => |x|=|z| =n --------------(1)
When k=1, xyz must be an element of L01, => |xy|=|z|,
but from (1), |x|=|z|, and also y!= ε,
which is a contradiction.
So the assumption that the language, L01 is regular is not correct.
71
Examples of languages, not regular
• L = { 0 i2
| i>=0}
• Lpr = {0p
| p is a prime number}
• L = {0n
10n
| n>=1}
• L = {0n
1m
| n<=m}
• L = {0n
| n is a perfect cube}
72
Finite state Machine with Output
• Mealy Machine :- Outputs corresponds to
transition between states
• Moore Machine :- Output determined only
by state.
Mathematical Representation of Mealy
Machine
M = (Q, Σ, λ, ∆, q0, δ)
where
Q =A nonempty finite set of state in M.
Σ = A nonempty finite set of input symbols.
∆ = A nonempty finite set of outputs.
δ = It is the transition function which takes two
arguments input state and input symbol.
q0 = Initial state of M.
λ = It is a mapping function which maps Q * Σ to ∆
giving output associated with each transition.
Representation of Mealy Machine
Let M be the Mealy Machine and a1, a2, a3, … an
be input symbols where n > 0 then output of
M is λ(q0, a1), λ(q1, a2), λ(q2, a3), λ(q3, a4), λ(q4,
a5)… λ(qn-1, an), such that
δ(qi-1, ai) = qi for 1 < i < n.
Example of Mealy Machine
Present
State
Input a = 0 Input a = 1
State output State Output
q1 q3 0 Q2 0
q2 q1 1 q4 0
q3 q2 1 q1 1
q4 q4 1 q3 0
Transition Table
Values of Q, Σ, ∆
• Q = {q1, q2, q3, q4}
• Σ = {0, 1}
• ∆ = {0, 1}
λ(q1, 0) = 0 δ(q1, 0) =
q3
λ(q2, 0) = 1 δ(q2, 0) =
q1
λ(q3, 0) = 1 δ(q3, 0) =
q2
λ(q4, 0) = 1 δ(q4, 0) =
q4
λ(q1, 1) = 0 δ(q1, 1) =
q2
Mealy Machine Transition Diagram
q1
q2
q4
q3
0/1
0/1
1/0
1/1
1/0
0/1
1/0
0/0
e.g. In 1/1, a = 1 and λ(q, a) = 1
Mathematical Representation of Moore
Machine
M = (Q, Σ, λ, ∆, q0, δ)
where
Q =A nonempty finite set of state in M.
Σ = A nonempty finite set of input symbols.
∆ = A nonempty finite set of outputs.
δ = It is the transition function which takes two
arguments input state and input symbol.
q0 = Initial state of M belongs to Q.
λ = It is a mapping function which maps Q to ∆
giving output associated with each state.
Representation of Moore Machine
• Let M be a Moore machine and a1 , a2 , a3 ,
…….an be input symbols where n>0 then
output of M is λ(q1) , λ(q2), λ(q3) , λ(q4)
………… λ(qn) , such that
• δ(qi – 1 , ai ) = qi for 1<i<n.
Example of Moore Machine
Present
State
Input Output
a = 0 a = 1
q0 q3 q1 0
q1 q1 q2 1
q2 q2 q3 0
q3 q3 q0 0
Transition Table
Values of
Q, Σ, Δ
Q = {q0 ,q1 ,q2 , q3 }
Σ = { 0 , 1 }
Δ = { 0 , 1 }
λ(q0) = 0 , λ(q1) = 1 , λ(q2) = 0 , λ(q3) = 0
Transition Diagram
q0
q2 q3
q1
0
0
1
1
1
0
0 0
1
0
1
0
0
83
Turing Machines
• Infinite tape to the right
• Finite alphabets for input and tape
• Finite number of states
• Can read from and write to the tape
• Can accept or reject at any time
• May run forever
aa b bbba • • • • • • •
Control
84
Turing Machine
Designed to satisfy three criteria:
• They should be automata, with the same
general characteristics as DFAs and PFAs
• They should be as simple as possible to
describe and reason about
• They should be as general as possible in
terms if the computations they can carry out
85
Turing Machine
• A Turing Machine is a 7-tuple (Q, Σ, Γ, δ, q0, qaccept, qreject )
where
• 1. Q is the set of states,
• 2. Σ is the input alphabet not containing the blank
symbol
• 3. Γ is the tape alphabet, where Γ and Σ Γ,∈ ⊆
• 4. δ: Q × Γ → Q × Γ × {L, R} is the transition
function,
• 5. q0 Q is the start state,∈
• 6. qaccept Q is the accept state,∈
• 7. qreject Q is the reject state, where q∈ reject ≠ qaccept .
86
Turing Machine
• The input is placed on the leftmost squares of the tape, so
the first blank symbol marks the end of the input.
• The head starts on the leftmost square.
• The head cannot move off the left end of the tape.
• The machine runs until it enters the accept or reject state;
or it runs forever.
• For a given state and tape symbol, the transition function
specifies the next state, the symbol written on the tape to
replace the scanned symbol, and a direction of movement
of the head, L or R.
87
Turing Machine
• The collection of strings accepted by a Turing machine M is called
the language of M, or the language recognized by M, and is
denoted by L(M).
• A language is Turing-recognizable if some Turing machine
recognizes it.
• A Turing machine may reject an input by entering the qreject state or
by looping forever. Note that it is difficult to distinguish a machine
that is looping from one that is taking a long time to accept.
• A machine that halts on all input is called a decider and is said to
decide its language.
• A language is Turing-decidable (or simply decidable) is some
Turing machine decides it.
88
89
References
Introduction to Automata Theory, Languages, and
Computation
John E Hopcroft, Rajeev Motwani & Jeffrey D Ullman
An Introduction to Formal Languages and
Automata, Peter Linz
Theory of Computer Science (Automata,
Languages and Computation ) ,K L P Mishra & N
Chandrasekaran.
 Discrete Mathematics and it’s applications, Kenneth H.
Rosen.

More Related Content

What's hot

String Matching with Finite Automata,Aho corasick,
String Matching with Finite Automata,Aho corasick,String Matching with Finite Automata,Aho corasick,
String Matching with Finite Automata,Aho corasick,
8neutron8
 
Chapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.pptChapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.ppt
FamiDan
 

What's hot (20)

AUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTESAUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTES
 
Flat unit 2
Flat unit 2Flat unit 2
Flat unit 2
 
A Role of Lexical Analyzer
A Role of Lexical AnalyzerA Role of Lexical Analyzer
A Role of Lexical Analyzer
 
Lecture: Automata
Lecture: AutomataLecture: Automata
Lecture: Automata
 
Lecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular LanguagesLecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular Languages
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Theory of computation Lec3 dfa
Theory of computation Lec3 dfaTheory of computation Lec3 dfa
Theory of computation Lec3 dfa
 
Intro automata theory
Intro automata theory Intro automata theory
Intro automata theory
 
Finite automata(For college Seminars)
Finite automata(For college Seminars)Finite automata(For college Seminars)
Finite automata(For college Seminars)
 
String Matching with Finite Automata,Aho corasick,
String Matching with Finite Automata,Aho corasick,String Matching with Finite Automata,Aho corasick,
String Matching with Finite Automata,Aho corasick,
 
Chapter 5 Syntax Directed Translation
Chapter 5   Syntax Directed TranslationChapter 5   Syntax Directed Translation
Chapter 5 Syntax Directed Translation
 
Theory of Computation Lecture Notes
Theory of Computation Lecture NotesTheory of Computation Lecture Notes
Theory of Computation Lecture Notes
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Automata
AutomataAutomata
Automata
 
Dfa basics
Dfa basicsDfa basics
Dfa basics
 
NFA Converted to DFA , Minimization of DFA , Transition Diagram
NFA Converted to DFA , Minimization of DFA , Transition DiagramNFA Converted to DFA , Minimization of DFA , Transition Diagram
NFA Converted to DFA , Minimization of DFA , Transition Diagram
 
Lecture 3,4
Lecture 3,4Lecture 3,4
Lecture 3,4
 
language , grammar and automata
language , grammar and automatalanguage , grammar and automata
language , grammar and automata
 
Regular expression with DFA
Regular expression with DFARegular expression with DFA
Regular expression with DFA
 
Chapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.pptChapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.ppt
 

Similar to Theory of computing

Similar to Theory of computing (20)

Chapter2CDpdf__2021_11_26_09_19_08.pdf
Chapter2CDpdf__2021_11_26_09_19_08.pdfChapter2CDpdf__2021_11_26_09_19_08.pdf
Chapter2CDpdf__2021_11_26_09_19_08.pdf
 
Regular language and Regular expression
Regular language and Regular expressionRegular language and Regular expression
Regular language and Regular expression
 
Syntax Analyzer.pdf
Syntax Analyzer.pdfSyntax Analyzer.pdf
Syntax Analyzer.pdf
 
Automata theory - CFG and normal forms
Automata theory - CFG and normal formsAutomata theory - CFG and normal forms
Automata theory - CFG and normal forms
 
Lexical
LexicalLexical
Lexical
 
Regular expressions h1
Regular expressions h1Regular expressions h1
Regular expressions h1
 
Mod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptxMod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptx
 
Control structure
Control structureControl structure
Control structure
 
Theory of Automata ___ Basis ...........
Theory of Automata ___ Basis ...........Theory of Automata ___ Basis ...........
Theory of Automata ___ Basis ...........
 
9781284077247_PPTx_CH01.pptx
9781284077247_PPTx_CH01.pptx9781284077247_PPTx_CH01.pptx
9781284077247_PPTx_CH01.pptx
 
Lesson 02
Lesson 02Lesson 02
Lesson 02
 
Lesson 02
Lesson 02Lesson 02
Lesson 02
 
Unit-1-part-1.pptx
Unit-1-part-1.pptxUnit-1-part-1.pptx
Unit-1-part-1.pptx
 
theory of computation lecture 02
theory of computation lecture 02theory of computation lecture 02
theory of computation lecture 02
 
Theory of Automata Lesson 02
Theory of Automata Lesson 02Theory of Automata Lesson 02
Theory of Automata Lesson 02
 
01-Introduction&Languages.pdf
01-Introduction&Languages.pdf01-Introduction&Languages.pdf
01-Introduction&Languages.pdf
 
Automata
AutomataAutomata
Automata
 
Automata_Theory_and_compiler_design_UNIT-1.pptx.pdf
Automata_Theory_and_compiler_design_UNIT-1.pptx.pdfAutomata_Theory_and_compiler_design_UNIT-1.pptx.pdf
Automata_Theory_and_compiler_design_UNIT-1.pptx.pdf
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
 
Lecture3 lexical analysis
Lecture3 lexical analysisLecture3 lexical analysis
Lecture3 lexical analysis
 

More from Ranjan Kumar (20)

Introduction to java ee
Introduction to java eeIntroduction to java ee
Introduction to java ee
 
Fantastic life views ons
Fantastic life views  onsFantastic life views  ons
Fantastic life views ons
 
Lessons on Life
Lessons on LifeLessons on Life
Lessons on Life
 
Story does not End here
Story does not End hereStory does not End here
Story does not End here
 
Whata Split Second Looks Like
Whata Split Second Looks LikeWhata Split Second Looks Like
Whata Split Second Looks Like
 
Friendship so Sweet
Friendship so SweetFriendship so Sweet
Friendship so Sweet
 
Dedicate Time
Dedicate TimeDedicate Time
Dedicate Time
 
Paradise on Earth
Paradise on EarthParadise on Earth
Paradise on Earth
 
Bolivian Highway
Bolivian HighwayBolivian Highway
Bolivian Highway
 
Chinese Proverb
Chinese ProverbChinese Proverb
Chinese Proverb
 
Warren Buffet
Warren BuffetWarren Buffet
Warren Buffet
 
Dear Son Dear Daughter
Dear Son Dear DaughterDear Son Dear Daughter
Dear Son Dear Daughter
 
Jara Sochiye
Jara SochiyeJara Sochiye
Jara Sochiye
 
Blue Beauty
Blue BeautyBlue Beauty
Blue Beauty
 
Alaska Railway Routes
Alaska Railway RoutesAlaska Railway Routes
Alaska Railway Routes
 
Poison that Kills the Dreams
Poison that Kills the DreamsPoison that Kills the Dreams
Poison that Kills the Dreams
 
Horrible Jobs
Horrible JobsHorrible Jobs
Horrible Jobs
 
Best Aviation Photography
Best Aviation PhotographyBest Aviation Photography
Best Aviation Photography
 
Role of Attitude
Role of AttitudeRole of Attitude
Role of Attitude
 
45 Lesons in Life
45 Lesons in Life45 Lesons in Life
45 Lesons in Life
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

Theory of computing

  • 2. 2 • Terminologies of TOC • Languages • Grammar • Noam Chomsky hierarchy • Parse Tree • BNF Notation • Finite automation • Regular Expressions • Theory of Automata • DFA & NFA • Pumping lemma • Languages which are not Regular • FSM with Output • Turing Machine
  • 3. 3 Terminologies of TOC • Alphabet – finite set of symbols – denoted by Σ. Examples : Σ = {a,b, c,…, z} Σ = {0, 1} Σ = {a} Σ = {ε} Σ = ø
  • 4. 4 Terminologies of TOC • String (word) – Finite sequence of symbols from an alphabet., usually denoted by w. Ex: English is a string from Σ = {a,b, c,…, z} 01110 is a string from Σ = {0,1} • Empty string – String with no symbols ε or e
  • 5. 5 Terminologies of TOC • Length of a string w, denoted by |w| - is the number of symbols in a string. Eg: |abc| = 3 |b| = 1 |ε| = 0 |ababxyz| = 7
  • 6. 6 Terminologies of TOC • Substring – string contained in a string Eg: a,ab,abc, ε are substrings of string abc • A string may have many occurrences of the same substring, Ex: abababc contains the substring ab three times • If w is a string then – W 0 = ε – W 1 = w – W 2 = w w … – W i+1 = w i w
  • 7. 7 String Operations 1. Concatenation: - binary operator - concatenation of x and y, denoted by xy or x y∘ , is the string x followed by y - Eg: dog house∘ => doghouse abc ε => abc∘ 2. Reversal: - unary in nature - denoted by w R , is the string w spelled backwards - Eg: (top) R = pot
  • 8. 8 Terminologies of TOC • (Formal) Language – set of strings over an alphabet, Σ, ie. any subset of Σ * is called a language. Eg: If Σ = {0,1}, then - L1= {0, 1, 00, 11} is a language - L2= set of palindromes is a language, ie - L2= {ε, 0, 1, 00, 11, 010, 101,…} - Σ * , {ε}, Ø • A language may be finite or infinite • Infinite language is written as L = { w Є Σ * : w has property P} Eg: L = { w Є {0,1} * ; w has equal number of 1’s and 0’s}
  • 9. 9 Operations on Languages If L, L1, L2are languages over Σ 1. Union L = L1U L2 1. Intersection L = L1∩ L2 1. Complement Lc= Σ* - L 1. Concatenation L = L1.L2 = {w : w = x.y, for some x Є L1 and y Є L2} 1. Closure (Kleen closure) L* = L0 U L1 U L2 U… 1. Positive closure L+ = L* - ε, L+ = L L*
  • 10. 10 Regular Expressions A Regular Expression is a string that is used to describe or match a set of strings, according to certain syntax rules. Eg: 0* = {ε, 0, 00, 000,…} 0+1 = {0, 1} 01 = {01} ab(a+b) = {aba, abb} a(c+ d) b = {acb, adb} a*b = {ε, a, aa, aaa, …} b = {b, ab, aab, aaab, …} Regular Language – Language generated by a regular expression.
  • 11. 11 Regular Expressions Operation Symbol Example Regular Expression concatenation ab ab [a-c][AB] aA aB bA bB cA CB∪ ∪ ∪ ∪ ∪ Kleene star * [ab]* (a b)*∪ disjunction | [ab]*|A (a b)* A∪ ∪ zero or more + a? (a λ)∪ one character . a.a a(a b)a if Σ={a,b}∪ n times {n} a{4} aaaa=a⁴ n or more times {n,} a{4,} aaaaa* n to m times {n,m} a{4,6} aaaa aaaaa aaaaaa∪ ∪ #> man grep
  • 12. 12 Regular Expressions • Describe the following sets by regular expression (1) {ε, a, aa, aaa, …} a* (2) {01,10} 01+10 (3) {01,011,0101} 01+011+0101 = 01(ε+1+01) (4) Strings that end with a over Σ ={a, b} (a+b)*a (5) Strings of 0’s and 1’s containing 00 as substring (0+1)*00(0+1)* (6) Strings of 0’s and 1’s beginning with 0 and ending with 1 0(0+1)*1 (7) L= {ε, 11, 1111, 111111, …} (11)*`
  • 13. 13 Noam Chomsky described the languages into four classes, namely • Type 0 Language (Recursively Enumerable Language) • Type 1 Language (Context Sensitive Language) • Type 2 Language (Context Free language) • Type 3 Language (Regular Language)
  • 14. 14 Grammar Generates strings in language by a process of replacing symbols • Similar to regular expressions. Four elements. • Terminal symbols: characters in alphabet – denote by 0 or 1 for binary alphabet. • Nonterminal symbols: local variables for internal use – denote by <name>. • Start Symbol: one special nonterminal. (analogous to start state in FSA) • Production rules: replacement rules – denote by <A> c => <D> b <B>
  • 15. A Familiar Example Terminals: horse, dog, cat, saw, heard, the Nonterminals: <sentence>, <subject>, <verb>, <object> Start Symbol: <sentence> Production rules: <sentence> => <subject> <verb><object> <subject> => the horse <subject> => the dog <subject> => the cat <object> => the horse <object> => the dog <object> => the cat <verb> => saw <verb> => heard Some Strings: the horse saw the dog the dog heard the cat the cat saw the horse
  • 16. Generating a String in Language Start with the start Symbol. <sentence> Generating a string in language: <sentence>
  • 17. Generating a String in Language Start with the start Symbol. Use any applicable production rule. <sentence> => <subject> <verb> <object> Generating a string in language: <sentence> => <subject> <verb> <object>
  • 18. Generating a String in Language Start with the start Symbol. Use any applicable production rule. <sentence> => <subject> <verb> <object> Generating a string in language: <sentence> => <subject> <verb> <object> => the horse saw the dog the horse saw the dog
  • 19. The C Language Grammar Terminals: if do while for switch break continue typedef struct return main int long char float double void static ; ( ) a b c A B C 0 1 2 + * - / _ # include += ++ … Nonterminals: <statement> <expression> <C source file> <identifier> <digit> <nondigit> <identifier> <selection-statement> <loop-statement> Start symbol: <C source file> A String: #include <stdio.h> int main(void) { printf(“Hello World!n”); return 0; }
  • 20. The C Language: Identifier Production Rules: <identifier> => <nondigit> => <identifier> <nondigit> => <identifier> <digit> <nondigit> => a | b | … | Y | Z | _ <digit> => 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Some identifiers: x f temp temp1 done _CanStartWithUnderscoreButNor7
  • 21. The C Language: Expressions Production rules: <expression> => <identifier> => <constant> => <cond-expression> => <assign-expression> <cond-expression> => <expression> > <expression> => <expression> != <expression> <assign-expression> => <expression> = <expression> => <expression> += <expression> Some expression: • x • x > 4 • done != 1 • x = y = z = 0 • x += 2.0 This grammar also considers 4 = x a valid expression
  • 22. The C Language: Statements Production rules: <statement> => <select-statement> => <loop-statement> => <compound-statement> => <express-statement> <select-statement> => if (<expression>) => if (<expression>) <statement> else <statement> <loop-statement> => while (<expression>) <statement> => do <statement> while (<expression>) <express-statement> => <expression>; A Statement: while (done != 1) if(f(x) > 4.0) done = 1; else x += 2.0;
  • 23. Grammar In practice, need to write out grammar for C. • Compiler check to see if your program is a valid “string” in the C language. • The C Standard formalizes what it means to be a valid ANSI C program using grammar • Compiler implementation: simulate FSA and PDA machine to recognize valid C programs.
  • 24. Type III Grammar (Regular) Limit production rules to have exactly one nonterminal on LHS and at most one nonterminal and terminal on RHS. <A> => <B> a <A> => <A> b <B> => c <C> => ϵ Example: <A> => <B> 0 Start = <A> <B> => <A> 1 <A> => ϵ String generated: ϵ, 10, 1010, 101010, 10101010, … Grammar GENERATES language = set of all strings derivable from applying production rules.
  • 25. Type II Grammar (Context Free) Limit production rules to have exactly one nonterminal on LHS, but anything on RHS. <A> => b <B> <C> a <C> <A> => <A> b c a <A> Example: <PAL> => 0 <PAL> 0 Start = <PAL> => 1 <PAL> 1 => 0 => 1 => ϵ String generated: ϵ, 1, 0, 101, 001100, 111010010111, …
  • 26. Type II Grammar (Context Free) Example: <S> => ( <S> ) Start = <S> => { <S> } => [ <S> ] => <S> <S> => ϵ String generated: ϵ, (), ()[()], (([]{()})[](())), …
  • 27. Type I Grammar (Context Sensitive) Add production rules of the type: [A] <B> [C] => [A] a [C] where [A] and [C] represent some fixed sequence of nonterminals and terminals. <A> <B> <C> => <A> b <C> <A> hi <B> <C> => <A> hib <C> <D>
  • 28. Type 0 Grammar (Recursive) No limit on production rules: at least one nonterminal on LHS. Example: Start = <S> <S> => <S> <S> <A><B> => <B><A> <S> => <A> <B> <C> <B><A> => <A><B> <A> => a <A><C> => <C><A> <B> => b <C><A> => <A><C> <C> => c <B><C> => <C><B> <S> => ϵ Strings Generated: ϵ, abc, aabbcc, cabcab, acacacacacabbbbbb, …
  • 29. Chomsky Hierarchy Type Machin e Gramm ar III Finite State Automata Regular II Push Down Automata Context Free I Least Bound Automata Context Sensitive 0 Turing Machine Recursive Powerful Machines Expressive Languages Essential one-to-one correspondence between machine and languages.
  • 30. 30 All Languages Chomsky Hierarchy Regular Language Context Free Language Context Sensitive Language Recursively Enumerable Language
  • 31. FSA and Type III Equivalence FSA’s and Type III grammar are equally powerful. • Given an FSA, can construct Type III grammar to generate same language. • Given Type III language, can construct FSA that accepts same language. Proof Idea: FSA Type III Grammar Start state Start symbol States Nonterminals Transition arcs Production rules: <A> => <B> a Accept state Production rules: <A> => a
  • 32. Compilers and Grammar Compiler: translates program from high-language to native machine language. Three basic phases. • Lexical analysis (tokenizing). – convert input into “tokens” or terminal symbols – # include <stdio.h> int main ( void ) { printf ( “Hello World!n” ) ; return 0 ; } – implement with FSA – Unix program lex
  • 33. Compilers and Grammar Compiler: translates program from high-language to native machine language. Three basic phases. • Lexical analysis (tokenizing). • Syntax analysis (parsing). – implemented using pushdown automata since C language is (almost) completely described with context-free grammar – Unix program yacc
  • 34. Compilers and Grammar Compiler: translates program from high-language to native machine language. Three basic phases. • Lexical analysis (tokenizing). • Syntax analysis (parsing). • Code generation. – parse tree gives structure of computation – traverse tree in postorder and create native code - * a d + + cb e Parse tree for expression: (a * (b + c)) – (d + e)
  • 35. 35 Theory of Automata • Dictionary defines Automaton as a machine/mechanism that operates as per encoded instructions. • Theory of Automata deals with the study of automata (machines), their states, and state transitions with respect to functions, without human intervention ie., as per encoded instructions.
  • 36. 36 Major Automata categories: • Finite Automata – Deterministic Finite Automata (DFA) – Non-Deterministic Finite Automata (NFA) • Pushdown Automata – Deterministic Pushdown Automata – Nondeterministic Pushdown Automata • Turing Machine Increasing order of functions
  • 37. 37 Deterministic Finite Automata(DFA) • A DFA consists of a finite set of states and a set of transitions from state to state that occur on input symbols chosen from an alphabet ∑.
  • 38. 38 DFA • Formal Definition: DFA A= (Q, ∑,δ, q0, F), where Q is a finite set of states, ∑ is a finite input alphabet q0 Є Q is the initial state F Є Q is the set of final states δ is the transition function mapping Q X ∑ to Q
  • 39. 39 DFA Draw the DFA for ,D= (Q, ∑,δ,S, F), when Q = {q0,q1}, ∑ = {a,b}, S = q0,F = {q1} and δ is given by a b q0 *q1 q0 q1 q1 q0 δ a q0 q1 b b a Start
  • 40. 40 DFA Draw DFA for {w : w is of the form x01y, for some x,y Є {0,1}} So, Q = {q0,q1,q2} ∑ = {0,1} S = q0 F = {q2} 0 1 q0 q1 * q2 q1 q0 q0 q2 q2 q2 δ 1 0 0,1 q0 q20 q 1 1Start
  • 41. 41 DFA Give DFA for the set of all strings ending in 00, over the alphabet ∑ = {0,1} So, Q = {q0,q1,q2} ∑ = {0,1} S = q0 F = {q2} 0 1 q0 q1 * q2 q1 q0 q2 q2 q0 q0 δ q0 q2 1 q 1 0 1 0 Start 1
  • 42. 42 DFA • Language accepted by a DFA is called Regular language. • DFA is an FA with determinism. • Determinism means for any DFA there will be one and only one transition from every state for every symbol of ∑
  • 43. 43 NonDeterministic Finite Automata(NFA) • NFA is an FA showing Nondeterminism. • A NFA can be different from a DFA in that – for any input symbol, nondeterministic one can transit to more than one states. – for any input symbol, nondeterministic one may not transit to another state
  • 44. 44 NFA • Formal Definition: NFA A = (Q, ∑,δ, q0, F), where Q is a finite set of states, ∑ is a finite input alphabet q0 Є Q is the initial state F ⊂ Q is the set of final states δ is the transition function mapping Q X ∑* -> Q
  • 45. 45 NFA This diagram represents an NFA which accepts strings ending in 01, ie., (0+1)*01 q0 q2 0,1 0 q 1 1 Start 0 1
  • 46. 46 NFA • Corresponding Transition Diagram {q0} {q0,q1} {q0,q2*} {q0,q1} {q0} {q0,q1} {q0,q2} {q0,q1} {q0} 0 1
  • 47. 47 Equivalence of DFA and NFA • For every NFA there exists a DFA which simulates the behavior of NFA • Language accepted by NFA will be equal to that accepted by DFA. • Language accepted by NFA is regular language.
  • 48. 48 How to construct Equivalent DFA for an NFA (1) Construct a DFA which accepts strings ending in 01 NFA q0 q20 q 1 1 0,1
  • 49. 49 Transition Diagram • Q = {q0,q1,q2} • ∑ = {0,1} • S = {q0} • F = {q2} {q0} {q0,q1} {q0,q2*} {q0,q1} {q0} {q0,q1} {q0,q2} {q0,q1} {q0} 0 1 B A C
  • 50. 50 DFA A C0 B 1 1 1 0 0
  • 51. 51 How to construct Equivalent DFA for an NFA • (2) Construct an NFA which accepts 0(0+1)*1 and then convert it into corresponding DFA NFA: q0 q20 q 1 1 0,1
  • 52. 52 Transition Diagram ( for 0(0+1)*1 ) • Q = {q0,q1,q2} • ∑ = {0,1} • S = {q0} • F = {q2} {q0} {q1} { } {q1,q2*} {q1} { } {q1} {q1,q2} { } { } {q1} {q1,q2} 0 1 B A C D
  • 53. 53 DFA A D0 B 1 C 0,1 0 1 0 1
  • 54. 54 Finite Automata with Epsilon transitions • NFAs are sometimes allowed to have a transition accepting ε string. • Such NFAs are called FA with ε transition. q1q0 εStart
  • 56. 56 Equivalence of RE and FA • Every language defined by a regular expression is also defined by a finite automaton. • In other words, there exists a finite automaton for every regular expression.
  • 57. 57 Equivalence of RE and FA (trivial cases) Let R be a regular expression, L(R) be the language generated by R, then • L(R) = {ε}, R = ε • L(R) = Ø • L(R) = L(a) = {a}, R= a ε a Start Start Start
  • 58. 58 Equivalence of RE and FA Let R and S be regular expressions, then: 1. Let M = R+S, then L(M) =L(R) U L(S) ε ε ε ε S R Start
  • 59. 59 Equivalence of RE and FA 1. Let M = R.S, then L(M) =L(R)L(S) R Sε Start
  • 60. 60 Equivalence of RE and FA R 3. Let M = R*, then L(M) =L(R)UL(R)UL(R)UL(R)… ε ε ε ε Start
  • 61. 61 Example Convert the RE = (0+1)*1(0+1) to an ε-NFA ε0 ε ε ε 1 ε ε ε ε ε ε εε 1 0 1ε ε
  • 62. 62 Algebraic laws for Regular Expressions If L, M, N are 3 regular expressions, then 1. Commutative Law for Union – L +M = M + L 1. Associative Law for Union – (L+M) + N = L + (M + N) 1. Associative Law for concatenation – (LM)N = L(MN)
  • 63. 63 Algebraic laws for Regular Expressions  Ø + L = L + Ø = L, Ø is the identity for union.  εL = L ε = L , ε is the identity for concatenation.  ØL = LØ = Ø, Ø is the annihilator for concatenation.
  • 64. 64 Algebraic laws for Regular Expressions 1. Distributive Law – L(M+N) = LM + LN (M+N) L = ML + NL 1. Idempotent law - L + L = L 1. Laws involving closures – (L*)* = L* Ø* = ε ε* = ε
  • 65. 65 Common Regular Expression Rules If P, Q ,R are regular expressions, then (1) (PQ)*P = P(QP)* (2) R*R* = R* (3)If R = Q + PR, then R = QP* (Arden’s theorem) (4) (P+Q)* = (P*Q*)*
  • 66. 66 Pumping Lemma (for Regular Languages) • Not every language is a regular language Eg: L01 = {0n 1n | n>= 1} • L01is a language that consists of the strings comprising n number of zeroes followed by n number of ones. • If there is an FA which accepts L01then it should, - accept n number of zeroes from start state - remember n, so that it can accept exactly n number of ones - accept n number of ones and reach the final state. • But FA lacks the capability to remember value n (lacks memory), so cannot accept L01. • L01cannot be accepted by any FA => L01is not regular => there exists languages which are not regular.
  • 67. 67 Pumping Lemma (for Regular Languages) (The pumping lemma for regular languages) Let L be a regular language. Then there exists a constant n (which depends on L) such that for every string w in L such that |w | ≥ n, we can break w into three strings, w=xyz, such that 1) y != ϵ 2) |xy | < n. 3) For all k ≥ 0, the string xyk z is also in L.
  • 68. 68 Pumping Lemma (for Regular Languages) Say, w = a1a2…am let, x= a1a2…ai y = ai+1ai+2…aj z = aj+1aj+2…am Then the FA can be viewed as, a1a2…ai ai+1ai+2…aj aj+1aj+2…am
  • 69. 69 Pumping Lemma (for Regular Languages) Prove that L01 = {0n 1n | n>= 1} is not regular. Assume that L01 is regular. So by Pumping lemma, we can have n ≥ 0, such that w Є L01, |w | = n and we can break w into three sub strings x, y , z such that, w = xyz such that, y != ϵ , |xy | ≤ n and xyk z Є L01. Assume, xy=0n and z=1n . So FA can be drawn as, a1a2…ai ai+1ai+2…aj aj+1aj+2…am
  • 70. 70 Pumping Lemma (for Regular Languages) Here length of y is k, k ≥ 0. When k=0, xz Є L01, => |x|=|z| =n --------------(1) When k=1, xyz must be an element of L01, => |xy|=|z|, but from (1), |x|=|z|, and also y!= ε, which is a contradiction. So the assumption that the language, L01 is regular is not correct.
  • 71. 71 Examples of languages, not regular • L = { 0 i2 | i>=0} • Lpr = {0p | p is a prime number} • L = {0n 10n | n>=1} • L = {0n 1m | n<=m} • L = {0n | n is a perfect cube}
  • 72. 72 Finite state Machine with Output • Mealy Machine :- Outputs corresponds to transition between states • Moore Machine :- Output determined only by state.
  • 73. Mathematical Representation of Mealy Machine M = (Q, Σ, λ, ∆, q0, δ) where Q =A nonempty finite set of state in M. Σ = A nonempty finite set of input symbols. ∆ = A nonempty finite set of outputs. δ = It is the transition function which takes two arguments input state and input symbol. q0 = Initial state of M. λ = It is a mapping function which maps Q * Σ to ∆ giving output associated with each transition.
  • 74. Representation of Mealy Machine Let M be the Mealy Machine and a1, a2, a3, … an be input symbols where n > 0 then output of M is λ(q0, a1), λ(q1, a2), λ(q2, a3), λ(q3, a4), λ(q4, a5)… λ(qn-1, an), such that δ(qi-1, ai) = qi for 1 < i < n.
  • 75. Example of Mealy Machine Present State Input a = 0 Input a = 1 State output State Output q1 q3 0 Q2 0 q2 q1 1 q4 0 q3 q2 1 q1 1 q4 q4 1 q3 0 Transition Table
  • 76. Values of Q, Σ, ∆ • Q = {q1, q2, q3, q4} • Σ = {0, 1} • ∆ = {0, 1} λ(q1, 0) = 0 δ(q1, 0) = q3 λ(q2, 0) = 1 δ(q2, 0) = q1 λ(q3, 0) = 1 δ(q3, 0) = q2 λ(q4, 0) = 1 δ(q4, 0) = q4 λ(q1, 1) = 0 δ(q1, 1) = q2
  • 77. Mealy Machine Transition Diagram q1 q2 q4 q3 0/1 0/1 1/0 1/1 1/0 0/1 1/0 0/0 e.g. In 1/1, a = 1 and λ(q, a) = 1
  • 78. Mathematical Representation of Moore Machine M = (Q, Σ, λ, ∆, q0, δ) where Q =A nonempty finite set of state in M. Σ = A nonempty finite set of input symbols. ∆ = A nonempty finite set of outputs. δ = It is the transition function which takes two arguments input state and input symbol. q0 = Initial state of M belongs to Q. λ = It is a mapping function which maps Q to ∆ giving output associated with each state.
  • 79. Representation of Moore Machine • Let M be a Moore machine and a1 , a2 , a3 , …….an be input symbols where n>0 then output of M is λ(q1) , λ(q2), λ(q3) , λ(q4) ………… λ(qn) , such that • δ(qi – 1 , ai ) = qi for 1<i<n.
  • 80. Example of Moore Machine Present State Input Output a = 0 a = 1 q0 q3 q1 0 q1 q1 q2 1 q2 q2 q3 0 q3 q3 q0 0 Transition Table
  • 81. Values of Q, Σ, Δ Q = {q0 ,q1 ,q2 , q3 } Σ = { 0 , 1 } Δ = { 0 , 1 } λ(q0) = 0 , λ(q1) = 1 , λ(q2) = 0 , λ(q3) = 0
  • 83. 83 Turing Machines • Infinite tape to the right • Finite alphabets for input and tape • Finite number of states • Can read from and write to the tape • Can accept or reject at any time • May run forever aa b bbba • • • • • • • Control
  • 84. 84 Turing Machine Designed to satisfy three criteria: • They should be automata, with the same general characteristics as DFAs and PFAs • They should be as simple as possible to describe and reason about • They should be as general as possible in terms if the computations they can carry out
  • 85. 85 Turing Machine • A Turing Machine is a 7-tuple (Q, Σ, Γ, δ, q0, qaccept, qreject ) where • 1. Q is the set of states, • 2. Σ is the input alphabet not containing the blank symbol • 3. Γ is the tape alphabet, where Γ and Σ Γ,∈ ⊆ • 4. δ: Q × Γ → Q × Γ × {L, R} is the transition function, • 5. q0 Q is the start state,∈ • 6. qaccept Q is the accept state,∈ • 7. qreject Q is the reject state, where q∈ reject ≠ qaccept .
  • 86. 86 Turing Machine • The input is placed on the leftmost squares of the tape, so the first blank symbol marks the end of the input. • The head starts on the leftmost square. • The head cannot move off the left end of the tape. • The machine runs until it enters the accept or reject state; or it runs forever. • For a given state and tape symbol, the transition function specifies the next state, the symbol written on the tape to replace the scanned symbol, and a direction of movement of the head, L or R.
  • 87. 87 Turing Machine • The collection of strings accepted by a Turing machine M is called the language of M, or the language recognized by M, and is denoted by L(M). • A language is Turing-recognizable if some Turing machine recognizes it. • A Turing machine may reject an input by entering the qreject state or by looping forever. Note that it is difficult to distinguish a machine that is looping from one that is taking a long time to accept. • A machine that halts on all input is called a decider and is said to decide its language. • A language is Turing-decidable (or simply decidable) is some Turing machine decides it.
  • 88. 88
  • 89. 89 References Introduction to Automata Theory, Languages, and Computation John E Hopcroft, Rajeev Motwani & Jeffrey D Ullman An Introduction to Formal Languages and Automata, Peter Linz Theory of Computer Science (Automata, Languages and Computation ) ,K L P Mishra & N Chandrasekaran.  Discrete Mathematics and it’s applications, Kenneth H. Rosen.

Editor's Notes

  1. Usually string is represented using w.