SlideShare uma empresa Scribd logo
1 de 40
Baixar para ler offline
AUTOMATA THEORY AND COMPILER
DESIGN
UNIT-I
Formal Language and Regular Expressions :
Languages, Definition Languages regular expressions,
Finite Automata – DFA, NFA. Conversion of regular
expression to NFA, NFA to DFA. Applications of Finite
Automata to lexical analysis, lex tools
Symbol – An atomic unit, such as a digit, character,
lower-case letter, etc. Sometimes a word.
[Formal language does not deal with the “meaning”
of the symbols.]
Alphabet – A finite set of symbols, usually denoted
by Σ.
Σ ={0, 1}
Σ = {0, a,b,c,9, 4}
Σ = {a, b, c,d}
String –
A finite length sequence of symbols, presumably
from some alphabet.
w=0110 y=0aa
x=aabcaa z = 111
Empty string(ε):
A string with zero occurrences of symbols is known as
an empty string. It is represented by ε.
ex :
w=0110 y=0aa
x=aabcaa z = 111
Concatenation : wz = 0110111
Length : |w| = 4 |ε| = 0 |x| = 6
Reversal : y R = aa0
Length of a string:
The number of symbols in a string w is called the length of a
string. It is denoted by |w|.
Some special sets of strings:
Σ * : All strings of symbols from Σ
Σ + : Σ * - {ε}
Example:
Σ = {0,1} Find Σ * & Σ +
Sol:
Σ * = {ε, 0, 1, 00, 01, 10, 11, 000, 001,…}
Σ + = {0, 1, 00, 01, 10, 11, 000, 001,…}
Language :
A language is a set of strings from some alphabet (finite
or infinite). In other words any subset L of Σ*.
Some special languages:
{} : The empty set/language, containing no string.
{ε} : A language containing one string, the empty string.
Examples:
L1 = {Set of string of length 2} using Σ {a,b} generate the L1?
Sol:
1) Σ = {0,1} using L = {x | x is in Σ* and x contains an even number of 0‟s} generate
L?
2) Σ = {0, 1, 2,…,9} using L = {x | x is in Σ* and x forms a finite length real number}
generate L ?
3)Construct the Language with ∑ = {0, 1} accepts those string which starts with 1
and ends with 0 string length is 3.
4) Construct the Language with ∑ = {0, 1} accepts even number of 0's and even
number of 1's string length is 4.
5) Construct the Language with ∑ = {0, 1} accepts the set of all strings with three
consecutive 0's.
6) Construct the Language with ∑ = {0, 1} accepts the strings with an even number of
0's followed by single 1.
•The language accepted by finite automata can be easily described
by simple expressions called Regular Expressions. It is the most
effective way to represent any language.
•The languages accepted by some regular expression are referred to
as Regular languages.
•A regular expression can also be described as a sequence of pattern
that defines a string.
•Regular expressions are used to match character combinations in
strings.
Regular expressions :
For instance:
In a regular expression, x* means zero or more occurrence of x. It can
generate L={e, x, xx, xxx, xxxx, .....}
In a regular expression, x+
means one or more occurrence of x. It can
generate L= {x, xx, xxx, xxxx, .....}
Operations on Regular Language:
The various operations on regular language are
1)Union: If L and M are two regular languages then their union L U M
is also a union.
L U M = {s | s is in L or s is in M} .
Ex:
2)Intersection: If L and M are two regular languages then their
intersection is also an intersection.
L ⋂ M = {st | s is in L and t is in M}
Ex:
3)Kleen closure: If L is a regular language then its Kleen closure
L1* will also be a regular language.
L* = Zero or more occurrence of language L.
Ex: x* means zero or more occurrence of x. It can generate
L={e, x, xx, xxx, xxxx, .....}
1)Write the regular expression for the language accepting all the string which are
starting with 1 and ending with 0, over ∑ = {0, 1}.
Solution:
In a regular expression, the first symbol should be 1, and the last symbol should be 0.
The r.e. is as follows:
R = 1 (0+1)* 0 .
2) Write the regular expression for the language accepting all the string in which any
number of a's is followed by any number of b's is followed by any number of c's.
Solution:
R =
3)Write the regular expression for the language starting and ending with a and
having any having any combination of b's in between.
R =
Generate the Language using the regular expression:
(0 +1)* : All strings of 0‟s and1‟s
0(0 +1)* :
(0 +1)*1 :
(0 + 1)*0(0+1)* :
(0 + 1)*0(0 + 1)*0(0+1)* :
(101*0)* :
1*(01*01*)* :
(1*01*0)*1*:
4) Write the regular expression for the language over ∑ = {0} having even length of the
string.
R =
5) Write the regular expression for the language having a string which should have
atleast one 0 and alteast one 1. R=
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.
Formal Definition of FA
A finite automaton is a collection of 5-tuple (Q, ∑, δ, q0, F),
where:
Q: finite set of states
∑: finite set of the input symbol
q0: initial state
F: final state
δ: Transition function
Finite Automata Model
Finite automata can be represented by input tape and finite control.
Input tape: It is a linear tape having some number of cells. Each input symbol
is placed in each cell.
Finite control: The finite control decides the next state on receiving
particular input from input tape. The tape reader reads the cells one by one
from left to right, and at a time only one input symbol is read.
Types of Automata:
There are two types of finite automata:
1.DFA(deterministic finite automata)
2.NFA(non-deterministic finite automata)
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.
Some important points about DFA and
NFA:
1.Every DFA is NFA, but NFA is not DFA.
2.There can be multiple final states in both NFA and DFA.
3.DFA is used in Lexical Analysis in Compiler.
4.NFA is more of a theoretical concept.
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
A DFA is a collection of 5-tuples same as we described in the
definition of FA
Examples of DFA
1)Design a FA with ∑ = {0, 1} accepts those string which starts with 1 and ends with 0.
2) Design a FA with ∑ = {0, 1} accepts the only input 101.
3) Design FA with ∑ = {0, 1} accepts even number of 0's and even number of 1's.
4) Design FA with ∑ = {0, 1} accepts the set of all strings with three consecutive 0's.
5) Design a FA with ∑ = {0, 1} accepts the strings with an even number of 0's followed by
single 1.
Minimization of DFA
DFA minimization stands for converting a given DFA to its equivalent
DFA with minimum number of states. DFA minimization is also called
as Optimization of DFA and uses partitioning algorithm.
Following are the various steps to minimize the DFA:
Step 1: Remove all the states that are unreachable from
the initial state via any set of the transition of DFA.
Step 2: Draw the transition table for all pair of states
Step 3: Now split the transition table into two tables T1
and T2. T1 contains all final states, and T2 contains
non-final states.
Step 4: Find similar rows from T1 such that:
1. δ (q, a) = p
Step 6: Repeat step 3 and step 4 for table T2 also.
Step 7: Now combine the reduced T1 and T2 tables.
The combined transition table is the transition table
of minimized DFA.
NFA (Non-Deterministic finite automata)
•NFA stands for non-deterministic finite automata. It is easy to
construct an NFA than DFA for a given regular language.
•The finite automata are called NFA when there exist many paths for
specific input from the current state to the next state.
•Every NFA is not DFA, but each NFA can be translated into DFA.
•NFA is defined in the same way as DFA but with the following two
exceptions, it contains multiple next states, and it contains ε
transition.
Formal definition of NFA:
NFA also has five states same
as DFA, but with different
transition function,
1 NFA with ∑ = {0, 1} accepts all strings starting with 01.check
w=010100
2) NFA with ∑ = {0, 1} and accept all string of length at least 2. w=11011011
3) Design an NFA with ∑ = {0, 1} in which double '1' is followed by double '0'.
4) Design an NFA in which all the string contain a substring 1110.
5) Using below table design NFA
epsilon closure
NFA with ∈ move: If any FA contains ε transaction or move,
the finite automata is called NFA with ∈ move.
ε-closure: ε-closure for a given state A means a set of
states which can be reached from the state A with only ε
(null) move including the state A itself.
Eliminating ε Transitions
NFA with ε can be converted to NFA without ε, and this NFA without ε can be
converted to DFA. To do this, we will use a method, which can remove all the ε
transition from given NFA.The method will be:
1.Find out all the ε transitions from each state from Q. That will be called as
ε-closure{q1} where qi ∈ Q.
2.Then δ' transitions can be obtained. The δ' transitions mean a ε-closure on δ
moves.
3.Repeat Step-2 for each input symbol and each state of given NFA.
4.Using the resultant states, the transition table for equivalent NFA without ε can
be built.
Example:
The Applications of Finite Automata
Finite Automata (FA) –
•For the designing of lexical analysis of a compiler.
•For recognizing the pattern using regular expressions.
•For the designing of the combination and sequential circuits using
Mealy and Moore Machines.
•Used in text editors.
•For the implementation of spell checkers.
•Can be used as a model for learning and decision making.
•Can parse text to extract information and structure data.
Automata_Theory_and_compiler_design_UNIT-1.pptx.pdf
Automata_Theory_and_compiler_design_UNIT-1.pptx.pdf
Automata_Theory_and_compiler_design_UNIT-1.pptx.pdf
Automata_Theory_and_compiler_design_UNIT-1.pptx.pdf
Automata_Theory_and_compiler_design_UNIT-1.pptx.pdf
Automata_Theory_and_compiler_design_UNIT-1.pptx.pdf
Automata_Theory_and_compiler_design_UNIT-1.pptx.pdf

