Theory of Computation Lecture # 11-12-13-14.

Slides:



Advertisements
Similar presentations
Lexical Analysis IV : NFA to DFA DFA Minimization
Advertisements

4b Lexical analysis Finite Automata
CSC 361NFA vs. DFA1. CSC 361NFA vs. DFA2 NFAs vs. DFAs NFAs can be constructed from DFAs using transitions: Called NFA- Suppose M 1 accepts L 1, M 2 accepts.
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
Lecture 8 From NFA to Regular Language. Induction on k= # of states other than initial and final states K=0 a a* b a c d c*a(d+bc*a)*
Finite Automata CPSC 388 Ellen Walker Hiram College.
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
CS 310 – Fall 2006 Pacific University CS310 Converting NFA to DFA Sections:1.2 Page 54 September 15, 2006.
Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by.
1 The scanning process Goal: automate the process Idea: –Start with an RE –Build a DFA How? –We can build a non-deterministic finite automaton (Thompson's.
Lecture 3: Closure Properties & Regular Expressions Jim Hook Tim Sheard Portland State University.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Regular.
Regular Expression to NFA-  (a+ba) * a. First Parsing Step concatenate (a+ba) * a.
Lecture 7 Sept 22, 2011 Goals: closure properties regular expressions.
CS5371 Theory of Computation Lecture 6: Automata Theory IV (Regular Expression = NFA = DFA)
1 A Single Final State for Finite Accepters. 2 Observation Any Finite Accepter (NFA or DFA) can be converted to an equivalent NFA with a single final.
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Thompson Construction, Subset Construction Thompson Construction, Subset Construction Continue….. LECTURE 7.
Cs3102: Theory of Computation Class 4: Nondeterminism Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.
CS-5800 Theory of Computation II PROJECT PRESENTATION By Quincy Campbell & Sandeep Ravikanti.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to DFA.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
COMP3190: Principle of Programming Languages DFA and its equivalent, scanner.
Transition Diagrams Lecture 3 Wed, Jan 21, Building Transition Diagrams from Regular Expressions A regular expression consists of symbols a, b,
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to.
Finite Automata Chapter 1. Automatic Door Example Top View.
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
Finite Automata & Regular Languages Sipser, Chapter 1.
Overview of Previous Lesson(s) Over View  A token is a pair consisting of a token name and an optional attribute value.  A pattern is a description.
Jianguo Lu : Lab 3 Jan 30, Winter 2004.
1 Introduction to the Theory of Computation Regular Expressions.
Compiler Construction Lecture Three: Lexical Analysis - Part Two CSC 2103: Compiler Construction Lecture Three: Lexical Analysis - Part Two Joyce Nakatumba-Nabende.
Converting Regular Expressions to NFAs Empty string   is a regular expression denoting  {  } a is a regular expression denoting {a} for any a in 
Page 1. 1)Let B n = { a k | where k is a multiple of n}. I.e. B 1 = { a k | where k is a multiple of 1} = { a k | k Є {0,1,2,3,…}} = {‘’, a, aa, aaa, aaaa,
1/29/02CSE460 - MSU1 Nondeterminism-NFA Section 4.1 of Martin Textbook CSE460 – Computability & Formal Language Theory Comp. Science & Engineering Michigan.
Animated Conversion of Regular Expressions to C Code On the regular expression: ((a ⋅ b)|c) *
CIS Automata and Formal Languages – Pei Wang
Theory of Computation Lecture #
Lexical analysis Finite Automata
Formal Language & Automata Theory
Chapter 2 Finite Automata
Theory of Computation Lecture # 9-10.
Lecture 9 Theory of AUTOMATA
Two issues in lexical analysis
Recognizer for a Language
Review: NFA Definition NFA is non-deterministic in what sense?
Single Final State for NFA
Jaya Krishna, M.Tech, Assistant Professor
Decision Properties of Regular Languages
CS 154, Lecture 3: DFANFA, Regular Expressions.
Principles of Computing – UFCFA3-30-1
COSC 3340: Introduction to Theory of Computation
4. Properties of Regular Languages
Recognition of Tokens.
Lecture 4: Lexical Analysis II: From REs to DFAs
Transition Diagrams Lecture 3 Fri, Jan 21, 2005.
Animated Conversion of Regular Expressions to C Code
CS 350 — Fall 2018 gilray.org/classes/fall2018/cs350/
This method is used for converting an
NFA TO DFA.
Finite Automata.
4b Lexical analysis Finite Automata
Finite Automata & Language Theory
CSCI 2670 Introduction to Theory of Computing
Chapter 3. Lexical Analysis (2)
4b Lexical analysis Finite Automata
Principles of Computing – UFCFA3-30-1
NFA’s With ε-Transitions
CSCI 2670 Introduction to Theory of Computing
CSCI 2670 Introduction to Theory of Computing
Presentation transcript:

Theory of Computation Lecture # 11-12-13-14

THOMPSON’S Construction Method Convert the regular expression to an NFA ((a⋅ b)|c)* Divide regular expression into terms call the r’s

THOMPSON’S Construction

THOMPSON’S Construction

THOMPSON’S Construction

THOMPSON’S Construction

THOMPSON’S Construction

THOMPSON’S Construction

SUBSET Construction Method Convert the NFA to a DFA

SUBSET Construction Method Draw transition table for DFA

SUBSET Construction Method Add 𝜀-closure(9) as DFA start state D states means DFA states

SUBSET Construction Method Mark state A D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(A, a)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(A, b)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(A, c)) D states means DFA states

