Languages and Regular expressions
Lecture 2
1
Languages and Regular expressions Lecture 2 1 Strings, Sets of - - PowerPoint PPT Presentation
Languages and Regular expressions Lecture 2 1 Strings, Sets of Strings, Sets of Sets of Strings We defined strings in the last lecture, and showed some properties. What about sets of strings? CS 374 2 n , *, and +
1
CS 374
2
CS 374
3
CS 374
4
CS 374
5
6
CS 374
arbitrary subset of Σ*. Convention: Italic Upper case letters denote languages.
– the empty set Ø – the set {ε}, – the set {0,1}* of all boolean finite length strings. – the set of all strings in {0,1}* with an odd number
– The set of all python programs that print “Hello World!”
language has countably many strings)
7
1 ε 2 3 1 1 4 00 5 01 1 6 10 1 7 11 8 000 9 001 1 10 010 1 11 011 12 100 1 13 101 14 110 15 111 1 16 1000 1 17 1001 18 1010 19 1011 1 20 1100
CS 374
8
CS 374
9
CS 374
10
CS 374
11
CS 374
12
CS 374
13
14
CS 374
15
CS 374
16
CS 374
17
18
CS 374
19
CS 374
20
Atomic expressions (Base cases)
Inductively defined expressions
alt notation (r1|r2) or (r1∪r2)
CS 374
21
CS 374
– All binary strings
– All binary strings of even length
– All binary strings containing the substring 001
– All binary strings with #1s ≡ 0 mod 3
– All binary strings without two consecutive 0s
22
CS 374
23
CS 374
24
CS 374
25
CS 374
visualization of the recursive nature of regular expressions.
– a leaf node labeled Ø – a leaf node labeled with a string – a node labeled + with two children, each of which is the root of a regular expression tree – a node labeled ⋅ with two children, each of which is the root of a regular expression tree – a node labeled * with one child, which is the root of a regular expression tree
26
CS 374
27
28
CS 374
29