SlideShare a Scribd company logo
1 of 5
2.4 From Regular Expression To DFAs

    An algorithm: translating a regular expression into a DFA via NFA.

    regular expression         NFA       DFA         program


2.4.1 From a regular expression to an NFA


    The idea of thompson’s construction:
      Use ε-transitions to “glue together” the machine of each piece of a regular
expression to form a machine that corresponds to the whole expression.

1. Basic regular expression:
      a basic regular expression is of the form a, ε,or φ

                 a




                 ε


2. Concatenation: rs
                                                 ε
                           r                                    s
                           ¨¨                                   ¨¨

  We have connected the accepting state of the machine of r to the start state of the
machine of s by anε-transition.
    The new machine has the start stale of the machine of r as its start state and the
accepting state of the machine of j as its accepting state.
    Clearly, this machine accepts L(rs) = L(r)L(s) and so corresponds to the regular
expression rs.

3. Choice among alternatives: r|s
             ε                  r
                                ¨¨                    ε




                                 s
             ε                                        ε
                                 ¨¨



   We have added a new start state and a new accepting state and connected them as
shown usingε-transitions.
   Clearly, this machine accepts the language L(r|s) =L(r )UL ( s).
                                             1
4. Repetition: construct a machine that corresponds to r*
       Given a machine that corresponds to r.




      We added two new states, a start state and an accepting state.

      The repetition in this machine is afforded by the newε-transition from the
 accepting state of the machine of r to its start state.

      We most also draw an ε-transition from the new start state to the new
 accepting state.

   This construction is not unique, simplifications are possible in the many cases.

Example 1: The regular expression ab|a

                                     a




                                         b




                                             2
Example 2: regular expression letter(letter|digit)*




  The machine for the choice letter |digit:
                            letter                              digit




 The NFA for the repetition (letter|digit) * as follows:
                                                      ε




    Finally, the NFA for the letter(letter|digit)*:        ε




2.4.2 from an NFA to a DFA


    Given an arbitrary NFA, construct an equivalent DFA. (i.e., one that accepts
precisely the same strings)
                                                3
We need some methods for:
    (1) Eliminating ε-transitions

         ε-closure: the set of all states reachable by ε-transitions from a state or states.

    (2) Eliminating multiple transitions from a state on a single input character.
        Keeping track of the set of states that are reachable by matching a single
         character.

    Both these processes lead us to consider sets of states instead of single states.
Thus, it is not surprising that the DFA we construct has as its states sets of states of the
original NFA.

The algorithm is called the subset construction.

1. The ε-closure of a Set of states:
   The ε-closure of a single state s is the set of states reachable by a series of zero or
more ε-transitions, and we write this set as s .
   Example 2.14: regular a*




   1 = { 1,2,4}, 2 ={2}, 3 ={2,3,4}, and 4 ={4}.

 The ε-closure of a set of states : the union of the ε-closures of each individual state.
          S= s
               sin S



 {1,3} = 1 ∪ 3 = {1,2,3}∪{2,3,4}={1,2,3,4}




                                             4
2. The Subset Construction:
   (1) compute the ε-closure of the start state of M; this becomes the start state of M
        .

    (2) For this set, and for each subsequent set, we compute transitions on characters
        a as follows.

              Given a set S of states and a character a in the alphabet,
              Compute the set
                  S′a = { t | for some s in S there is a transition from s to t on a }.
            Then, compute S a ' , the ε-closure of S′a.
           This defines a new state in the subset construction, together with a new
      transition S→ S a ' .

    (3) Continue with this process until no new states or transitions are created.

    (4) Mark as accepting those states constructed in this manner that contain an
     accepting state of M.

Example 2.15: consider the NFA of example 2.14




    M                        ε-closure of M ( S )           S′a
    1                        1,2,4                          2,3,4
    2,3,4                    2,3,4                          2,3,4

                                         a                     a




                                             5

More Related Content

What's hot

Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)bolovv
 
regular expressions (Regex)
regular expressions (Regex)regular expressions (Regex)
regular expressions (Regex)Rebaz Najeeb
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generationVipul Naik
 
