0% found this document useful (0 votes)
20 views21 pages

Lecture 3a and 3b

The languages denoted by the given regular expressions are: a. (a*b*)* denotes the set of all strings over the alphabet {a,b}. b. a(a|b)*a denotes the set of strings starting and ending with a. c. (aa|bb)*((ab|ba)(aa|bb)*(ab|ba)(aa|bb)*)* denotes the set of strings containing equal number of as and bs. d. a(ba|a)* denotes the set of strings starting with a and containing equal number of as and bs. e. ab(a|b*c)*bb*a denotes the set of strings starting with ab and ending with a, containing equal or

Uploaded by

maryejiropraise
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views21 pages

Lecture 3a and 3b

The languages denoted by the given regular expressions are: a. (a*b*)* denotes the set of all strings over the alphabet {a,b}. b. a(a|b)*a denotes the set of strings starting and ending with a. c. (aa|bb)*((ab|ba)(aa|bb)*(ab|ba)(aa|bb)*)* denotes the set of strings containing equal number of as and bs. d. a(ba|a)* denotes the set of strings starting with a and containing equal number of as and bs. e. ab(a|b*c)*bb*a denotes the set of strings starting with ab and ending with a, containing equal or

Uploaded by

maryejiropraise
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Lecture # 1

ALPHABETS, STRINGS AND


LANGUAGES
• Alphabet: Finite, nonempty set of symbols
Example:
Example:

• Strings: Finite sequence of symbols from an alphabet


e.g. 0011001

• Empty String: The string with zero occurrences of


symbols from alphabet. The empty string is denoted by
Continue…
• Length of String: Number of positions for
symbols in the string. |w| denotes the length
of string w
Example |0110| = 4; | | = 0
• Powers of an Alphabet: = = the set of strings
of length k with symbols from
Example:
Continue..
• Language: is a specific set of strings over some
fixed alphabet 
Example:
The set of legal English words
The set of strings consisting of n 0's followed by n
1’s
LP = the set of binary numbers whose value is
prime
Concatenation and Exponentiation
• The concatenation of two strings x and y is
denoted by xy
• The exponentiation of a string s is defined by

s0 = 
si = si-1s for i > 0

note that s = s = s
Language Operations
• Union
L  M = {s  s  L or s  M}
• Concatenation
LM = {xy  x  L and y  M}
• Exponentiation
L0 = {}; Li = Li-1L
• Kleene closure
L* = i=0,…, Li
• Positive closure
L+ = i=1,…, Li
Continue..
• The set of all strings over is denoted
Regular Expressions
• Basic symbols:
–  is a regular expression denoting language {}
– a   is a regular expression denoting language {a}
• If r and s are regular expressions denoting languages
L(r) and M(s) respectively, then
– rs is a regular expression denoting L(r)  M(s)
– rs is a regular expression denoting L(r)M(s)
– r* is a regular expression denoting L(r)*
– (r) is a regular expression denoting L(r)
• A language defined by a regular expression is called a
Regular set or a Regular Language
8
Regular Definitions
• Regular definitions introduce a naming convention:
d1  r 1
d2  r 2

dn  r n
where each ri is a regular expression over
  {d1, d2, …, di-1 }

9
• Example:

letter  AB…Zab…z
digit  01…9
id  letter ( letterdigit )*

• The following shorthands are often used:

r+ = rr*
r? = r
[a-z] = abc…z

• Examples:
digit  [0-9]
num  digit+ (. digit+)? ( E (+-)? digit+ )?
REGULAR EXPRESSION

• Regular expressions have the capability to express finite languages by


defining a pattern for finite strings of symbols. The grammar defined by
regular expressions is known as regular grammar.
• The language defined by regular grammar is known as regular language.
Regular expression is an important notation for specifying patterns. Each
pattern matches a set of strings, so regular expressions serve as names for a
set of strings. Programming language tokens can be described by regular
languages. The specification of regular expressions is an example of a
recursive definition. Regular languages are easy to understand and have
efficient implementation.
• There are a number of algebraic laws that are obeyed by regular
expressions, which can be used to manipulate regular expressions into
equivalent forms.
Operations on Languages

The various operations on languages are:
• Union of two languages L and M is written as
L U M = {s | s is in L or s is in M}
• Concatenation of two languages L and M is written as
LM = {st | s is in L and t is in M}
• The Kleene Closure of a language L is written as
L* = Zero or more occurrence of language L.
• Examples

L = {00,11} M = {1,01,11}
L ∪ M = {00,11,1,01}
L.M = {001,0001,0011,111,1101,1111}
L0 = {} L1= L ={00,11} L2={0000,0011,1100,1111}
L*={, 00, 11, 0000, 0011, 1100, 1111, 000000, 000011, ...}
Notations
If r and s are regular expressions denoting the languages Lr and
Ls, then
• Union : r|s is a regular expression denoting Lr U Ls
• Concatenation : rs is a regular expression denoting LrLs
• Kleene closure : r* is a regular expression denoting L(r)*
• r is a regular expression denoting Lr
Precedence and Associativity

• *, concatenation . , and | pipesign are left associative


• * has the highest precedence
• Concatenation . has the second highest precedence.
• | pipesign has the lowest precedence of all.
Representing valid tokens of a language in regular expression

If x is a regular expression, then:


• x* means zero or more occurrence of x.
i.e., it can generate { e, x, xx, xxx, xxxx, … }
• x+ means one or more occurrence of x.
i.e., it can generate { x, xx, xxx, xxxx … } or x.x*
• x? means at most one occurrence of x
i.e., it can generate either {x} or {e}.

[a-z] is all lower-case alphabets of English language.


[A-Z] is all upper-case alphabets of English language.
[0-9] is all natural digits used in mathematics.
Regular Expressions - Examples
Regular Expressions - Examples
Regular Expressions
for Given Regular Languages -- Examples
Examples
Let ∑= {a,b}. Write regular expressions for the languages over ∑ that contain:
(i) All strings beginning with ab. ---- ab(a|b)*
(ii) All strings that contain exactly two a’s. ---- b*ab*ab*
(iii) All strings in which every a is followed by a b. --- (b|ab)+

Describe the languages denoted by the following regular expressions:


(i) 0(0|1)*0
The language contains binary numbers that starts with a 0 and ends with another 0
(ii) (0|1)*0(0|1)(0|1)
The language contains binary numbers that ends with 000,011,010,
or 001
(iii) 0*10*10*10*
The language contains binary numbers that have exactly 3 digits 1
Examples

Given Alphabet X = {0, 1}. Write regular expressions for the languages over X that
contain the following
(i) (0 + 1)* = the set of all binary strings
(ii) 031*04 = all strings consisting of three 0’s, followed by any number of 1’s,
followed by four 0’s
(iii) 0*1001* = all strings starting with any number of 0’s, followed by 100,
followed by and number of 1’s
EXERCISES

i. What language is denoted by the following regular expressions?


a. (a*b*)*
b. a(a|b)*a
c. (aa|bb)*((ab|ba)(aa|bb)*(ab|ba)(aa|bb)*)*
d. a(ba|a)*
e. ab(a|b*c)*bb*a

You might also like