SUBSET Construction Method Mark B D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(B, a)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(B, b)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(B, c)) D states means DFA states

SUBSET Construction Method Mark C D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(C, a)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(C, b)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(C, c)) D states means DFA states

SUBSET Construction Method Mark D D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(D, a)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(D, b)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(D, c)) D states means DFA states

SUBSET Construction Method Draw DFA D states means DFA states

Another Example D states means DFA states

Thompson Construction First we construct the union of a and b A union b thompson construction

Thompson Construction Now for kleen start A union b kleen start thompson construction

Thompson Construction Now the union of and c is A union b kleen start thompson construction

Conversion to DFA Using Subset Construction A union b kleen start thompson construction

SUBSET Construction Method

SUBSET Construction Method Compute 𝜀-closure(move(0, a)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(0, b)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(0, c)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(1, a)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(1, b)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(1, c)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(2, a)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(2, b)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(2, c)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(3, a)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(3, b)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(3, c)) D states means DFA states

Another Example D states means DFA states

NFA Construction The concatenation steps to construct the transition graph of aaa are omitted for simplicity

NFA Construction The concatenation steps to construct the transition graph of aa are omitted for simplicity

NFA Construction

SUBSET Construction Method First of all we calculate e-closure of start state

SUBSET Construction Method Compute 𝜀-closure(move(0, a)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(0, b)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(1, a)) and 𝜀-closure(move(1, b)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(2, a)) and 𝜀-closure(move(2, b)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(3, a)) and 𝜀-closure(move(3, b)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(4, a)) and 𝜀-closure(move(4, b)) D states means DFA states

SUBSET Construction Method Compute 𝜀-closure(move(5, a)) and 𝜀-closure(move(5, b)) D states means DFA states

Some more examples of NFA (aa+bb)* e-closure(0)={0,1,4,7}*=A

Some more examples of NFA (a+b)* e-closure(0)={0,1,2,4,7}=A

Some more examples of NFA (a+b)*abb e-closure(0)={0,1,2,4,7}=A

Minimization of DFA Removal of dead states. For any DFA there is a DFA with equal or fewer states that matches exactly the same language. In other words, there can be several DFAs that represent a language, some will be bigger than others and only one will be minimal. To minimize a DFA three steps must be performed: Removal of dead states. Removal of inaccessible states. Merging of identical states.

Removal of Dead States A dead states is a state that only leads to itself for every symbol in the alphabet. As we can see in this fairly contrived example: In the diagram above the non-final state 1, once reached, can never be left. If it was a final state it would be meaningful but as it is it can be disposed of.

Removal of Inaccessible States An inaccessible state is one that cannot be reached no matter what word is given to the DFA. As we can see in the above diagram there is no way to ever reach state 1. As such it can be removed.

Merging of Identical States There are some states that move to exactly to the same states for the same symbols as other states do.

Merging of Identical States DFA with redundant state_removed