Converting A Subset of LTL Formula to Buchi Automata
Converting A Subset of LTL Formula to Buchi Automata Converting A Subset of LTL Formula to Buchi Automata
Converting A Subset of LTL Formula to Buchi Automata ijseajournal
 
CONVERTING A SUBSET OF LTL FORMULA TO BUCHI AUTOMATA
CONVERTING A SUBSET OF LTL FORMULA TO BUCHI AUTOMATACONVERTING A SUBSET OF LTL FORMULA TO BUCHI AUTOMATA
CONVERTING A SUBSET OF LTL FORMULA TO BUCHI AUTOMATAmathsjournal
 
Automata
AutomataAutomata
AutomataGaditek
 
context free language
context free languagecontext free language
context free languagekhush_boo31
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generationRamchandraRegmi
 
Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generationIffat Anjum
 
AUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTESAUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTESsuthi
 
Managing I/O & String function in C
Managing I/O & String function in CManaging I/O & String function in C
Managing I/O & String function in CAbinaya B
 

What's hot (19)

Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)
 
regular expressions (Regex)
regular expressions (Regex)regular expressions (Regex)
regular expressions (Regex)
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generation
 
Converting A Subset of LTL Formula to Buchi Automata
Converting A Subset of LTL Formula to Buchi Automata Converting A Subset of LTL Formula to Buchi Automata
Converting A Subset of LTL Formula to Buchi Automata
 
CONVERTING A SUBSET OF LTL FORMULA TO BUCHI AUTOMATA
CONVERTING A SUBSET OF LTL FORMULA TO BUCHI AUTOMATACONVERTING A SUBSET OF LTL FORMULA TO BUCHI AUTOMATA
CONVERTING A SUBSET OF LTL FORMULA TO BUCHI AUTOMATA
 
Automata
AutomataAutomata
Automata
 
AI Lesson 13
AI Lesson 13AI Lesson 13
AI Lesson 13
 
AI Lesson 16
AI Lesson 16AI Lesson 16
AI Lesson 16
 
context free language
context free languagecontext free language
context free language
 
Cs419 lec7 cfg
Cs419 lec7   cfgCs419 lec7   cfg
Cs419 lec7 cfg
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Unit i
Unit iUnit i
Unit i
 
Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generation
 
Unit05 dbms
Unit05 dbmsUnit05 dbms
Unit05 dbms
 
Join dependency
Join dependencyJoin dependency
Join dependency
 
AUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTESAUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTES
 
Unit ii
Unit iiUnit ii
Unit ii
 
Managing I/O & String function in C
Managing I/O & String function in CManaging I/O & String function in C
Managing I/O & String function in C
 
Context free grammar
Context free grammarContext free grammar
Context free grammar
 

Viewers also liked

Principles of Compiler Design
Principles of Compiler DesignPrinciples of Compiler Design
Principles of Compiler DesignBabu Pushkaran
 
Chapter Three(1)
Chapter Three(1)Chapter Three(1)
Chapter Three(1)bolovv
 
Theory of computing
Theory of computingTheory of computing
Theory of computingRanjan Kumar
 
Two-way Deterministic Finite Automata
Two-way Deterministic Finite AutomataTwo-way Deterministic Finite Automata
Two-way Deterministic Finite AutomataHafsa.Naseem
 
Regular language and Regular expression
Regular language and Regular expressionRegular language and Regular expression
Regular language and Regular expressionAnimesh Chaturvedi
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compilerIffat Anjum
 
Compiler Design
Compiler DesignCompiler Design
Compiler DesignMir Majid
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysisraosir123
 

Viewers also liked (16)

Principles of Compiler Design
Principles of Compiler DesignPrinciples of Compiler Design
Principles of Compiler Design
 
Chapter Three(1)
Chapter Three(1)Chapter Three(1)
Chapter Three(1)
 
Theory of computing
Theory of computingTheory of computing
Theory of computing
 
Two-way Deterministic Finite Automata
Two-way Deterministic Finite AutomataTwo-way Deterministic Finite Automata
Two-way Deterministic Finite Automata
 
Regular language and Regular expression
Regular language and Regular expressionRegular language and Regular expression
Regular language and Regular expression
 
Automata 3
Automata 3Automata 3
Automata 3
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
 
Automata 1
Automata 1Automata 1
Automata 1
 
