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

CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330: Organization of Programming Languages

Regular Expressions and

Finite Automata

CMSC 330 1

Page 2: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 2

How do regular expressions work?

What we’ve learned

• What regular expressions are

• What they can express, and cannot

• Programming with them

What’s next: how they work• A great computer science result

Page 3: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

Languages and Machines

Page 4: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 4

A Few Questions About REs

How are REs implemented?

• Implementing a one-off RE is not so hardØ How to do it in general?

Page 5: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 5

A Few Questions About REs

How are REs implemented?

• Implementing a one-off RE is not so hardØ How to do it in general?

What are the basic components of REs?• Can implement some features in terms of others

Ø E.g., we saw that e+ is the same as ee*

Page 6: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 6

A Few Questions About REs

How are REs implemented?

• Implementing a one-off RE is not so hardØ How to do it in general?

What are the basic components of REs?• Can implement some features in terms of others

Ø E.g., we saw that e+ is the same as ee*

What does a regular expression represent?• Just a set of strings

Ø This observation provides insight on how we go about our implementation

Page 7: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 7

Definition: Alphabet

An alphabet is a finite set of symbols

• Usually denoted Σ

Example alphabets:

• Binary:

• Decimal:

• Alphanumeric:

Σ = {0,1}

Σ = {0,1,2,3,4,5,6,7,8,9}

Σ = {0-9,a-z,A-Z}

Page 8: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 8

Definition: String

A string is a finite sequence of symbols from Σ

• ε is the empty string ("" in Ruby)

• |s| is the length of string sØ |Hello| = 5, |ε| = 0

• NoteØ Ø is the empty set (with 0 elements)

Ø Ø ≠ { ε } ≠ ε

Page 9: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 9

Definition: String

A string is a finite sequence of symbols from Σ

• ε is the empty string ("" in Ruby)

• |s| is the length of string sØ |Hello| = 5, |ε| = 0

• NoteØ Ø is the empty set (with 0 elements)

Ø Ø ≠ { ε } ≠ ε

Example strings:• 0101 Î Σ = {0,1} (binary)

• 0101 Î Σ = decimal

• 0101 Î Σ = alphanumeric

Page 10: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 10

Definition: String concatenation

String concatenation is indicated by juxtaposition

s1 = super

s2 = hero

• Sometimes also written s1·s2

s1s2 = superhero

Page 11: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 11

Definition: String concatenation

String concatenation is indicated by juxtaposition

• For any string s, we have sε = εs = s

• You can concatenate strings from different alphabets; then the new alphabet is the union of the originals: Ø If s1 = super Î Σ1 = {s,u,p,e,r} and s2 = hero Î Σ2 = {h,e,r,o},

then s1s2 = superhero Î Σ3 = {e,h,o,p,r,s,u}

Page 12: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 12

Definition: Language

A language L is a set of strings over an alphabet

Example: The set of phone numbers over the alphabet Σ = {0, 1, 2, 3, 4, 5, 6, 7, 9, (, ), -}

Page 13: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 13

Definition: Language

A language L is a set of strings over an alphabet

Example: The set of phone numbers over the alphabet Σ = {0, 1, 2, 3, 4, 5, 6, 7, 9, (, ), -}

• Give an example element of this language

• Are all strings over the alphabet in the language?

• Is there a Ruby regular expression for this language?/\(\d{3,3}\) \d{3,3}-\d{4,4}/

No

(123) 456-7890

Page 14: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 14

Definition: Language

A language L is a set of strings over an alphabet

Example: The set of phone numbers over the alphabet Σ = {0, 1, 2, 3, 4, 5, 6, 7, 9, (, ), -}

• Give an example element of this language

• Are all strings over the alphabet in the language?

• Is there a Ruby regular expression for this language?

Example: The set of all strings over Σ• Often written Σ*

/\(\d{3,3}\) \d{3,3}-\d{4,4}/

No

(123) 456-7890

Page 15: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 15

Definition: Language (cont.)

Example: The set of strings of length 0 over the alphabet Σ = {a, b, c}• L = { s | s ∊ Σ* and |s| = 0} = {ε} ≠ Ø

Page 16: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 16

Definition: Language (cont.)

Example: The set of strings of length 0 over the alphabet Σ = {a, b, c}• L = { s | s ∊ Σ* and |s| = 0} = {ε} ≠ Ø

Example: The set of all valid Ruby programs• Is there a Ruby regular expression for this language?

Page 17: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 17

Definition: Language (cont.)

Example: The set of strings of length 0 over the alphabet Σ = {a, b, c}• L = { s | s ∊ Σ* and |s| = 0} = {ε} ≠ Ø

Example: The set of all valid Ruby programs• Is there a Ruby regular expression for this language?

