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

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

View Full Document Right Arrow Icon
CS 421 Lecture 6: Regular expressions s Announcements s Lecture outline s Regular expressions s Ocamllex 6/8/2009 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
Overview of Ocamllex s Automatic OCaml lexer generator OCaml definition of a lexing function Specification of tokens via regular expressions Ocamllex
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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”, …}
Background image of page 5

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

View Full DocumentRight Arrow Icon
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 ??
Background image of page 6
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
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online