Automata 2
Automata 2Automata 2
Automata 2
 
Automata 4
Automata 4Automata 4
Automata 4
 
Automata 5
Automata 5Automata 5
Automata 5
 
Deterministic Finite Automata
Deterministic Finite AutomataDeterministic Finite Automata
Deterministic Finite Automata
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysis
 
Compiler Chapter 1
Compiler Chapter 1Compiler Chapter 1
Compiler Chapter 1
 

Similar to Chapter 2 2 1 1

Nondeterministic Finite Automata AFN.pdf
Nondeterministic Finite Automata AFN.pdfNondeterministic Finite Automata AFN.pdf
Nondeterministic Finite Automata AFN.pdfSergioUlisesRojasAla
 
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
 
CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...
CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...
CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...parmeet834
 
Chapter 2 2 1 2
Chapter 2 2 1 2Chapter 2 2 1 2
Chapter 2 2 1 2bolovv
 
Regular expression
Regular expressionRegular expression
Regular expressionRajon
 
1.4. finite automaton with ε moves
1.4. finite automaton with ε   moves1.4. finite automaton with ε   moves
1.4. finite automaton with ε movesSampath Kumar S
 
MidtermI-review.pptx
MidtermI-review.pptxMidtermI-review.pptx
MidtermI-review.pptxamara jyothi
 

Similar to Chapter 2 2 1 1 (20)

Nondeterministic Finite Automata AFN.pdf
Nondeterministic Finite Automata AFN.pdfNondeterministic Finite Automata AFN.pdf
Nondeterministic Finite Automata AFN.pdf
 
RegexCat
RegexCatRegexCat
RegexCat
 
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,
 
CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...
CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...
CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...
 
Hwsoln03 toc
Hwsoln03 tocHwsoln03 toc
Hwsoln03 toc
 
Chapter 2 2 1 2
Chapter 2 2 1 2Chapter 2 2 1 2
Chapter 2 2 1 2
 
Regular expression
Regular expressionRegular expression
Regular expression
 
1.4. finite automaton with ε moves
1.4. finite automaton with ε   moves1.4. finite automaton with ε   moves
1.4. finite automaton with ε moves
 
Chapter7
Chapter7Chapter7
Chapter7
 
Flat unit 2
Flat unit 2Flat unit 2
Flat unit 2
 
re1.ppt
re1.pptre1.ppt
re1.ppt
 
Re1 (3)
Re1 (3)Re1 (3)
Re1 (3)
 
re1.ppt
re1.pptre1.ppt
re1.ppt
 
re1.ppt
re1.pptre1.ppt
re1.ppt
 
MidtermI-review.pptx
MidtermI-review.pptxMidtermI-review.pptx
MidtermI-review.pptx
 
Pcd(Mca)
Pcd(Mca)Pcd(Mca)
Pcd(Mca)
 
PCD ?s(MCA)
PCD ?s(MCA)PCD ?s(MCA)
PCD ?s(MCA)
 
Pcd(Mca)
Pcd(Mca)Pcd(Mca)
Pcd(Mca)
 
Compiler Design Material 2
Compiler Design Material 2Compiler Design Material 2
Compiler Design Material 2
 
Theory of computation and automata
Theory of computation and automataTheory of computation and automata
Theory of computation and automata
 

More from bolovv

Chapter Seven(2)
Chapter Seven(2)Chapter Seven(2)
Chapter Seven(2)bolovv
 
Chapter Eight(3)
Chapter Eight(3)Chapter Eight(3)
Chapter Eight(3)bolovv
 
Chapter Five(2)
Chapter Five(2)Chapter Five(2)
Chapter Five(2)bolovv
 
Chapter One
Chapter OneChapter One
Chapter Onebolovv
 
Chapter Seven(1)
Chapter Seven(1)Chapter Seven(1)
Chapter Seven(1)bolovv
 
Chapter Eight(1)
Chapter Eight(1)Chapter Eight(1)
Chapter Eight(1)bolovv
 
Chapter 1 1
Chapter 1 1Chapter 1 1
Chapter 1 1bolovv
 

More from bolovv (7)

Chapter Seven(2)
Chapter Seven(2)Chapter Seven(2)
Chapter Seven(2)
 