No. Matching (an arbitrary number of) brackets so thatthey are balanced is impossible using REs { { { … } } }

Page 18: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 18

Definition: Language (cont.)

Example: The set of strings of length 0 over the alphabet Σ = {a, b, c}• L = { s | s ∊ Σ* and |s| = 0} = {ε} ≠ Ø

Example: The set of all valid Ruby programs• Is there a Ruby regular expression for this language?

REs represent languages, but not all of them• The languages represented by regular expressions are called,

appropriately, the regular languages

No. Matching (an arbitrary number of) brackets so thatthey are balanced is impossible using REs { { { … } } }

Page 19: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 19

Definition: Regular Expressions

Given an alphabet Σ, the regular expressionsover Σ are defined inductively as

regular expression denotes language

Ø Ø

ε {ε}

each element σ ∊ Σ {σ}

Constants

Page 20: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 20

Definition: Regular Expressions (cont.)

Let A and B be regular expressions denoting languages LA and LB, respectively

There are no other regular expressions over Σ

regular expression denotes language

AB LALB

(A|B) LA ∪ LB

A* LA*

Operations

Page 21: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 21

Operations on Languages

Let Σ be an alphabet and let L, L1, L2 be languages over Σ

Concatenation L1L2 is defined as• L1L2 = { xy | x ∊ L1 and y ∊ L2}

Page 22: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 22

Operations on Languages

Let Σ be an alphabet and let L, L1, L2 be languages over Σ

Concatenation L1L2 is defined as• L1L2 = { xy | x ∊ L1 and y ∊ L2}

Union is defined as• L1 � L2 = { x | x ∊ L1 or x ∊ L2}

Page 23: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 23

Operations on Languages

Let Σ be an alphabet and let L, L1, L2 be languages over Σ

Concatenation L1L2 is defined as• L1L2 = { xy | x ∊ L1 and y ∊ L2}

Union is defined as• L1 � L2 = { x | x ∊ L1 or x ∊ L2}

Kleene closure is defined as• L* = { x | x = ε or x ∊ L or x ∊ LL or x ∊ LLL or …}

Page 24: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 24

Regular Expressions Denote Languages

By applying operations on constants

• Generates a set of strings (i.e., a language)

• ExamplesØ a → {�a�}

Ø a|b → {�a�} ∪ {�b�} = {�a�, �b�}

Ø a* → {ε} ∪ {�a�} ∪ {�aa�} ∪… = {ε,�a�, “aa�, … }

If s � language generated by a RE r, we say that r accepts, describes, or recognizes string s

Page 25: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 25

Precedence

Order in which operators are appliedØ Kleene closure * > concatenation > union |

Ø ab|c = ( a b ) | c = {�ab�, �c�}

Ø ab* = a ( b* ) = {�a�, �ab�, �abb�…}

Ø a|b* = a | ( b* ) = {�a�, ��, �b�, �bb�, �bbb�…}

• Can change order using parentheses ( )Ø E.g., a(b|c), (ab)*, (a|b)*

Page 26: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 26

Regular Languages

The languages that can be described using regular expressions are the regular languages or regular sets

Page 27: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 27

Regular Languages

The languages that can be described using regular expressions are the regular languages or regular sets

Not all languages are regular• Examples (without proof):

Ø The set of palindromes over Σ

Ø {anbn | n > 0 } (an = sequence of n a�s)

anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
Page 28: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 28

Regular Languages

The languages that can be described using regular expressions are the regular languages or regular sets

Not all languages are regular• Examples (without proof):

Ø The set of palindromes over Σ

Ø {anbn | n > 0 } (an = sequence of n a�s)

Almost all programming languages are not regular

• But aspects of them sometimes are (e.g., identifiers)

• Regular expressions are commonly used in parsing tools

Page 29: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 29

Ruby Regular Expressions

Almost all of the features we�ve seen for Ruby REs can be reduced to this formal definition• /Ruby/ – concatenation of single-character REs

• /(Ruby|Regular)/ – union

• /(Ruby)*/ – Kleene closure

• /(Ruby)+/ – same as (Ruby)(Ruby)*

