Java II Finite Automata I

Similar documents
AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Kleene-*

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

CMSC 330: Organization of Programming Languages

Minimal DFA. minimal DFA for L starting from any other

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb.

Theory of Computation Regular Languages. (NTU EE) Regular Languages Fall / 38

Lexical Analysis Part III

Theory of Computation Regular Languages

Java II Finite Automata I

Designing finite automata II

Regular expressions, Finite Automata, transition graphs are all the same!!

Convert the NFA into DFA

Non-deterministic Finite Automata

Worked out examples Finite Automata

CS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

Non-deterministic Finite Automata

Chapter 1, Part 1. Regular Languages. CSC527, Chapter 1, Part 1 c 2012 Mitsunori Ogihara 1

Scanner. Specifying patterns. Specifying patterns. Operations on languages. A scanner must recognize the units of syntax Some parts are easy:

Chapter 2 Finite Automata

CHAPTER 1 Regular Languages. Contents. definitions, examples, designing, regular operations. Non-deterministic Finite Automata (NFA)

Formal Languages and Automata

Deterministic Finite Automata

CHAPTER 1 Regular Languages. Contents

CMSC 330: Organization of Programming Languages. DFAs, and NFAs, and Regexps (Oh my!)

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)

Chapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1

Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute

Lexical Analysis Finite Automate

Automata Theory 101. Introduction. Outline. Introduction Finite Automata Regular Expressions ω-automata. Ralf Huuck.

