CMSC 330: Organization of Programming Languages

Similar documents
CMSC 330: Organization of Programming Languages. Theory of Regular Expressions Finite Automata

Clarifications from last time. This Lecture. Last Lecture. CMSC 330: Organization of Programming Languages. Finite Automata.

How do regular expressions work? CMSC 330: Organization of Programming Languages

Nondeterministic Finite Automata

Languages. Non deterministic finite automata with ε transitions. First there was the DFA. Finite Automata. Non-Deterministic Finite Automata (NFA)

Deterministic Finite Automata. Non deterministic finite automata. Non-Deterministic Finite Automata (NFA) Non-Deterministic Finite Automata (NFA)

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages. Regular Expressions and Finite Automata

Outline. Nondetermistic Finite Automata. Transition diagrams. A finite automaton is a 5-tuple (Q, Σ,δ,q 0,F)

Chapter Five: Nondeterministic Finite Automata

CS 154, Lecture 2: Finite Automata, Closure Properties Nondeterminism,

CSE 105 Theory of Computation Professor Jeanne Ferrante

September 11, Second Part of Regular Expressions Equivalence with Finite Aut

CSE 311: Foundations of Computing. Lecture 23: Finite State Machine Minimization & NFAs

COM364 Automata Theory Lecture Note 2 - Nondeterminism

UNIT-II. NONDETERMINISTIC FINITE AUTOMATA WITH ε TRANSITIONS: SIGNIFICANCE. Use of ε-transitions. s t a r t. ε r. e g u l a r

HKN CS/ECE 374 Midterm 1 Review. Nathan Bleier and Mahir Morshed

CSE 105 Homework 1 Due: Monday October 9, Instructions. should be on each page of the submission.

CS 154, Lecture 3: DFA NFA, Regular Expressions

Sri vidya college of engineering and technology

Nondeterministic finite automata

Lecture 1: Finite State Automaton

Nondeterministic Finite Automata and Regular Expressions

1. Induction on Strings

CS 154 Formal Languages and Computability Assignment #2 Solutions

Theory of Computation (I) Yijia Chen Fudan University

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Nondeterministic Finite Automata. Nondeterminism Subset Construction

Nondeterminism and Epsilon Transitions

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CS 322 D: Formal languages and automata theory

Automata and Languages

Lecture 4 Nondeterministic Finite Accepters

CSC236 Week 11. Larry Zhang

Inf2A: Converting from NFAs to DFAs and Closure Properties

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Theory Bridge Exam Example Questions

CISC 4090: Theory of Computation Chapter 1 Regular Languages. Section 1.1: Finite Automata. What is a computer? Finite automata

Closure Properties of Regular Languages. Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Deterministic Finite Automaton (DFA)

COMP4141 Theory of Computation

Introduction to the Theory of Computation. Automata 1VO + 1PS. Lecturer: Dr. Ana Sokolova.

Chap. 1.2 NonDeterministic Finite Automata (NFA)

CSE 105 THEORY OF COMPUTATION

Uses of finite automata

60-354, Theory of Computation Fall Asish Mukhopadhyay School of Computer Science University of Windsor

Finite Automata. Dr. Neil T. Dantam. Fall CSCI-561, Colorado School of Mines. Dantam (Mines CSCI-561) Finite Automata Fall / 35

CSE 311 Lecture 25: Relating NFAs, DFAs, and Regular Expressions. Emina Torlak and Kevin Zatloukal

Lecture 4: Nondeterministic Finite Automata

Recitation 2 - Non Deterministic Finite Automata (NFA) and Regular OctoberExpressions

Finite Automata. BİL405 - Automata Theory and Formal Languages 1

T (s, xa) = T (T (s, x), a). The language recognized by M, denoted L(M), is the set of strings accepted by M. That is,

Introduction to the Theory of Computation. Automata 1VO + 1PS. Lecturer: Dr. Ana Sokolova.