Mais conteúdo relacionado

Semelhante a Automata_Theory_and_compiler_design_UNIT-1.pptx.pdf

compiler Design course material chapter 2
compiler Design course material chapter 2compiler Design course material chapter 2
compiler Design course material chapter 2gadisaAdamu
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysisraosir123
 
Thoery of Computaion and Chomsky's Classification
Thoery of Computaion and Chomsky's ClassificationThoery of Computaion and Chomsky's Classification
Thoery of Computaion and Chomsky's ClassificationPrafullMisra
 
LECTURE 2 Converting NFA ( b) to DFA.pptx
LECTURE 2 Converting NFA ( b) to DFA.pptxLECTURE 2 Converting NFA ( b) to DFA.pptx
LECTURE 2 Converting NFA ( b) to DFA.pptxAbhishekKumarPandit5
 
Lecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.pptLecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.pptNderituGichuki1
 
Introduction to the theory of computation
Introduction to the theory of computationIntroduction to the theory of computation
Introduction to the theory of computationprasadmvreddy
 
RegularExpressions.pdf
RegularExpressions.pdfRegularExpressions.pdf
RegularExpressions.pdfImranBhatti58
 
The Theory of Finite Automata.pptx
The Theory of Finite Automata.pptxThe Theory of Finite Automata.pptx
The Theory of Finite Automata.pptxssuser039bf6
 
AUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTESAUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTESsuthi
 
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.pdfDrIsikoIsaac
 
Resumen material MIT
Resumen material MITResumen material MIT
Resumen material MITRawel Luciano
 

Semelhante a Automata_Theory_and_compiler_design_UNIT-1.pptx.pdf (20)

compiler Design course material chapter 2
compiler Design course material chapter 2compiler Design course material chapter 2
compiler Design course material chapter 2
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysis
 
Thoery of Computaion and Chomsky's Classification
Thoery of Computaion and Chomsky's ClassificationThoery of Computaion and Chomsky's Classification
Thoery of Computaion and Chomsky's Classification
 
LECTURE 2 Converting NFA ( b) to DFA.pptx
LECTURE 2 Converting NFA ( b) to DFA.pptxLECTURE 2 Converting NFA ( b) to DFA.pptx
LECTURE 2 Converting NFA ( b) to DFA.pptx
 
Lecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.pptLecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.ppt
 
Ch3.ppt
Ch3.pptCh3.ppt
Ch3.ppt
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Unit ii
Unit iiUnit ii
Unit ii
 
Introduction to the theory of computation
Introduction to the theory of computationIntroduction to the theory of computation
Introduction to the theory of computation
 
Lexical
LexicalLexical
Lexical
 
RegularExpressions.pdf
RegularExpressions.pdfRegularExpressions.pdf
RegularExpressions.pdf
 
