Download presentation
Presentation is loading. Please wait.
1
More Applications of the Pumping Lemma
2
The Pumping Lemma: Given a infinite regular language
there exists an integer for any string with length we can write with and such that:
3
Non-regular languages
4
Theorem: The language is not regular Proof: Use the Pumping Lemma
5
Assume for contradiction
that is a regular language Since is infinite we can apply the Pumping Lemma
6
Let be the integer in the Pumping Lemma
Pick a string such that: and length We pick
7
Write From the Pumping Lemma it must be that length Thus:
8
From the Pumping Lemma:
Thus:
9
From the Pumping Lemma:
Thus:
10
BUT: CONTRADICTION!!!
11
Conclusion: Therefore: Our assumption that
is a regular language is not true Conclusion: is not a regular language
12
Non-regular languages
13
Theorem: The language is not regular Proof: Use the Pumping Lemma
14
Assume for contradiction
that is a regular language Since is infinite we can apply the Pumping Lemma
15
Let be the integer in the Pumping Lemma
Pick a string such that: and length We pick
16
Write From the Pumping Lemma it must be that length Thus:
17
From the Pumping Lemma:
Thus:
18
From the Pumping Lemma:
Thus:
19
BUT: CONTRADICTION!!!
20
Conclusion: Therefore: Our assumption that
is a regular language is not true Conclusion: is not a regular language
21
Non-regular languages
22
Theorem: The language is not regular Proof: Use the Pumping Lemma
23
Assume for contradiction
that is a regular language Since is infinite we can apply the Pumping Lemma
24
Let be the integer in the Pumping Lemma
Pick a string such that: length We pick
25
Write From the Pumping Lemma it must be that length Thus:
26
From the Pumping Lemma:
Thus:
27
From the Pumping Lemma:
Thus:
28
Since: There must exist such that:
29
However: for for any
30
BUT: CONTRADICTION!!!
31
Conclusion: Therefore: Our assumption that
is a regular language is not true Conclusion: is not a regular language
32
Lex
33
Lex: a lexical analyzer
A Lex program recognizes strings For each kind of string found the lex program takes an action
34
Lex Output Identifier: Var Operand: = Input Integer: 12 Operand: +
Semicolumn: ; Keyword: if Parenthesis: ( Identifier: test .... Input Var = ; if (test > 20) temp = 0; else while (a < 20) temp++; Lex program
35
Lex program In Lex strings are described with regular expressions
“+” “-” “=“ /* operators */ “if” “then” /* keywords */
36
Lex program Regular expressions (0|1|2|3|4|5|6|7|8|9)+ /* integers */
(a|b|..|z|A|B|...|Z)+ /* identifiers */
37
integers (0|1|2|3|4|5|6|7|8|9)+ [0-9]+
38
identifiers (a|b|..|z|A|B|...|Z)+ [a-zA-Z]+
39
Examples: Each regular expression has an associated action (in C code)
linenum++; \n prinf(“integer”); [0-9]+ [a-zA-Z]+ printf(“identifier”);
40
Default action: ECHO; Prints the string identified to the output
41
A small lex program %% [ \t\n] ; /*skip spaces*/ [0-9]+
printf(“Integer\n”); [a-zA-Z]+ printf(“Identifier\n”);
42
Output Input Integer Identifier test var 9800
43
. Another program %{ int linenum = 1; %} %% [ \t] ; /*skip spaces*/ \n
prinf(“Integer\n”); [0-9]+ [a-zA-Z]+ printf(“Identifier\n”); . printf(“Error in line: %d\n”, linenum);
44
Output Input Integer Identifier Error in line: 3 test var temp
45
Lex matches the longest input string
Example: Regular Expressions “if” “ifend” ifend if Input: Matches: “ifend” “if”
46
Lex Internal Structure of Lex Minimal DFA Regular expressions NFA DFA
The final states of the DFA are associated with actions
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.