06-Regular-Expressions

# 06-Regular-Expressions - CS 421 Lecture 6 Regular...

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

CS 421 Lecture 6: Regular expressions s Announcements s Lecture outline s Regular expressions s Ocamllex 6/8/2009 1

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

View Full Document
Announcements s MP2 extension and update s New due date 1:00pm Friday, June 12 s Problem 10 has been updated s “Valid” old solutions will get full credit s MP3 has been posted s Due 1:00pm Wed, June 17 s Warning: more work than the first MPs s Collaboration is allowed in two-person teams
Overview of Ocamllex s Automatic OCaml lexer generator OCaml definition of a lexing function Specification of tokens via regular expressions Ocamllex

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

View Full Document
Regular expressions s A regular expression is one of s ε , a.k.a. “” s a ’ for any character s r 1 r 2 , where r 1 and r 2 are regular expr’s s r 1 |r 2 , where r 1 and r 2 are regular expr’s s r*, where r is a regualr expr s Ø s Every regular expr r represents a set of strings, denoted L(r) s Language of r
Regular expression examples s L(‘a’ ’b’ ’c’) = {“abc”} s L((‘a’ | ’b’) ‘c’) = {“ac”, “bc”} s L((‘a’ | ‘b’)* ‘c’) = {“c”, “ac”, “bc”, “aac”, “abc”, …}

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

View Full Document
Regular expression examples s Keywords: s ‘c’ ‘a’ ‘s’ ‘e’ | ‘c’ ‘ ‘l’ ‘a’ ‘s’ ‘s’ | … s Operators s ‘<‘ | ‘<‘ ‘<‘ | ‘<‘ ‘=‘ | … s Identifiers s (‘a’ | ‘b’ | … | ‘z’ | ‘A’ | … | ‘Z’) (‘a’ | ‘b’ | … | ‘z’ | ‘A’ | … | ‘Z’ | ‘0’ | ‘1’ | … | ‘9’)* s Int literals s ??
Abbreviations s “c 1 c 2 … c n => ‘c 1 ’ ‘c 2 ’ … ‘c n s [‘a’ – ‘z’ ‘#’] => ‘a’ | ‘b’ | … | ‘z’ | ‘#’ s [‘a’ ‘w’ ‘#’] => ‘a’ | ‘w’ | ‘#’ s r+ => r(r*) s r? => r | “” s [^ ‘a’ – ‘z’] => all chars except ‘a’ – ‘z’ (complement of ‘a’ – ‘z’) s _ => any single char

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 07/01/2009 for the course CS CS421 taught by Professor Kirillmechitov during the Summer '09 term at University of Illinois, Urbana Champaign.

### Page1 / 31

06-Regular-Expressions - CS 421 Lecture 6 Regular...

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

View Full Document
Ask a homework question - tutors are online