NFA DFA Example 3 CMSC 330: Organization of Programming Languages. Equivalence of DFAs and NFAs. Equivalence of DFAs and NFAs (cont.

CSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages

Finite Automata-cont d

CISC 4090 Theory of Computation

Speech Recognition Lecture 2: Finite Automata and Finite-State Transducers

Non Deterministic Automata. Linz: Nondeterministic Finite Accepters, page 51

Finite-State Automata: Recap

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2016

Lecture 08: Feb. 08, 2019

Finite Automata. Informatics 2A: Lecture 3. John Longley. 22 September School of Informatics University of Edinburgh

Let's start with an example:

More on automata. Michael George. March 24 April 7, 2014

Nondeterminism and Nodeterministic Automata

1 Nondeterministic Finite Automata

Formal Language and Automata Theory (CS21004)

Finite Automata. Informatics 2A: Lecture 3. Mary Cryan. 21 September School of Informatics University of Edinburgh

FABER Formal Languages, Automata and Models of Computation

CS375: Logic and Theory of Computing

Nondeterminism. Nondeterministic Finite Automata. Example: Moves on a Chessboard. Nondeterminism (2) Example: Chessboard (2) Formal NFA

NFAs and Regular Expressions. NFA-ε, continued. Recall. Last class: Today: Fun:

NFAs continued, Closure Properties of Regular Languages

Formal languages, automata, and theory of computation

Speech Recognition Lecture 2: Finite Automata and Finite-State Transducers. Mehryar Mohri Courant Institute and Google Research

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Non-Deterministic Finite Automata. Fall 2018 Costas Busch - RPI 1

Grammar. Languages. Content 5/10/16. Automata and Languages. Regular Languages. Regular Languages

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

Homework 3 Solutions

CS:4330 Theory of Computation Spring Regular Languages. Equivalences between Finite automata and REs. Haniel Barbosa

a,b a 1 a 2 a 3 a,b 1 a,b a,b 2 3 a,b a,b a 2 a,b CS Determinisitic Finite Automata 1

Non-Deterministic Finite Automata

Compiler Design. Fall Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

80 CHAPTER 2. DFA S, NFA S, REGULAR LANGUAGES. 2.6 Finite State Automata With Output: Transducers

Harvard University Computer Science 121 Midterm October 23, 2012

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2014

Languages & Automata

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014

First Midterm Examination

Fundamentals of Computer Science

Non Deterministic Automata. Formal Languages and Automata - Yonsei CS 1

Regular languages refresher

Some Theory of Computation Exercises Week 1

Section: Other Models of Turing Machines. Definition: Two automata are equivalent if they accept the same language.

3 Regular expressions

CS375: Logic and Theory of Computing

Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem 2/16/15

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

input tape head moves current state

NFAs continued, Closure Properties of Regular Languages

1 From NFA to regular expression

Lecture 9: LTL and Büchi Automata

Coalgebra, Lecture 15: Equations for Deterministic Automata

CS 311 Homework 3 due 16:30, Thursday, 14 th October 2010

Thoery of Automata CS402

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018

ɛ-closure, Kleene s Theorem,

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

State Minimization for DFAs

CS 275 Automata and Formal Language Theory

Lecture 6 Regular Grammars

11.1 Finite Automata. CS125 Lecture 11 Fall Motivation: TMs without a tape: maybe we can at least fully understand such a simple model?

Myhill-Nerode Theorem

Name Ima Sample ASU ID

GNFA GNFA GNFA GNFA GNFA

Normal Forms for Context-free Grammars

Agenda. Agenda. Regular Expressions. Examples of Regular Expressions. Regular Expressions (crash course) Computational Linguistics 1

Closure Properties of Regular Languages

Table of contents: Lecture N Summary... 3 What does automata mean?... 3 Introduction to languages... 3 Alphabets... 3 Strings...

Transcription:

Jv II Finite Automt I Bernd Kiefer Bernd.Kiefer@dfki.de Deutsches Forschungszentrum für künstliche Intelligenz Finite Automt I p.1/13

Processing Regulr Expressions We lredy lerned out Jv s regulr expression functionlity Now we get to know the mchinery ehind Pttern nd Mtcher clsses Compiling regulr expression into Pttern oject produces Finite Automton This utomton is then used to perform the mtching tsks We will see how to construct finite utomton tht recognizes n input string, i.e., tries to find full mtch Finite Automt I p.2/13

Definition: Finite Automton A finite utomton (FA) is tuple A =< Q,Σ,δ,q 0,F > Q finite non-empty set of sttes Σ finite lphet of input letters δ (totl) trnsition function Q Σ Q q 0 Q the initil stte F Q the set of finl (ccepting) sttes Trnsition grphs (digrms): initil stte sttes trnsition finl stte d o g q 0 q 1 q 2 q 3 Finite Automt I p.3/13

Finite Automt: Mtching A finite utomton ccepts given input string s if there is sequence of sttes p 1,p 2,...,p s Q such tht 1. p 1 = q 0, the strt stte 2. δ(p i,s i ) = p i+1, where s i is the i-th chrcter in s 3. p s F, i.e., finl stte A string is successfully mtched if we hve found the pproprite sequence of sttes Imgine the string on n input tpe with pointer tht is dvnced when using δ trnsition The set of strings ccepted y n utomton is the ccepted lnguge, nlogous to regulr expressions Finite Automt I p.4/13

(Non)deterministic Automt in the definition of utomt, δ ws totl function given n input string, the pth through the utomton is uniquely determined those utomt re therefore clled deterministic for nondeterministic FA, δ is trnsition reltion δ : Q Σ {} P(Q), where P(Q) is the powerset of Q llows trnsitions from one stte into severl sttes with the sme input symol need not e totl cn hve trnsitions leled (not in Σ), which represents the empty string Finite Automt I p.5/13

RegExps Automt Construct nondeterminstic utomt from regulr expressions (αβ) q 0α... q fα q 0β... q fβ (α β) q 0α... q fα q 0β... q fβ q 0 q f (α) q 0α... q fα q 0 q f Finite Automt I p.6/13

NFA vs. DFA Trversing DFA is esy given the input string: the pth is uniquely determined In contrst, trversing n NFA requires keeping trck of set of (current) sttes, strting with the set {q o } Processing the next input symol mens tking ll possile outgoing trnsitions from this set nd collecting the new set From every NFA, n equivlent DFA (one which does ccept the sme lnguge), cn e computed Bsic Ide: trck the susets tht cn e reched for every possile input Finite Automt I p.7/13

Trversing n NFA Finite Automt I p.8/13

Trversing n NFA Finite Automt I p.8/13

Trversing n NFA Finite Automt I p.8/13

Trversing n NFA Finite Automt I p.8/13

Trversing n NFA Finite Automt I p.8/13

Trversing n NFA Finite Automt I p.8/13

NFA DFA: Suset Construction Simulte in prllel ll possile moves the utomton cn mke The sttes of the resulting DFA will represent sets of sttes of the NFA, i.e., elements of P(Q) We use two opertions on sttes/stte-sets of the NFA -closure(t) move(t, ) Set of sttes rechle from ny stte s in T on on -trnsitions Set of sttes to which there is trnsition from one stte in T on input symol The finl sttes of the DFA re those where the corresponding NFA suset contins finl stte Finite Automt I p.9/13

Algorithm: Suset Construction proc SusetConstruction(s 0 ) DFASttes = -closure({s 0 }) while there is n unmrked stte T in DFASttes do mrk T for ech input symol do U := -closure(move(t, )) DFADelt[T, ] := U if U DFASttes then dd U s unmrked stte to DFASttes proc -closure(t) -closure := T; to check := T while to check not empty do get some stte t from to check for ech stte u with edge leled from t to u if u -closure then dd u to -closure nd to check Finite Automt I p.10/13

Exmple: Suset Construction Finite Automt I p.11/13

Exmple: Suset Construction 0,1, 2,4,7 Finite Automt I p.11/13

Exmple: Suset Construction 0,1, 2,4,7 1,2,3 4,6,7,8 Finite Automt I p.11/13

Exmple: Suset Construction 0,1, 2,4,7 1,2,3 4,6,7,8 1,2,4 5,6,7 Finite Automt I p.11/13

Exmple: Suset Construction 0,1, 2,4,7 1,2,3 4,6,7,8 1,2,4 5,6,7 Finite Automt I p.11/13

Exmple: Suset Construction 0,1, 2,4,7 1,2,3 4,6,7,8 1,2,4 5,6,7 Finite Automt I p.11/13

0,1, 2,4,7 1,2,3 4,6,7,8 Exmple: Suset Construction 1,2,4 5,6,7 Finite Automt I p.11/13

0,1, 2,4,7 1,2,3 4,6,7,8 Exmple: Suset Construction 1,2,4 5,6,7 1,2,4 5,6,7,9 Finite Automt I p.11/13

0,1, 2,4,7 1,2,3 4,6,7,8 Exmple: Suset Construction 1,2,4 5,6,7 1,2,4 5,6,7,9 Finite Automt I p.11/13

Time/Spce Considertions DFA trversl is liner to the length of input string x NFA needs O(n) spce (sttes+trnsitions), where n is the length of the regulr expression NFA trversl my need time n x, so why use NFAs? Finite Automt I p.12/13

Time/Spce Considertions DFA trversl is liner to the length of input string x NFA needs O(n) spce (sttes+trnsitions), where n is the length of the regulr expression NFA trversl my need time n x, so why use NFAs? There re DFA tht hve t lest 2 n sttes! Finite Automt I p.12/13

Time/Spce Considertions DFA trversl is liner to the length of input string x NFA needs O(n) spce (sttes+trnsitions), where n is the length of the regulr expression NFA trversl my need time n x, so why use NFAs? There re DFA tht hve t lest 2 n sttes! Solution 1: Lzy construction of the DFA: construct DFA sttes on the fly up to certin mount nd cche them Finite Automt I p.12/13

Time/Spce Considertions DFA trversl is liner to the length of input string x NFA needs O(n) spce (sttes+trnsitions), where n is the length of the regulr expression NFA trversl my need time n x, so why use NFAs? There re DFA tht hve t lest 2 n sttes! Solution 1: Lzy construction of the DFA: construct DFA sttes on the fly up to certin mount nd cche them Solution 2: Try to minimize the DFA: There is unique (modulo stte nmes) miniml utomton for regulr lnguge! Finite Automt I p.12/13

Minimiztion Algorithm y Hopcroft proc Minimize() B 1 = F; B 2 = Q F E = {B 1,B 2 } k = 3 for Σ do (i) = {s Q s B i t : δ(t,) = s} L = the smller of the (i) while L do tke some i L nd delete it for j < k s.th. t B j Finite Automt I p.13/13