The Theory of Finite Automata.pptx
The Theory of Finite Automata.pptxThe Theory of Finite Automata.pptx
The Theory of Finite Automata.pptx
 
AUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTESAUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTES
 
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
 
Resumen material MIT
Resumen material MITResumen material MIT
Resumen material MIT
 
Lec1.pptx
Lec1.pptxLec1.pptx
Lec1.pptx
 
Theory of computation and automata
Theory of computation and automataTheory of computation and automata
Theory of computation and automata
 
Theory of computation and automata
Theory of computation and automataTheory of computation and automata
Theory of computation and automata
 
PART A.doc
PART A.docPART A.doc
PART A.doc
 
2_4 Finite Automata.ppt
2_4 Finite Automata.ppt2_4 Finite Automata.ppt
2_4 Finite Automata.ppt
 

Último

Gyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxGyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxShibin Azad
 
[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online PresentationGDSCYCCE
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...Sayali Powar
 
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringBasic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringDenish Jangid
 
How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17Celine George
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Celine George
 
Mbaye_Astou.Education Civica_Human Rights.pptx
Mbaye_Astou.Education Civica_Human Rights.pptxMbaye_Astou.Education Civica_Human Rights.pptx
Mbaye_Astou.Education Civica_Human Rights.pptxnuriaiuzzolino1
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxCapitolTechU
 
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17Celine George
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...Nguyen Thanh Tu Collection
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfQucHHunhnh
 
philosophy and it's principles based on the life
philosophy and it's principles based on the lifephilosophy and it's principles based on the life
philosophy and it's principles based on the lifeNitinDeodare
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya - UEM Kolkata Quiz Club
 
IATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdffIATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdff17thcssbs2
 
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...Abhinav Gaur Kaptaan
 
Keeping Your Information Safe with Centralized Security Services
Keeping Your Information Safe with Centralized Security ServicesKeeping Your Information Safe with Centralized Security Services
Keeping Your Information Safe with Centralized Security ServicesTechSoup
 
Neurulation and the formation of the neural tube
Neurulation and the formation of the neural tubeNeurulation and the formation of the neural tube
Neurulation and the formation of the neural tubeSaadHumayun7
 
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdfTelling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdfTechSoup
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Mohamed Rizk Khodair
 

Último (20)

Gyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxGyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptx
 
[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringBasic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
 
How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17
 
Mbaye_Astou.Education Civica_Human Rights.pptx
Mbaye_Astou.Education Civica_Human Rights.pptxMbaye_Astou.Education Civica_Human Rights.pptx
Mbaye_Astou.Education Civica_Human Rights.pptx
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
 
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
 
Word Stress rules esl .pptx
Word Stress rules esl               .pptxWord Stress rules esl               .pptx
Word Stress rules esl .pptx
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
philosophy and it's principles based on the life
philosophy and it's principles based on the lifephilosophy and it's principles based on the life
philosophy and it's principles based on the life
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
 
IATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdffIATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdff
 
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
 
Keeping Your Information Safe with Centralized Security Services
Keeping Your Information Safe with Centralized Security ServicesKeeping Your Information Safe with Centralized Security Services
Keeping Your Information Safe with Centralized Security Services
 
Neurulation and the formation of the neural tube
Neurulation and the formation of the neural tubeNeurulation and the formation of the neural tube
Neurulation and the formation of the neural tube
 
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdfTelling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).
 

Automata_Theory_and_compiler_design_UNIT-1.pptx.pdf

  • 1. AUTOMATA THEORY AND COMPILER DESIGN UNIT-I Formal Language and Regular Expressions : Languages, Definition Languages regular expressions, Finite Automata – DFA, NFA. Conversion of regular expression to NFA, NFA to DFA. Applications of Finite Automata to lexical analysis, lex tools
  • 2. Symbol – An atomic unit, such as a digit, character, lower-case letter, etc. Sometimes a word. [Formal language does not deal with the “meaning” of the symbols.] Alphabet – A finite set of symbols, usually denoted by Σ. Σ ={0, 1} Σ = {0, a,b,c,9, 4} Σ = {a, b, c,d}
  • 3. String – A finite length sequence of symbols, presumably from some alphabet. w=0110 y=0aa x=aabcaa z = 111 Empty string(ε): A string with zero occurrences of symbols is known as an empty string. It is represented by ε.
  • 4. ex : w=0110 y=0aa x=aabcaa z = 111 Concatenation : wz = 0110111 Length : |w| = 4 |ε| = 0 |x| = 6 Reversal : y R = aa0 Length of a string: The number of symbols in a string w is called the length of a string. It is denoted by |w|.
  • 5. Some special sets of strings: Σ * : All strings of symbols from Σ Σ + : Σ * - {ε} Example: Σ = {0,1} Find Σ * & Σ + Sol: Σ * = {ε, 0, 1, 00, 01, 10, 11, 000, 001,…} Σ + = {0, 1, 00, 01, 10, 11, 000, 001,…}
  • 6. Language : A language is a set of strings from some alphabet (finite or infinite). In other words any subset L of Σ*. Some special languages: {} : The empty set/language, containing no string. {ε} : A language containing one string, the empty string. Examples: L1 = {Set of string of length 2} using Σ {a,b} generate the L1? Sol:
  • 7. 1) Σ = {0,1} using L = {x | x is in Σ* and x contains an even number of 0‟s} generate L? 2) Σ = {0, 1, 2,…,9} using L = {x | x is in Σ* and x forms a finite length real number} generate L ? 3)Construct the Language with ∑ = {0, 1} accepts those string which starts with 1 and ends with 0 string length is 3. 4) Construct the Language with ∑ = {0, 1} accepts even number of 0's and even number of 1's string length is 4. 5) Construct the Language with ∑ = {0, 1} accepts the set of all strings with three consecutive 0's. 6) Construct the Language with ∑ = {0, 1} accepts the strings with an even number of 0's followed by single 1.
  • 8. •The language accepted by finite automata can be easily described by simple expressions called Regular Expressions. It is the most effective way to represent any language. •The languages accepted by some regular expression are referred to as Regular languages. •A regular expression can also be described as a sequence of pattern that defines a string. •Regular expressions are used to match character combinations in strings. Regular expressions :
  • 9. For instance: In a regular expression, x* means zero or more occurrence of x. It can generate L={e, x, xx, xxx, xxxx, .....} In a regular expression, x+ means one or more occurrence of x. It can generate L= {x, xx, xxx, xxxx, .....} Operations on Regular Language: The various operations on regular language are 1)Union: If L and M are two regular languages then their union L U M is also a union. L U M = {s | s is in L or s is in M} . Ex:
  • 10. 2)Intersection: If L and M are two regular languages then their intersection is also an intersection. L ⋂ M = {st | s is in L and t is in M} Ex: 3)Kleen closure: If L is a regular language then its Kleen closure L1* will also be a regular language. L* = Zero or more occurrence of language L. Ex: x* means zero or more occurrence of x. It can generate L={e, x, xx, xxx, xxxx, .....}
  • 11. 1)Write the regular expression for the language accepting all the string which are starting with 1 and ending with 0, over ∑ = {0, 1}. Solution: In a regular expression, the first symbol should be 1, and the last symbol should be 0. The r.e. is as follows: R = 1 (0+1)* 0 . 2) Write the regular expression for the language accepting all the string in which any number of a's is followed by any number of b's is followed by any number of c's. Solution: R = 3)Write the regular expression for the language starting and ending with a and having any having any combination of b's in between. R =
  • 12. Generate the Language using the regular expression: (0 +1)* : All strings of 0‟s and1‟s 0(0 +1)* : (0 +1)*1 : (0 + 1)*0(0+1)* : (0 + 1)*0(0 + 1)*0(0+1)* : (101*0)* : 1*(01*01*)* : (1*01*0)*1*: 4) Write the regular expression for the language over ∑ = {0} having even length of the string. R = 5) Write the regular expression for the language having a string which should have atleast one 0 and alteast one 1. R=
  • 13. 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.
  • 14. Formal Definition of FA A finite automaton is a collection of 5-tuple (Q, ∑, δ, q0, F), where: Q: finite set of states ∑: finite set of the input symbol q0: initial state F: final state δ: Transition function
  • 15. Finite Automata Model Finite automata can be represented by input tape and finite control. Input tape: It is a linear tape having some number of cells. Each input symbol is placed in each cell. Finite control: The finite control decides the next state on receiving particular input from input tape. The tape reader reads the cells one by one from left to right, and at a time only one input symbol is read.
  • 16. Types of Automata: There are two types of finite automata: 1.DFA(deterministic finite automata) 2.NFA(non-deterministic finite automata)
  • 17. 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. Some important points about DFA and NFA: 1.Every DFA is NFA, but NFA is not DFA. 2.There can be multiple final states in both NFA and DFA. 3.DFA is used in Lexical Analysis in Compiler. 4.NFA is more of a theoretical concept.
  • 18. 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.
  • 19. Formal Definition of DFA A DFA is a collection of 5-tuples same as we described in the definition of FA
  • 20. Examples of DFA 1)Design a FA with ∑ = {0, 1} accepts those string which starts with 1 and ends with 0. 2) Design a FA with ∑ = {0, 1} accepts the only input 101. 3) Design FA with ∑ = {0, 1} accepts even number of 0's and even number of 1's. 4) Design FA with ∑ = {0, 1} accepts the set of all strings with three consecutive 0's. 5) Design a FA with ∑ = {0, 1} accepts the strings with an even number of 0's followed by single 1.
  • 21. Minimization of DFA DFA minimization stands for converting a given DFA to its equivalent DFA with minimum number of states. DFA minimization is also called as Optimization of DFA and uses partitioning algorithm. Following are the various steps to minimize the DFA: Step 1: Remove all the states that are unreachable from the initial state via any set of the transition of DFA. Step 2: Draw the transition table for all pair of states Step 3: Now split the transition table into two tables T1 and T2. T1 contains all final states, and T2 contains non-final states. Step 4: Find similar rows from T1 such that: 1. δ (q, a) = p
  • 22. Step 6: Repeat step 3 and step 4 for table T2 also. Step 7: Now combine the reduced T1 and T2 tables. The combined transition table is the transition table of minimized DFA.
  • 23. NFA (Non-Deterministic finite automata) •NFA stands for non-deterministic finite automata. It is easy to construct an NFA than DFA for a given regular language. •The finite automata are called NFA when there exist many paths for specific input from the current state to the next state. •Every NFA is not DFA, but each NFA can be translated into DFA. •NFA is defined in the same way as DFA but with the following two exceptions, it contains multiple next states, and it contains ε transition.
  • 24. Formal definition of NFA: NFA also has five states same as DFA, but with different transition function,
  • 25. 1 NFA with ∑ = {0, 1} accepts all strings starting with 01.check w=010100 2) NFA with ∑ = {0, 1} and accept all string of length at least 2. w=11011011 3) Design an NFA with ∑ = {0, 1} in which double '1' is followed by double '0'. 4) Design an NFA in which all the string contain a substring 1110. 5) Using below table design NFA
  • 26. epsilon closure NFA with ∈ move: If any FA contains ε transaction or move, the finite automata is called NFA with ∈ move. ε-closure: ε-closure for a given state A means a set of states which can be reached from the state A with only ε (null) move including the state A itself.
  • 27.
  • 28. Eliminating ε Transitions NFA with ε can be converted to NFA without ε, and this NFA without ε can be converted to DFA. To do this, we will use a method, which can remove all the ε transition from given NFA.The method will be: 1.Find out all the ε transitions from each state from Q. That will be called as ε-closure{q1} where qi ∈ Q. 2.Then δ' transitions can be obtained. The δ' transitions mean a ε-closure on δ moves. 3.Repeat Step-2 for each input symbol and each state of given NFA. 4.Using the resultant states, the transition table for equivalent NFA without ε can be built.
  • 30.
  • 31.
  • 32.
  • 33. The Applications of Finite Automata Finite Automata (FA) – •For the designing of lexical analysis of a compiler. •For recognizing the pattern using regular expressions. •For the designing of the combination and sequential circuits using Mealy and Moore Machines. •Used in text editors. •For the implementation of spell checkers. •Can be used as a model for learning and decision making. •Can parse text to extract information and structure data.