• /(Ruby)?/ – same as (ε|(Ruby)) (// is ε)

• /[a-z]/ – same as (a|b|c|...|z)

• / [^0-9]/ – same as (a|b|c|...) for a,b,c,... � Σ - {0..9}

• ^, $ – correspond to extra characters in alphabet

Page 30: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 30

Implementing Regular Expressions

We can implement a regular expression by turning it into a finite automaton

• A �machine� for recognizing a regular language

�String�

�String�

�String�

�String�

�String�

�String�

Yes

No

Page 31: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 31

Finite Automata

Σ = { }States:

Start:Final:

Transitions:

anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
Page 32: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 32

Finite Automata

Machine starts in start or initial state

Repeat until the end of the string is reached

• Scan the next symbol s of the string

• Take transition edge labeled with s

String is accepted if automaton is in final state when end of string reached

States

Start state Final state

Transition on 1

Page 33: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 33

Finite Automata: States

Start state

• State with incoming transition from no other state

• Can have only 1 start state

Final states

• States with double circle

• Can have 0 or more final states

• Any state, including the start state, can be final

S1 S2

Page 34: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 34

Finite Automaton: Example 1

0 0 1 0 1 1Accepted?

anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
Page 35: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 35

Finite Automaton: Example 2

0 0 1 0 1 0Accepted?

Page 36: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 36

What Language is This?

Page 37: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 37

What Language is This?

All strings over {0, 1} that end in 1

What is a regular expression for this language?

Page 38: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 38

What Language is This?

All strings over {0, 1} that end in 1

What is a regular expression for this language?(0|1)*1

Page 39: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 39

Finite Automaton: Example 3

(a,b,c notation shorthand for three self loops)

aabcc

accepts?

state at end

string

Page 40: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 40

Finite Automaton: Example 3

(a,b,c notation shorthand for three self loops)

YS2aabcc

accepts?

state at end

string

Page 41: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 41

Finite Automaton: Example 3

(a,b,c notation shorthand for three self loops)

accepts?

state at end

string

accc

Page 42: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 42

Finite Automaton: Example 3

(a,b,c notation shorthand for three self loops)

accepts?

state at end

string

YS2accc

Page 43: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 43

Finite Automaton: Example 3

(a,b,c notation shorthand for three self loops)

accepts?

state at end

string

bbbc

Page 44: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 44

Finite Automaton: Example 3

(a,b,c notation shorthand for three self loops)

accepts?

state at end

string

YS2bbbc

Page 45: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 45

Finite Automaton: Example 3

(a,b,c notation shorthand for three self loops)

accepts?

state at end

string

aacbbb

Page 46: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 46

Finite Automaton: Example 3

(a,b,c notation shorthand for three self loops)

accepts?

state at end

string

NS3aacbbb

Page 47: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 47

Finite Automaton: Example 3

(a,b,c notation shorthand for three self loops)

accepts?

state at end

string

ε

Page 48: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 48

Finite Automaton: Example 3

(a,b,c notation shorthand for three self loops)

accepts?

state at end

string

YS0ε

Page 49: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 49

Finite Automaton: Example 3

(a,b,c notation shorthand for three self loops)

accepts?

state at end

string

acba

Page 50: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 50

Finite Automaton: Example 3

(a,b,c notation shorthand for three self loops)

accepts?

state at end

string

NS3acba

Page 51: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 51

Finite Automaton: Example 3 (cont.)

What language does this FA accept?

Page 52: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 52

Finite Automaton: Example 3 (cont.)

What language does this FA accept?

a*b*c*

Page 53: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 53

Finite Automaton: Example 3 (cont.)

What language does this FA accept?

a*b*c*

S3 is a dead state– a nonfinal state with no transition to another state

Page 54: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 54

Dead State: Shorthand Notation

If a transition is omitted, assume it goes to a dead state that is not shown

is short for

Page 55: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 55

Dead State: Shorthand Notation

If a transition is omitted, assume it goes to a dead state that is not shown

Language?• Strings over {0,1,2,3} with alternating even

and odd digits, beginning with odd digit

is short for

Page 56: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 56

Finite Automaton: Example 4

Page 57: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

CMSC 330 57

Finite Automaton: Example 4

a*b*c* again, so DFAs are not unique

Page 58: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

Finite Automaton: Example 5

Description for each state

• 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�

Page 59: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

Finite Automaton: Example 5

Language?

Page 60: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

Finite Automaton: Example 5

Language?

Ø (a|b)*abb

Page 61: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

Examples

Give a DFA that accepts binary numbers with an odd number of 1’s over {0,1}

CMSC 330 61

anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
Page 62: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

Examples

Construct a DFA to accept a string containing even number of zeroes and any number of ones. Alphabet ={0,1}

CMSC 330 62

anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
Page 63: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

Examples

Construct a DFA to accept all strings containing odd number of zeroes and odd number of ones Alphabet ={0,1}

CMSC 330 63

anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
Page 64: CMSC 330: Organization of Programming LanguagesA Few Questions About REs How are REs implemented? • Implementing a one-off RE is not so hard Ø How to do it in general? What are

Examples

Construct a DFA to accept all strings DO NOT contain odd number of zeroes and odd number of ones Alphabet ={0,1}

CMSC 330 64

anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat
anwar mamat