Title: More Applications of the Pumping Lemma
1More Applications ofthe Pumping Lemma
2The Pumping Lemma
- Given a infinite regular language
- for any string with length
3Non-regular languages
Regular languages
4Theorem
The language
is not regular
Proof
Use the Pumping Lemma
5Assume for contradiction that is a regular
language
Since is infinite we can apply the Pumping
Lemma
6Let be the integer in the Pumping Lemma
Pick a string such that
length
pick
7Write
From the Pumping Lemma
it must be that length
8We have
From the Pumping Lemma
Thus
9Therefore
BUT
CONTRADICTION!!!
10Our assumption that is a regular language is not
true
Therefore
Conclusion
is not a regular language
11Non-regular languages
Regular languages
12Theorem
The language
is not regular
Proof
Use the Pumping Lemma
13Assume for contradiction that is a regular
language
Since is infinite we can apply the Pumping
Lemma
14Let be the integer in the Pumping Lemma
Pick a string such that
length
pick
15Write
From the Pumping Lemma
it must be that length
16We have
From the Pumping Lemma
Thus
17Therefore
BUT
CONTRADICTION!!!
18Our assumption that is a regular language is not
true
Therefore
Conclusion
is not a regular language
19Non-regular languages
Regular languages
20Theorem
The language
is not regular
Proof
Use the Pumping Lemma
21Assume for contradiction that is a regular
language
Since is infinite we can apply the Pumping
Lemma
22Let be the integer in the Pumping Lemma
Pick a string such that
length
pick
23Write
From the Pumping Lemma
it must be that length
24We have
From the Pumping Lemma
Thus
25Therefore
And since
There is
26However
for
for any
27Therefore
and
BUT
CONTRADICTION!!!
28Our assumption that is a regular language is not
true
Therefore
Conclusion
is not a regular language
29Lex
30Lex a lexical analyzer
- A Lex program recognizes strings
- For each kind of string found
- the lex program takes an action
31Output
Identifier Var Operand Integer 12 Operand
Integer 9 Semicolumn Keyword
if Parenthesis ( Identifier test ....
Input
Var 12 9 if (test gt 20) temp 0 else
while (a lt 20) temp
Lex program
32In Lex strings are described with regular
expressions
Lex program
Regular expressions
-
/ operators /
if then
/ keywords /
33Lex program
Regular expressions
(0123456789)
/ integers /
(ab..zAB...Z)
/ identifiers /
34integers
0-9
(0123456789)
35identifiers
(ab..zAB...Z)
a-zA-Z
36Each regular expression has an associated action
(in C code)
Examples
Regular expression
Action
linenum
\n
prinf(integer)
0-9
a-zA-Z
printf(identifier)
37Default action ECHO
Prints the string identified to the output
38A small program
\t\n /skip
spaces/
0-9
printf(Integer\n)
a-zA-Z
printf(Identifier\n)
39Output
Input
Integer Identifier Identifier Integer Integer Inte
ger
1234 test var 566 78 9800
40Another program
int linenum 1
\t /skip spaces/
\n
linenum
prinf(Integer\n)
0-9
printf(Identifier\n)
a-zA-Z
.
printf(Error in line d\n,
linenum)
41Output
Input
Integer Identifier Identifier Integer Integer Inte
ger Error in line 3 Identifier
1234 test var 566 78 9800 temp
42Lex matches the longest input string
if ifend
Regular Expressions
Example
ifend if ifn
Input
Matches ifend if nomatch
43Internal Structure of Lex
Lex
Minimal DFA
Regular expressions
NFA
DFA
The final states of the DFA are associated with
actions