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 Regular languages 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 pick Let be the integer in the Pumping Lemma Pick a string such that: length
7 Write it must be that length From the Pumping Lemma
8 From the Pumping Lemma: Thus: We have:
9 Therefore: BUT: CONTRADICTION!!!
10 Our assumption that is a regular language is not true Conclusion: is not a regular language Therefore:
11 Regular languages Non-regular languages
12 Theorem: The language is not regular Proof: Use the Pumping Lemma
13 Assume for contradiction that is a regular language Since is infinite we can apply the Pumping Lemma
14 pick Let be the integer in the Pumping Lemma Pick a string such that: length
15 Write it must be that length From the Pumping Lemma
16 From the Pumping Lemma: Thus: We have:
17 Therefore: BUT: CONTRADICTION!!!
18 Our assumption that is a regular language is not true Conclusion: is not a regular language Therefore:
19 Regular languages Non-regular languages
20 Theorem: The language is not regular Proof: Use the Pumping Lemma
21 Assume for contradiction that is a regular language Since is infinite we can apply the Pumping Lemma
22 pick Let be the integer in the Pumping Lemma Pick a string such that: length
23 Write it must be that length From the Pumping Lemma
24 From the Pumping Lemma: Thus: We have:
25 Therefore: And since: There is :
26 However:for for any
27 Therefore: BUT: CONTRADICTION!!! and
28 Our assumption that is a regular language is not true Conclusion: is not a regular language Therefore:
29 Lex
30 Lex: a lexical analyzer A Lex program recognizes strings For each kind of string found the lex program takes an action
31 Var = ; 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.... Input Output
32 In Lex strings are described with regular expressions “if” “then” “+” “-” “=“ /* operators */ /* keywords */ Lex program Regular expressions
33 (0|1|2|3|4|5|6|7|8|9)+ /* integers */ /* identifiers */ Regular expressions (a|b|..|z|A|B|...|Z)+ Lex program
34 integers [0-9]+(0|1|2|3|4|5|6|7|8|9)+
35 (a|b|..|z|A|B|...|Z)+ [a-zA-Z]+ identifiers
36 Each regular expression has an associated action (in C code) Examples: \n Regular expressionAction linenum++; [a-zA-Z]+ printf(“identifier”); [0-9]+ prinf(“integer”);
37 Default action: ECHO; Prints the string identified to the output
38 A small program % [a-zA-Z]+printf(“Identifier\n”); [0-9]+printf(“Integer\n”); [ \t\n] ; /*skip spaces*/
test var Input Output Integer Identifier Integer
40 % [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; %} \nlinenum++;
test var temp Input Output Integer Identifier Integer Error in line: 3 Identifier
42 Lex matches the longest input string “if” “ifend” Regular Expressions Input: ifend if ifn Matches: “ifend” “if” nomatch Example:
43 Internal Structure of Lex Lex Regular expressions NFADFA Minimal DFA The final states of the DFA are associated with actions