Chapter Eight(3)
Chapter Eight(3)Chapter Eight(3)
Chapter Eight(3)
 
Chapter Five(2)
Chapter Five(2)Chapter Five(2)
Chapter Five(2)
 
Chapter One
Chapter OneChapter One
Chapter One
 
Chapter Seven(1)
Chapter Seven(1)Chapter Seven(1)
Chapter Seven(1)
 
Chapter Eight(1)
Chapter Eight(1)Chapter Eight(1)
Chapter Eight(1)
 
Chapter 1 1
Chapter 1 1Chapter 1 1
Chapter 1 1
 

Recently uploaded

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
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 productivityPrincipled Technologies
 
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?Igalia
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
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...Miguel Araújo
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
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 Scriptwesley chun
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 

Recently uploaded (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
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?
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
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...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

Chapter 2 2 1 1

  • 1. 2.4 From Regular Expression To DFAs An algorithm: translating a regular expression into a DFA via NFA. regular expression NFA DFA program 2.4.1 From a regular expression to an NFA The idea of thompson’s construction: Use ε-transitions to “glue together” the machine of each piece of a regular expression to form a machine that corresponds to the whole expression. 1. Basic regular expression: a basic regular expression is of the form a, ε,or φ a ε 2. Concatenation: rs ε r s ¨¨ ¨¨ We have connected the accepting state of the machine of r to the start state of the machine of s by anε-transition. The new machine has the start stale of the machine of r as its start state and the accepting state of the machine of j as its accepting state. Clearly, this machine accepts L(rs) = L(r)L(s) and so corresponds to the regular expression rs. 3. Choice among alternatives: r|s ε r ¨¨ ε s ε ε ¨¨ We have added a new start state and a new accepting state and connected them as shown usingε-transitions. Clearly, this machine accepts the language L(r|s) =L(r )UL ( s). 1
  • 2. 4. Repetition: construct a machine that corresponds to r* Given a machine that corresponds to r. We added two new states, a start state and an accepting state. The repetition in this machine is afforded by the newε-transition from the accepting state of the machine of r to its start state. We most also draw an ε-transition from the new start state to the new accepting state. This construction is not unique, simplifications are possible in the many cases. Example 1: The regular expression ab|a a b 2
  • 3. Example 2: regular expression letter(letter|digit)* The machine for the choice letter |digit: letter digit The NFA for the repetition (letter|digit) * as follows: ε Finally, the NFA for the letter(letter|digit)*: ε 2.4.2 from an NFA to a DFA Given an arbitrary NFA, construct an equivalent DFA. (i.e., one that accepts precisely the same strings) 3
  • 4. We need some methods for: (1) Eliminating ε-transitions ε-closure: the set of all states reachable by ε-transitions from a state or states. (2) Eliminating multiple transitions from a state on a single input character. Keeping track of the set of states that are reachable by matching a single character. Both these processes lead us to consider sets of states instead of single states. Thus, it is not surprising that the DFA we construct has as its states sets of states of the original NFA. The algorithm is called the subset construction. 1. The ε-closure of a Set of states: The ε-closure of a single state s is the set of states reachable by a series of zero or more ε-transitions, and we write this set as s . Example 2.14: regular a* 1 = { 1,2,4}, 2 ={2}, 3 ={2,3,4}, and 4 ={4}. The ε-closure of a set of states : the union of the ε-closures of each individual state. S= s sin S {1,3} = 1 ∪ 3 = {1,2,3}∪{2,3,4}={1,2,3,4} 4
  • 5. 2. The Subset Construction: (1) compute the ε-closure of the start state of M; this becomes the start state of M . (2) For this set, and for each subsequent set, we compute transitions on characters a as follows. Given a set S of states and a character a in the alphabet, Compute the set S′a = { t | for some s in S there is a transition from s to t on a }. Then, compute S a ' , the ε-closure of S′a. This defines a new state in the subset construction, together with a new transition S→ S a ' . (3) Continue with this process until no new states or transitions are created. (4) Mark as accepting those states constructed in this manner that contain an accepting state of M. Example 2.15: consider the NFA of example 2.14 M ε-closure of M ( S ) S′a 1 1,2,4 2,3,4 2,3,4 2,3,4 2,3,4 a a 5