Algorithms for NLP

CS 455/555: Finite automata

acs-04: Regular Languages Regular Languages Andreas Karwath & Malte Helmert Informatik Theorie II (A) WS2009/10

PS2 - Comments. University of Virginia - cs3102: Theory of Computation Spring 2010

CS21 Decidability and Tractability

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

Recap DFA,NFA, DTM. Slides by Prof. Debasis Mitra, FIT.

Please give details of your answer. A direct answer without explanation is not counted.

Languages, regular languages, finite automata

Lecture 3: Nondeterministic Finite Automata

Finite Automata Part Two

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) September,

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Theory of Languages and Automata

Computational Models - Lecture 1 1

Lecture 17: Language Recognition

CS375 Midterm Exam Solution Set (Fall 2017)

CS243, Logic and Computation Nondeterministic finite automata

Text Search and Closure Properties

Text Search and Closure Properties

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CSE 105 THEORY OF COMPUTATION

Automata Theory CS F-04 Non-Determinisitic Finite Automata

Classes and conversions

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CISC 4090 Theory of Computation

Computational Models Lecture 2 1

Computational Models #1

Equivalence of Regular Expressions and FSMs

CMPSCI 250: Introduction to Computation. Lecture #22: From λ-nfa s to NFA s to DFA s David Mix Barrington 22 April 2013

Automata Theory. Lecture on Discussion Course of CS120. Runzhe SJTU ACM CLASS

Nondeterministic Finite Automata

Closure under the Regular Operations

FABER Formal Languages, Automata. Lecture 2. Mälardalen University

Finite Automata. Dr. Neil T. Dantam. Fall CSCI-561, Colorado School of Mines. Dantam (Mines CSCI-561) Finite Automata Fall / 43

False. They are the same language.

Finite Automata and Regular Languages

Context-free grammars and languages

Pushdown Automata. Reading: Chapter 6

1. (a) Explain the procedure to convert Context Free Grammar to Push Down Automata.

UNIT-I. Strings, Alphabets, Language and Operations

Computer Sciences Department

ECS 120: Theory of Computation UC Davis Phillip Rogaway February 16, Midterm Exam

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Theory of computation: initial remarks (Chapter 11)

Pushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen

Transcription:

CMSC 330: Organization of Programming Languages Theory of Regular Expressions DFAs and NFAs Reminders Project 1 due Sep. 24 Homework 1 posted Exam 1 on Sep. 25 Exam topics list posted Practice homework (and solutions) posted CMSC 330 2 1

Previous Course Review {s s defined} means the set of string s such that s is chosen or defined as given s A means s is an element of the set A De Morgan s Laws: There exists and for all symbols Etc CMSC 330 3 Review Basic parts of a regular expression? concatenation,, *, ε,, {a} What does a DFA do? Basic parts of a DFA? alphabet, set of states, start state, final states, transition function (, Q, q 0, F, ) CMSC 330 4 2

Example DFA S0 = Haven t seen anything yet OR seen zero or more b s OR Last symbol seen was a b S1 = Last symbol seen was an a S2 = Last two symbols seen were ab S3 = Last three symbols seen were abb Language? (a b)*abb CMSC 330 5 Notes about the DFA definition Can not have more than one transition leaving a state on the same symbol the transition function must be a valid function) Can not have transitions with no or empty labels the transitions must be labeled by alphabet symbols CMSC 330 6 3

Nondeterministic Finite Automata (NFA) An NFA is a 5-tuple (, Q, q 0, F, ) where is an alphabet Qis a nonempty set of states q 0 Q is the start state F Q is the set of final states There may be 0, 1, or many Q x ( { }) x Q specifies the NFA's transitions Transitions on are allowed can optionally take these transitions without consuming any input Can have more than one transition for a given state and symbol An NFA accepts s if there is at least one path from its start to final state on s CMSC 330 7 NFA for (a b)*abb ba Has paths to either S0 or S1 Neither is final, so rejected babaabb Has paths to different states One leads to S3, so accepted CMSC 330 8 4

