![Page 1: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/1.jpg)
1
More Applications
of
the Pumping Lemma
![Page 2: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/2.jpg)
2
The Pumping Lemma:
• Given a infinite regular language L
• there exists an integer m
• for any string with length Lw mw ||
• we can write zyxw
• with andmyx || 1|| y
• such that: Lzyx i ...,2,1,0i
![Page 3: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/3.jpg)
3
Regular languages
Non-regular languages *}:{ wwwL R
![Page 4: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/4.jpg)
4
Theorem: The language
is not regular
Proof: Use the Pumping Lemma
*}:{ wwwL R },{ ba
![Page 5: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/5.jpg)
5
*}:{ wwwL R
Assume for contradiction
that is a regular languageL
Since is infinite
we can apply the Pumping Lemma
L
![Page 6: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/6.jpg)
6
mmmm abbaw We pick
Let be the integer in the Pumping Lemma
Pick a string such that: w Lw
mw ||length
m
*}:{ wwwL R
and
![Page 7: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/7.jpg)
7
Write zyxabba mmmm
it must be that length
From the Pumping Lemma
ababbabaaaaxyz ..................
x y z
m m m m
1||,|| ymyx
1, kay kThus:
![Page 8: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/8.jpg)
8
From the Pumping Lemma: Lzyx i
...,2,1,0i
Thus: Lzyx 2
1, kay kmmmm abbazyx
![Page 9: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/9.jpg)
9
From the Pumping Lemma:
Lababbabaaaaaazxy ∈.....................=2
x y z
km + m m m
1, kay k
y
Lzyx 2
Thus:
mmmm abbazyx
Labba mmmkm
![Page 10: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/10.jpg)
10
Labba mmmkm
Labba mmmkm
*}:{ wwwL RBUT:
CONTRADICTION!!!
1k
![Page 11: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/11.jpg)
11
Our assumption that
is a regular language is not true
L
Conclusion: L is not a regular language
Therefore:
![Page 12: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/12.jpg)
12
Regular languages
Non-regular languages
}0,:{ lncbaL lnln
![Page 13: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/13.jpg)
13
Theorem: The language
is not regular
Proof: Use the Pumping Lemma
}0,:{ lncbaL lnln
![Page 14: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/14.jpg)
14
Assume for contradiction
that is a regular languageL
Since is infinite
we can apply the Pumping Lemma
L
}0,:{ lncbaL lnln
![Page 15: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/15.jpg)
15
mmm cbaw 2We pick
Let be the integer in the Pumping Lemma
Pick a string such that: w Lw
mw ||length
m
}0,:{ lncbaL lnln
and
![Page 16: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/16.jpg)
16
Write zyxcba mmm 2
it must be that length
From the Pumping Lemma
cccbcabaaaaaxyz ..................
x y z
m m m2
1||,|| ymyx
1, kay kThus:
![Page 17: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/17.jpg)
17
From the Pumping Lemma: Lzyx i
...,2,1,0i
Thus:
mmm cbazyx 2
Lxzzyx ∈=0
1, kay k
![Page 18: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/18.jpg)
18
From the Pumping Lemma:
Lcccbcabaaaxz ...............
x z
km m m2
mmm cbazyx 2 1, kay k
Lxz
Thus: Lcba mmkm 2
![Page 19: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/19.jpg)
19
Lcba mmkm 2
Lcba mmkm 2
BUT:
CONTRADICTION!!!
}0,:{ lncbaL lnln
1k
![Page 20: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/20.jpg)
20
Our assumption that
is a regular language is not true
L
Conclusion: L is not a regular language
Therefore:
![Page 21: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/21.jpg)
21
Regular languages
Non-regular languages }0:{ ! naL n
![Page 22: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/22.jpg)
22
Theorem: The language
is not regular
Proof: Use the Pumping Lemma
}0:{ ! naL n
nnn )1(21!
![Page 23: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/23.jpg)
23
Assume for contradiction
that is a regular languageL
Since is infinite
we can apply the Pumping Lemma
L
}0:{ ! naL n
![Page 24: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/24.jpg)
24
!maw We pick
Let be the integer in the Pumping Lemma
Pick a string such that: w Lw
mw ||length
m
}0:{ ! naL n
![Page 25: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/25.jpg)
25
Write zyxam !
it must be that length
From the Pumping Lemma
aaaaaaaaaaaxyz m ...............!
x y z
m mm !
1||,|| ymyx
mkay k 1,Thus:
![Page 26: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/26.jpg)
26
From the Pumping Lemma: Lzyx i
...,2,1,0i
Thus:
!mazyx
Lzyx 2
mkay k 1,
![Page 27: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/27.jpg)
27
From the Pumping Lemma:
Laaaaaaaaaaaazxy ..................2
x y z
km mm !
Thus:
!mazyx mkay k 1,
Lzyx 2
y
La km !
![Page 28: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/28.jpg)
28
La km !
!! pkm
}0:{ ! naL nSince:
mk 1
There must exist such that: p
![Page 29: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/29.jpg)
29
However:
)!1(
)1(!
!!
!!
!
m
mm
mmm
mm
mmkm ! for 1m
)!1(! mkm
!! pkm for any p
![Page 30: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/30.jpg)
30
La km !
La km !
BUT:
CONTRADICTION!!!
}0:{ ! naL n
mk 1
![Page 31: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/31.jpg)
31
Our assumption that
is a regular language is not true
L
Conclusion: L is not a regular language
Therefore:
![Page 32: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/32.jpg)
32
Lex
![Page 33: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/33.jpg)
33
Lex: a lexical analyzer
• A Lex program recognizes strings
• For each kind of string found
the lex program takes an action
![Page 34: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/34.jpg)
34
Var = 12 + 9;
if (test > 20)
temp = 0;
else
while (a < 20)
temp++;
Lexprogram
Identifier: Var
Operand: =
Integer: 12
Operand: +
Integer: 9
Semicolumn: ;
Keyword: if
Parenthesis: (
Identifier: test
....
Input
Output
![Page 35: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/35.jpg)
35
In Lex strings are described
with regular expressions
“if”
“then”
“+”
“-”
“=“
/* operators */
/* keywords */
Lex programRegular expressions
![Page 36: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/36.jpg)
36
(0|1|2|3|4|5|6|7|8|9)+ /* integers */
/* identifiers */
Regular expressions
(a|b|..|z|A|B|...|Z)+
Lex program
![Page 37: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/37.jpg)
37
integers
[0-9]+(0|1|2|3|4|5|6|7|8|9)+
![Page 38: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/38.jpg)
38
(a|b|..|z|A|B|...|Z)+ [a-zA-Z]+
identifiers
![Page 39: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/39.jpg)
39
Each regular expression
has an associated action (in C code)
Examples:
\n
Regular expression Action
linenum++;
[a-zA-Z]+ printf(“identifier”);
[0-9]+ prinf(“integer”);
![Page 40: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/40.jpg)
40
Default action: ECHO;
Prints the string identified
to the output
![Page 41: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/41.jpg)
41
A small program
%%
[a-zA-Z]+ printf(“Identifier\n”);
[0-9]+ printf(“Integer\n”);
[ \t\n] ; /*skip spaces*/
![Page 42: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/42.jpg)
42
1234 test
var 566 78
9800
Input Output
Integer
Identifier
Identifier
Integer
Integer
Integer
![Page 43: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/43.jpg)
43
%%
[a-zA-Z]+ printf(“Identifier\n”);
[0-9]+ prinf(“Integer\n”);
[ \t] ; /*skip spaces*/
. printf(“Error in line: %d\n”,
linenum);
Another program%{
int linenum = 1;
%}
\n linenum++;
![Page 44: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/44.jpg)
44
1234 test
var 566 78
9800 +
temp
Input Output
Integer
Identifier
Identifier
Integer
Integer
Integer
Error in line: 3
Identifier
![Page 45: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/45.jpg)
45
Lex matches the longest input string
“if”
“ifend”
Regular Expressions
Input: ifend if ifn
Matches: “ifend” “if” nomatch
Example:
![Page 46: More Applications of the Pumping Lemmaryan/cse4083/busch/class07.pdf5 L {ww R: w 6 *} Assume for contradiction that is a regular language L Since is infinite we can apply the Pumping](https://reader034.vdocument.in/reader034/viewer/2022042314/5f01eaee7e708231d401acaa/html5/thumbnails/46.jpg)
46
Internal Structure of Lex
Lex
Regular
expressionsNFA DFA
Minimal
DFA
The final states of the DFA are
associated with actions