Vous êtes sur la page 1sur 8

The Pumping Lemma:

Given a infinite regular language

More Applications

there exists an integer

of

for any string

the Pumping Lemma

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

Theorem: The language

L = {ww R : w *}

= {a , b}

is not regular

Regular languages

Proof:

Use the Pumping Lemma

L = {ww R : w *}

L = {ww R : w *}
Let

Assume for contradiction


that L is a regular language

m be the integer in the Pumping Lemma

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

From the Pumping Lemma


it must be that length | x

x y z = a mb mb m a m

y | m, | y | 1

y = ak , k 1

From the Pumping Lemma:

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

Our assumption that L


is a regular language is not true

L = {a nbl c n +l : n, l 0}
Regular languages

Conclusion: L

is not a regular language

11

12

2
PDF created with pdfFactory Pro trial version www.pdffactory.com

L = {a n bl c n +l : n, l 0}

Theorem: The language

L = {a n bl c n +l : n, l 0}

Assume for contradiction


that L is a regular language

is not regular

Proof:

Use the Pumping Lemma

Since L is infinite
we can apply the Pumping Lemma
13

L = {a n bl c n +l : n, l 0}
Let

Write

m be the integer in the Pumping Lemma

Pick a string

w such that: w L
length

14

a mb m c 2 m = x y z

From the Pumping Lemma


it must be that length | x

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

From the Pumping Lemma:


From the Pumping Lemma:

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

Our assumption that L


is a regular language is not true

Therefore:

L = {a n bl c n +l : n, l 0}

a m k b mc 2 m L

Conclusion: L

is not a regular language

CONTRADICTION!!!
19

Non-regular languages

20

Theorem: The language

L = {a n! : n 0}

L = {a n! : n 0}
is not regular

Regular languages

n! = 1 2 ( n 1) n
Proof:

Use the Pumping Lemma

21

22

L = {a n! : n 0}

L = {a n! : n 0}
Let

Assume for contradiction


that L is a regular language

m be the integer in the Pumping Lemma

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!

From the Pumping Lemma


it must be that length | x

y | m, | y | 1

x yi z L

From the Pumping Lemma:

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

From the Pumping Lemma:

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:

There must exist

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

m!+ k < ( m + 1)!


m!+ k p!

for any

CONTRADICTION!!!

p
29

30

5
PDF created with pdfFactory Pro trial version www.pdffactory.com

Therefore:

Our assumption that L


is a regular language is not true

Lex
Conclusion: L

is not a regular language

31

32

Output

Lex: a lexical analyzer


Input

A Lex program recognizes strings

Var = 12 + 9;
if (test > 20)
temp = 0;
else
while (a < 20)
temp++;

For each kind of string found


the lex program takes an action

Lex
program

Identifier: Var
Operand: =
Integer: 12
Operand: +
Integer: 9
Semicolumn: ;
Keyword: if
Parenthesis: (
Identifier: test
....

33

34

In Lex strings are described


with regular expressions

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

Each regular expression


has an associated action (in C code)

38

Default action:

ECHO;

Examples:
Regular expression

Action

\n

linenum++;

[0-9]+

prinf(integer);

[a-zA-Z]+

printf(identifier);

Prints the string identified


to the output

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

printf(Error in line: %d\n,


43
linenum);

44

Internal Structure of Lex

Lex matches the longest input string


Example: Regular Expressions

Input:
Matches:

ifend

if

ifend

if

if
ifend

ifn

Lex
Regular
expressions

NFA

DFA

Minimal
DFA

The final states of the DFA are


associated with actions

nomatch
45

46

8
PDF created with pdfFactory Pro trial version www.pdffactory.com

Vous aimerez peut-être aussi