Another example DFA Language? (ab aba)* CMSC 330 9 NFA for (ab aba)* aba Has paths to states S0, S1 ababa Has paths to S0, S1 Need to use -transition CMSC 330 10 5

Relating R.E.'s to DFAs and NFAs Regular expressions, NFAs, and DFAs accept the same languages! DFA can transform NFA can transform can transform r.e. (we ll discuss this next) CMSC 330 11 Reducing Regular Expressions to NFAs Goal: Given regular expression e, construct NFA: <e> = (, Q, q 0, F, ) Remember r.e. defined recursively from primitive r.e. languages Invariant: F = 1 in our NFAs Recall F = set of final states Base case: a <a> = ({a}, {S0, S1}, S0, {S1}, {(S0, a, S1)} ) CMSC 330 12 6

Reduction (cont d) Base case: < > = (, {S0}, S0, {S0}, ) Base case: < > = (, {S0, S1}, S0, {S1}, ) CMSC 330 13 Reduction (cont d) Induction: AB <A> <B> CMSC 330 14 7

Reduction (cont d) Induction: AB <A> <B> <A> = ( A, Q A, q A, {f A }, A ) <B> = ( B, Q B, q B, {f B }, B ) <AB> = ( A B, Q A Q B, q A, {f B }, A B {(f A,, q B )} ) CMSC 330 15 Practice Draw the NFA for these regular expressions using exactly the reduction method: ab hello Write the formal (5-tuple) NFA for the same regular expressions CMSC 330 16 8

Reduction (cont d) Induction: (A B) CMSC 330 17 Reduction (cont d) Induction: (A B) <A> = ( A, Q A, q A, {f A }, A ) <B> = ( B, Q B, q B, {f B }, B ) <(A B)> = ( A B, Q A Q B {S0,S1}, S0, {S1}, A B {(S0,,q A ), (S0,,q B ), (f A,,S1), (f B,,S1)}) CMSC 330 18 9

Practice Draw the NFA for these regular expressions using exactly the reduction method: ab bc hello hi Write the formal NFA for the same regular expressions CMSC 330 19 Reduction (cont d) Induction: A* CMSC 330 20 10

Reduction (cont d) Induction: A* <A> = ( A, Q A, q A, {f A }, A ) <A*> = ( A, Q A {S0,S1}, S0, {S1}, A {(f A,,S1), (S0,,q A ), (S0,,S1), (S1,,S0)}) CMSC 330 21 Practice Draw the NFA for these regular expressions using exactly the reduction method: (ab bc*)* hello (hi)* Write the formal NFA for the same regular expressions CMSC 330 22 11

Reduction Complexity Given a regular expression A of size n... Size = # of symbols + # of operations How many states does <A> have? 2 added for each, 2 added for each * O(n) That s pretty good! CMSC 330 23 Practice Draw NFAs for the following regular expressions and languages: (0 1)*110* 101* 111 all binary strings ending in 1 (odd numbers) all alphabetic strings which come after hello in alphabetic order (ab*c d*a ab)d CMSC 330 24 12

Handling ε-transitions What if we want to remove all those unneeded ε- transitions? First, some definitions: We say: if it is possible to transition from state p to state q taking only ε-transitions if p, p 1, p 2, p n, q Q (p q) such that CMSC 330 25 ε-closure For any state p, the ε-closure of p is defined as the set of states q such that {q } CMSC 330 26 13

Example What s the ε-closure of S2 in this NFA? {S2, S0} CMSC 330 27 Example Find the ε-closure for each of the states in this NFA: CMSC 330 28 14

Example Make the NFA for the regular expression (0 1*)111(0* 1) Find the epsilon closure for each of the states of your NFA CMSC 330 29 15