Review: NFA Definition NFA is non-deterministic in what sense?

Slides:



Advertisements
Similar presentations
CSE 311 Foundations of Computing I
Advertisements

4b Lexical analysis Finite Automata
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
Finite Automata CPSC 388 Ellen Walker Hiram College.
1 CIS 461 Compiler Design and Construction Fall 2012 slides derived from Tevfik Bultan et al. Lecture-Module 5 More Lexical Analysis.
Compiler Construction
Lecture # 5. Topics Minimization of DFA Examples What are the Important states of NFA? How to convert a Regular Expression directly into a DFA ?
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state.
1 The scanning process Main goal: recognize words/tokens Snapshot: At any point in time, the scanner has read some input and is on the way to identifying.
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.
Fall 2004COMP 3351 Single Final State for NFA. Fall 2004COMP 3352 Any NFA can be converted to an equivalent NFA with a single final state.
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
Decidable Questions About Regular languages 1)Membership problem: “Given a specification of known type and a string w, is w in the language specified?”
CS412/413 Introduction to Compilers Radu Rugina Lecture 4: Lexical Analyzers 28 Jan 02.
TRANSITION DIAGRAM BASED LEXICAL ANALYZER and FINITE AUTOMATA Class date : 12 August, 2013 Prepared by : Karimgailiu R Panmei Roll no. : 11CS10020 GROUP.
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,
Lexical Analysis: Finite Automata CS 471 September 5, 2007.
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.
CMSC 330: Organization of Programming Languages Theory of Regular Expressions NFAs  DFAs.
Lexical Analysis – Part II EECS 483 – Lecture 3 University of Michigan Wednesday, September 13, 2006.
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.
Chapter 5 Finite Automata Finite State Automata n Capable of recognizing numerous symbol patterns, the class of regular languages n Suitable for.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Complexity and Computability Theory I Lecture #5 Rina Zviel-Girshin Leah Epstein Winter
CS412/413 Introduction to Compilers Radu Rugina Lecture 3: Finite Automata 25 Jan 02.
June 13, 2016 Prof. Abdelaziz Khamis 1 Chapter 2 Scanning – Part 2.
Converting Regular Expressions to NFAs Empty string   is a regular expression denoting  {  } a is a regular expression denoting {a} for any a in 
 2005 SDU Lecture11 Decidability.  2005 SDU 2 Topics Discuss the power of algorithms to solve problems. Demonstrate that some problems can be solved.
1/29/02CSE460 - MSU1 Nondeterminism-NFA Section 4.1 of Martin Textbook CSE460 – Computability & Formal Language Theory Comp. Science & Engineering Michigan.
Department of Software & Media Technology
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.
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
CIS Automata and Formal Languages – Pei Wang
Lexical analysis Finite Automata
Properties of Regular Languages
Finite-State Machines (FSMs)
Chapter 2 Finite Automata
The time complexity for e-closure(T).
PDAs Accept Context-Free Languages
Two issues in lexical analysis
Recognizer for a Language
Single Final State for NFA
Jaya Krishna, M.Tech, Assistant Professor
Decision Properties of Regular Languages
Lecture 5: Lexical Analysis III: The final bits
COSC 3340: Introduction to Theory of Computation
4. Properties of Regular Languages
Decidable Languages Costas Busch - LSU.
Lecture 4 (new improved) Subset construction NFA  DFA
Lecture 4: Lexical Analysis II: From REs to DFAs
Transition Diagrams Lecture 3 Fri, Jan 21, 2005.
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
4b Lexical analysis Finite Automata
Chapter 1 Regular Language
Regular Language Equivalence and DFA Minimization
Lecture 5 Scanning.
Lexical Analysis Uses formalism of Regular Languages
Presentation transcript:

Review: NFA Definition NFA is non-deterministic in what sense? Time complexity of the algorithm to determine whether a string can be recognized by an NFA. Algorithm to convert a regular expression to an NFA.

The algorithm that recognizes the language accepted by NFA(revisit). Input: an NFA (transition table) and a string x (terminated by eof). output “yes” if accepted, “no” otherwise. S = e-closure({s0}); a = nextchar; while a != eof do begin S = e-closure(move(S, a)); a := next char; end if (intersect (S, F) != empty) then return “yes” else return “no” Time complexity O(|S|^2|x|) : With transition e-closure is a set, move({s}, a) may also be a set. Converting a NFA to a DFA that recognizes the same language: starting from and assign each set to a new state. Example: Figure 3.27 in page 120.

Algorithm to convert an NFA to a DFA that accepts the same language (algorithm 3.2, page 118) initially e-closure(s0) is the only state in Dstates and it is marked while there is an unmarked state T in Dstates do begin mark T; for each input symbol a do begin U := e-closure(move(T, a)); if (U is not in Dstates) then add U as an unmarked state to Dstates; Dtran[T, a] := U; end end; Initial state = e-closure(s0), Final state = ?

Question: for a NFA with |S| states, at most how many states can its corresponding DFA have? Using DFA or NFA?? Trade-off between space and time!!

The number of states determines the space complexity. A DFA can potentially have a large number of states. Converting an NFA to a DFA may not result in the minimum-state DFA. In the final product, we would like to construct a DFA with the minimum number of states (while still recognizing the same language). Basic idea: assuming all states have a transition on every input symbol (what if this is not the case??), find all groups of states that can be distinguished by some input strings. An input string w distinguishes two states s and t, if starting from s and feeding w, we end up in a non-accepting state while starting from t and feeding w, we end up in an accepting state, or vice versa.

Algorithm (3.6, page 142): Input: a DFA M output: a minimum state DFA M’ If some states in M ignore some inputs, add transitions to a “dead” state. Let P = {All accepting states, All nonaccepting states} Let P’ = {} Loop: for each group G in P do Partition G into subgroups so that s and t (in G) belong to the same subgroup if and only if each input a moves s and t to the same state of the same group in P put the new subgroups in P’ if (P != P’) {P = P’; goto loop} Remove any dead states and unreachable states (transition between groups can be inferred).

Lex implementation: Example: minimize the DFA for Fig 3.29 (pages 121) Regular expression  NFA  DFA  optimized DFA How to deal with multiple regular expressions?