Presentation is loading. Please wait.

Presentation is loading. Please wait.

L ECTURE 3 Chapter 4 Regular Expressions. I MPORTANT T ERMS Regular Expressions Regular Languages Finite Representations.

Similar presentations


Presentation on theme: "L ECTURE 3 Chapter 4 Regular Expressions. I MPORTANT T ERMS Regular Expressions Regular Languages Finite Representations."— Presentation transcript:

1 L ECTURE 3 Chapter 4 Regular Expressions

2 I MPORTANT T ERMS Regular Expressions Regular Languages Finite Representations

3 R ECURSIVE D EFINITION OF R EGULAR EXPRESSIONS Rule 1: Every letter of ∑ can be made into a regular expression by writing it in boldface; ^ is a regular expression. Rule 2 : If r1, and r2 are regular expressions, then so are: (r l ) r 1 r 2 r 1 + r 2 r l * Rule 3 : Nothing else is a regular expression.

4 I MPORTANT DEFINITIONS S + T = {w : w € S or w € T} (Union) ST = {w = w 1 w 2 : w 1 € S,w 2 € T} (Concatenation or Product) S* = S 0 + S 1 + S 2 + · · · (Kleene’s Closure) S + = S 1 + S 2 + · · · (Positive Closure)

5 E XAMPLE Suppose that we wished to describe the language L over the alphabet ∑ = {a,b} where L = {a ab abb abbb abbbb... } R.E= ab*

6 (ab)* = ^ or ab or abab or ababab... XX* = X +

7 E XAMPLE ab*a language (ab*a) = {aa aba abba abbba abbbba....}

8 E XAMPLE The language of the expression a*b* contains all the strings of a's and b's in which all the a's (if any) come before all the b's (if any). language (a*b*) = {^ a b aa ab bb aaa aab abb bbb aaaa... } Notice that ba and aba are not in this language. Notice also that there need not be the same number of a's and b's. Here we should again be very careful to observe that a*b* ≠ (ab)*

9 E XAMPLE The following expressions both define the language L2 = {x odd } x(xx)* or (xx)*x but the expression x*xx* does not since it includes the word (xx) x (x).

10 A NOTHER USE PLUS (+) SIGN By the expression x + y where x and y are strings of characters from an alphabet, we mean "either x or y".

11 EXAMPLE Consider the language T defined over the alphabet ∑ {a, b, c} T = {a c ab cb abb cbb abbb cbbb abbbb cbbbb... } All the words in T begin with an a or a c and then are followed by some number of b's. Symbolically, we may write this as T = language ((a + c)b*) = language (either a or c then some b's)

12 EXAMPLE Now let us consider a finite language L that contains all the strings of a's and b's of length exactly three. L = {aaa aab aba abb baa bab bba bbb} The first letter of each word in L is either an a or a b. The second letter of each word in L is either an a or a b. The third letter of each word in L is either an a or a b. So we may write L = language ((a + b)(a + b)(a + b)) or for short, L = language ((a + b) 3 )

13 E XAMPLE CONT … If we want to define the set of all seven letter strings of a's and b's, we could write (a + b) 7. In general, if we want to refer to the set of all possible strings of a's and b's of any length whatsoever we could write, (a + b)* This is the set of all possible strings of letters from the alphabet ∑ = {a, b} (a+b)*= {^ a b ab ba aa bb aba abb…}


Download ppt "L ECTURE 3 Chapter 4 Regular Expressions. I MPORTANT T ERMS Regular Expressions Regular Languages Finite Representations."

Similar presentations


Ads by Google