{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

04-regularExpressions

# 04-regularExpressions - Last Lecture CMSC 330 Organization...

This preview shows pages 1–3. Sign up to view the full content.

1 CMSC 330: Organization of Programming Languages Theory of Regular Expressions CMSC 330 2 Last Lecture Ruby language • Regular expressions • Arrays • Code blocks • Hash • File • Exceptions CMSC 330 3 Introduction That’s it for the basics of Ruby • If you need other material for your project, come to office hours or check out the documentation Next up: How do regular expressions (REs) really work? • Mixture of a very practical tool (string matching with REs) and some nice theory • A great computer science result CMSC 330 4 A Few Questions About REs What does a regular expression represent? • Just a set of strings What are the basic components of REs? • E.g., we saw that e+ is the same as ee* How are REs implemented? • We’ll see how to build a structure to parse REs CMSC 330 5 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} CMSC 330 6 Definition: String A string is a finite sequence of symbols from Σ ε is the empty string ( "" in Ruby) • |s| is the length of string s h |Hello| = 5, | ε | = 0 • Note: Ø is the empty set (with 0 elements); Ø { ε } Example strings: • 0101 Σ = {0,1} (binary) • 0101 Σ = decimal • 0101 Σ = alphanumeric

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 CMSC 330 7 Definition: Concatenation Concatenation is indicated by juxtaposition • If s 1 = super and s 2 = hero , then s 1 s 2 = superhero • Sometimes also written s 1 ·s 2 • 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: h If s 1 = super Σ 1 = {s,u,p,e,r} and s 2 = hero Σ 2 = {h,e,r,o} , then s 1 s 2 = superhero Σ 3 = {e,h,o,p,r,s,u} CMSC 330 8 Definition: Language A language 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?
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 5

04-regularExpressions - Last Lecture CMSC 330 Organization...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online