Lecture # 5. Topics Minimization of DFA Examples What are the Important states of NFA? How to convert a Regular Expression directly into a DFA ?

Slides:



Advertisements
Similar presentations
Lexical Analysis Arial Font Family.
Advertisements

4b Lexical analysis Finite Automata
Complexity and Computability Theory I Lecture #4 Rina Zviel-Girshin Leah Epstein Winter
CPSC Compiler Tutorial 4 Midterm Review. Deterministic Finite Automata (DFA) Q: finite set of states Σ: finite set of “letters” (input alphabet)
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
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)*
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University 2005.
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
Compiler Construction Sohail Aslam Lecture Finite Automaton of Items Then for every item A →  X  we must add an  -transition for every production.
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
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.
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.
CS 310 – Fall 2006 Pacific University CS310 Decidability Section 4.1/4.2 November 10, 2006.
1 Single Final State for NFAs and DFAs. 2 Observation Any Finite Automaton (NFA or DFA) can be converted to an equivalent NFA with a single final state.
Lecture 7 Sept 22, 2011 Goals: closure properties regular expressions.
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
Lecture 5UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 5.
1 Pertemuan Lexical Analysis (Scanning) Matakuliah: T0174 / Teknik Kompilasi Tahun: 2005 Versi: 1/6.
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Regular Languages and Expressions
CS 540 Spring CS 540 Spring 2013 GMU2 The Course covers: Lexical Analysis Syntax Analysis Semantic Analysis Runtime environments Code Generation.
Regular Expressions (RE) Empty set Φ A RE denotes the empty set Empty string λ A RE denotes the set {λ} Symbol a A RE denotes the set {a} Alternation M.
Thompson Construction, Subset Construction Thompson Construction, Subset Construction Continue….. LECTURE 7.
Chapter 3 Chang Chi-Chung The Role of the Lexical Analyzer Lexical Analyzer Parser Source Program Token Symbol Table getNextToken error.
CS308 Compiler Principles Lexical Analyzer Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Fall 2012.
Overview of Previous Lesson(s) Over View  Strategies that have been used to implement and optimize pattern matchers constructed from regular expressions.
Lecture # 3 Chapter #3: Lexical Analysis. Role of Lexical Analyzer It is the first phase of compiler Its main task is to read the input characters and.
Overview of Previous Lesson(s) Over View  An NFA accepts a string if the symbols of the string specify a path from the start to an accepting state.
Thompson Construction Prepared by: Anupam Prakash 04CS1017.
Transition Diagrams Lecture 3 Wed, Jan 21, Building Transition Diagrams from Regular Expressions A regular expression consists of symbols a, b,
Chapter 3 Chang Chi-Chung The Role of the Lexical Analyzer Lexical Analyzer Parser Source Program Token Symbol Table getNextToken error.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
1 Lexical Analysis and Lexical Analyzer Generators Chapter 3 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University,
Pembangunan Kompilator.  A recognizer for a language is a program that takes a string x, and answers “yes” if x is a sentence of that language, and.
Lecture # 4 Chapter 1 (Left over Topics) Chapter 3 (continue)
CMSC 330: Organization of Programming Languages Finite Automata NFAs  DFAs.
Fall 2003CS416 Compiler Design1 Lexical Analyzer Lexical Analyzer reads the source program character by character to produce tokens. Normally a lexical.
Overview of Previous Lesson(s) Over View  Algorithm for converting RE to an NFA.  The algorithm is syntax- directed, it works recursively up the parse.
Lexical Analyzer CS308 Compiler Theory1. 2 Lexical Analyzer Lexical Analyzer reads the source program character by character to produce tokens. Normally.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2007.
1 February 23, February 23, 2016February 23, 2016February 23, 2016 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University.
using Deterministic Finite Automata & Nondeterministic Finite Automata
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.
LECTURE 5 Scanning. SYNTAX ANALYSIS We know from our previous lectures that the process of verifying the syntax of the program is performed in two stages:
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2006.
Deterministic Finite Automata Nondeterministic Finite Automata.
1 1. Eliminate all  -transitions from the following FA without changing the number of states and the language accepted by the automaton. You should also.
CS412/413 Introduction to Compilers Radu Rugina Lecture 3: Finite Automata 25 Jan 02.
Converting Regular Expressions to NFAs Empty string   is a regular expression denoting  {  } a is a regular expression denoting {a} for any a in 
Lecture 2 Compiler Design Lexical Analysis By lecturer Noor Dhia
COMP 3438 – Part II - Lecture 3 Lexical Analysis II Par III: Finite Automata Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ. 1.
Deterministic Finite-State Machine (or Deterministic Finite Automaton) A DFA is a 5-tuple, (S, Σ, T, s, A), consisting of: S: a finite set of states Σ:
Introduction to Lexical Analysis
CS314 – Section 5 Recitation 3
The time complexity for e-closure(T).
Two issues in lexical analysis
Review: NFA Definition NFA is non-deterministic in what sense?
Lexical Analysis and Lexical Analyzer Generators
Properties of Regular Languages
COSC 3340: Introduction to Theory of Computation
4. Properties of Regular Languages
Non-Deterministic Finite Automata
Lecture 4: Lexical Analysis II: From REs to DFAs
Animated Conversion of Regular Expressions to C Code
Theory of Computation Lecture #
This method is used for converting an
Finite Automata & Language Theory
Chapter 3. Lexical Analysis (2)
Regular Language Equivalence and DFA Minimization
Presentation transcript:

