Académique Documents
Professionnel Documents
Culture Documents
More Applications
of
such that:
L = {ww R : w *}
with length
| w| m
| x y | m and | y | 1
Non-regular languages
w=x y z
we can write
with
w L
i = 0, 1, 2, ...
x yi z L
L = {ww R : w *}
= {a , b}
is not regular
Regular languages
Proof:
L = {ww R : w *}
L = {ww R : w *}
Let
Pick a string
w such that: w L
length
Since L is infinite
we can apply the Pumping Lemma
We pick
5
and
| w| m
w = a mb mb m a m
6
1
PDF created with pdfFactory Pro trial version www.pdffactory.com
Write
a mb mb m a m = x y z
x y z = a mb mb m a m
y | m, | y | 1
y = ak , k 1
m m m
i = 0, 1, 2, ...
xyz = a...aa...a...ab...bb...ba...a
x
Thus:
y = ak , k 1
x y z = a mb mb m a m
From the Pumping Lemma:
m + k
x yi z L
Thus:
x y2 z L
y = ak , k 1
a m+ k b mb m a m L
k 1
x y2 z L
BUT:
m m m
L = {ww R : w *}
xy 2 z = a...aa...aa...a...ab...bb...ba...a L
x
Thus:
Therefore:
a m+ k b mb m a m L
a m+ k b mb m a m L
CONTRADICTION!!!
9
10
Non-regular languages
L = {a nbl c n +l : n, l 0}
Regular languages
Conclusion: L
11
12
2
PDF created with pdfFactory Pro trial version www.pdffactory.com
L = {a n bl c n +l : n, l 0}
L = {a n bl c n +l : n, l 0}
is not regular
Proof:
Since L is infinite
we can apply the Pumping Lemma
13
L = {a n bl c n +l : n, l 0}
Let
Write
Pick a string
w such that: w L
length
14
a mb m c 2 m = x y z
and
| w| m
w=a b c
y = ak , k 1
Thus:
y = ak , k 1
16
x y z = a mb m c 2 m
y = ak , k 1
xz L
mk
x yi z L
2m
xz = a...aa...ab...bc...cc...c L
i = 0, 1, 2, ...
x
Thus:
2m
m m 2m
15
x y z = a mb m c 2 m
xyz = a...aa...aa...ab...bc...cc...c
x
We pick
y | m, | y | 1
x y 0 z = xz L
Thus:
17
z
a m k b m c 2 m L
18
3
PDF created with pdfFactory Pro trial version www.pdffactory.com
a m k b m c 2 m L
BUT:
k 1
Therefore:
L = {a n bl c n +l : n, l 0}
a m k b mc 2 m L
Conclusion: L
CONTRADICTION!!!
19
Non-regular languages
20
L = {a n! : n 0}
L = {a n! : n 0}
is not regular
Regular languages
n! = 1 2 ( n 1) n
Proof:
21
22
L = {a n! : n 0}
L = {a n! : n 0}
Let
Pick a string
w such that: w L
length
Since L is infinite
we can apply the Pumping Lemma
We pick
23
| w| m
w = a m!
24
4
PDF created with pdfFactory Pro trial version www.pdffactory.com
Write
a m! = x y z
x y z = a m!
y | m, | y | 1
x yi z L
m! m
y = ak , 1 k m
i = 0, 1, 2, ...
xyz = a m! = a...aa...aa...aa...aa...a
x
Thus:
Thus:
y = ak , 1 k m
x y z = a m!
25
26
a m!+ k L
y = ak , 1 k m
x y2 z L
m+k
x y2 z L
Since:
1 k m
L = {a n! : n 0}
m! m
xy 2 z = a...aa...aa...aa...aa...aa...a L
x
Thus:
However:
such that:
m!+ k = p!
a m!+ k L
m!+ k m!+ m
m!+ m!
27
for
28
m >1
< m!m + m!
= m!(m + 1)
a m!+ k L
BUT:
1 k m
L = {a n! : n 0}
= (m + 1)!
a m!+ k L
for any
CONTRADICTION!!!
p
29
30
5
PDF created with pdfFactory Pro trial version www.pdffactory.com
Therefore:
Lex
Conclusion: L
31
32
Output
Var = 12 + 9;
if (test > 20)
temp = 0;
else
while (a < 20)
temp++;
Lex
program
Identifier: Var
Operand: =
Integer: 12
Operand: +
Integer: 9
Semicolumn: ;
Keyword: if
Parenthesis: (
Identifier: test
....
33
34
Lex program
Lex program
Regular expressions
+
-
=
/* operators */
if
then
/* keywords */
Regular expressions
(0|1|2|3|4|5|6|7|8|9)+
(a|b|..|z|A|B|...|Z)+
35
/* integers */
/* identifiers */
36
6
PDF created with pdfFactory Pro trial version www.pdffactory.com
integers
(0|1|2|3|4|5|6|7|8|9)+
identifiers
[0-9]+
(a|b|..|z|A|B|...|Z)+
[a-zA-Z]+
37
38
Default action:
ECHO;
Examples:
Regular expression
Action
\n
linenum++;
[0-9]+
prinf(integer);
[a-zA-Z]+
printf(identifier);
39
40
A small program
%%
[ \t\n]
Output
Input
/*skip spaces*/
1234
[0-9]+
printf(Integer\n);
[a-zA-Z]+
printf(Identifier\n);
test
var 566
9800
41
78
Integer
Identifier
Identifier
Integer
Integer
Integer
42
7
PDF created with pdfFactory Pro trial version www.pdffactory.com
Another program
%{
int linenum = 1;
%}
%%
1234
[ \t]
\n
; /*skip spaces*/
linenum++;
[0-9]+
prinf(Integer\n);
[a-zA-Z]+
printf(Identifier\n);
Output
Input
Integer
Identifier
Identifier
Integer
Integer
Integer
Error in line: 3
Identifier
test
var 566
78
9800 +
temp
44
Input:
Matches:
ifend
if
ifend
if
if
ifend
ifn
Lex
Regular
expressions
NFA
DFA
Minimal
DFA
nomatch
45
46
8
PDF created with pdfFactory Pro trial version www.pdffactory.com