Lecture # 5

Topics Minimization of DFA Examples What are the Important states of NFA? How to convert a Regular Expression directly into a DFA ?

Example # 2 The DFA for a(b|c)*

Example #2: Applying Minimization

Example # 3 Minimize the following DFA:

Example 3: Minimized

Example # 4 Minimize the following DFA: AB C D E b b b b b a a a a a A start BD E bb a a b a a

8 Section 3.9: From Regular Expression to DFA Directly The “important states” of an NFA are those without an  -transition, that is if move({s},a)   for some a then s is an important state The subset construction algorithm uses only the important states when it determines  -closure(move(T,a))

9 From Regular Expression to DFA Directly (Algorithm) Augment the regular expression r with a special end symbol # to make accepting states important: the new expression is r# Construct a syntax tree for r# Traverse the tree to construct functions nullable, firstpos, lastpos, and followpos

10 From Regular Expression to DFA Directly: Syntax Tree of ( a | b )* abb# * | 1 a 2 b 3 a 4 b 5 b # 6 concatenation closure alternation position number (for leafs  )

11 From Regular Expression to DFA Directly: Annotating the Tree nullable(n): the sub tree at node n generates languages including the empty string firstpos(n): set of positions that can match the first symbol of a string generated by the sub tree at node n lastpos(n): the set of positions that can match the last symbol of a string generated be the sub tree at node n followpos(i): the set of positions that can follow position i in the tree

12 From Regular Expression to DFA Directly: Annotating the Tree Node nnullable(n)firstpos(n)lastpos(n) Leaf  true  Leaf ifalse{i}{i}{i}{i} | / \ c 1 c 2 nullable(c 1 ) or nullable(c 2 ) firstpos(c 1 )  firstpos(c 2 ) lastpos(c 1 )  lastpos(c 2 ) / \ c 1 c 2 nullable(c 1 ) and nullable(c 2 ) if nullable(c 1 ) then firstpos(c 1 )  firstpos(c 2 ) else firstpos(c 1 ) if nullable(c 2 ) then lastpos(c 1 )  lastpos(c 2 ) else lastpos(c 2 ) *|c1*|c1 truefirstpos(c 1 )lastpos(c 1 )

13 From Regular Expression to DFA Directly: Syntax Tree of ( a | b )* abb# {6}{1, 2, 3} {5}{1, 2, 3} {4}{1, 2, 3} {3}{1, 2, 3} {1, 2} * | {1} a {2} b {3} a {4} b {5} b {6} # nullable firstposlastpos

14 From Regular Expression to DFA Directly: followpos for each node n in the tree do if n is a cat-node with left child c 1 and right child c 2 then for each i in lastpos(c 1 ) do followpos(i) := followpos(i)  firstpos(c 2 ) end do else if n is a star-node for each i in lastpos(n) do followpos(i) := followpos(i)  firstpos(n) end do end if end do

15 From Regular Expression to DFA Directly: Algorithm s 0 := firstpos(root) where root is the root of the syntax tree Dstates := {s 0 } and is unmarked while there is an unmarked state T in Dstates do mark T for each input symbol a   do let U be the set of positions that are in followpos(p) for some position p in T, such that the symbol at position p is a if U is not empty and not in Dstates then add U as an unmarked state to Dstates end if Dtran[T,a] := U end do end do

16 From Regular Expression to DFA Directly: Example 1,2,3 start a 1,2, 3,4 1,2, 3,6 1,2, 3,5 bb bb a a a Nodefollowpos 1{1, 2, 3} 2 3{4} 4{5} 5{6}

17 Time-Space Tradeoffs Automaton Space (worst case) Time (worst case) NFA O(r)O(r)O(  r  x  ) DFAO(2 |r| ) O(x)O(x)