More Applications of the Pumping Lemma 1 The

  • Slides: 43
Download presentation
More Applications of the Pumping Lemma 1

More Applications of the Pumping Lemma 1

The Pumping Lemma: • Given a infinite regular language • there exists an integer

The Pumping Lemma: • Given a infinite regular language • there exists an integer • for any string with length • we can write • with • such that: and 2

Non-regular languages Regular languages 3

Non-regular languages Regular languages 3

Theorem: The language is not regular Proof: Use the Pumping Lemma 4

Theorem: The language is not regular Proof: Use the Pumping Lemma 4

Assume for contradiction that is a regular language Since is infinite we can apply

Assume for contradiction that is a regular language Since is infinite we can apply the Pumping Lemma 5

Let be the integer in the Pumping Lemma Pick a string such that: length

Let be the integer in the Pumping Lemma Pick a string such that: length pick 6

Write From the Pumping Lemma it must be that length 7

Write From the Pumping Lemma it must be that length 7

We have: From the Pumping Lemma: Thus: 8

We have: From the Pumping Lemma: Thus: 8

Therefore: BUT: CONTRADICTION!!! 9

Therefore: BUT: CONTRADICTION!!! 9

Therefore: Our assumption that is a regular language is not true Conclusion: is not

Therefore: Our assumption that is a regular language is not true Conclusion: is not a regular language 10

Non-regular languages Regular languages 11

Non-regular languages Regular languages 11

Theorem: The language is not regular Proof: Use the Pumping Lemma 12

Theorem: The language is not regular Proof: Use the Pumping Lemma 12

Assume for contradiction that is a regular language Since is infinite we can apply

Assume for contradiction that is a regular language Since is infinite we can apply the Pumping Lemma 13

Let be the integer in the Pumping Lemma Pick a string such that: length

Let be the integer in the Pumping Lemma Pick a string such that: length pick 14

Write From the Pumping Lemma it must be that length 15

Write From the Pumping Lemma it must be that length 15

We have: From the Pumping Lemma: Thus: 16

We have: From the Pumping Lemma: Thus: 16

Therefore: BUT: CONTRADICTION!!! 17

Therefore: BUT: CONTRADICTION!!! 17

Therefore: Our assumption that is a regular language is not true Conclusion: is not

Therefore: Our assumption that is a regular language is not true Conclusion: is not a regular language 18

Non-regular languages Regular languages 19

Non-regular languages Regular languages 19

Theorem: The language is not regular Proof: Use the Pumping Lemma 20

Theorem: The language is not regular Proof: Use the Pumping Lemma 20

Assume for contradiction that is a regular language Since is infinite we can apply

Assume for contradiction that is a regular language Since is infinite we can apply the Pumping Lemma 21

Let be the integer in the Pumping Lemma Pick a string such that: length

Let be the integer in the Pumping Lemma Pick a string such that: length pick 22

Write From the Pumping Lemma it must be that length 23

Write From the Pumping Lemma it must be that length 23

We have: From the Pumping Lemma: Thus: 24

We have: From the Pumping Lemma: Thus: 24

Therefore: And since: There is : 25

Therefore: And since: There is : 25

However: for any 26

However: for any 26

Therefore: BUT: and CONTRADICTION!!! 27

Therefore: BUT: and CONTRADICTION!!! 27

Therefore: Our assumption that is a regular language is not true Conclusion: is not

Therefore: Our assumption that is a regular language is not true Conclusion: is not a regular language 28

Lex 29

Lex 29

Lex: a lexical analyzer • A Lex program recognizes strings • For each kind

Lex: a lexical analyzer • A Lex program recognizes strings • For each kind of string found the lex program takes an action 30

Output Input Var = 12 + 9; if (test > 20) temp = 0;

Output Input Var = 12 + 9; 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. . 31

In Lex strings are described with regular expressions Lex program Regular expressions “+” “-”

In Lex strings are described with regular expressions Lex program Regular expressions “+” “-” “=“ /* operators */ “if” “then” /* keywords */ 32

Lex program Regular expressions (0|1|2|3|4|5|6|7|8|9)+ (a|b|. . |z|A|B|. . . |Z)+ /* integers */

Lex program Regular expressions (0|1|2|3|4|5|6|7|8|9)+ (a|b|. . |z|A|B|. . . |Z)+ /* integers */ /* identifiers */ 33

integers (0|1|2|3|4|5|6|7|8|9)+ [0 -9]+ 34

integers (0|1|2|3|4|5|6|7|8|9)+ [0 -9]+ 34

identifiers (a|b|. . |z|A|B|. . . |Z)+ [a-z. A-Z]+ 35

identifiers (a|b|. . |z|A|B|. . . |Z)+ [a-z. A-Z]+ 35

Each regular expression has an associated action (in C code) Examples: Regular expression Action

Each regular expression has an associated action (in C code) Examples: Regular expression Action n linenum++; [0 -9]+ prinf(“integer”); [a-z. A-Z]+ printf(“identifier”); 36

Default action: ECHO; Prints the string identified to the output 37

Default action: ECHO; Prints the string identified to the output 37

A small program %% [ tn] ; /*skip spaces*/ [0 -9]+ printf(“Integern”); [a-z. A-Z]+

A small program %% [ tn] ; /*skip spaces*/ [0 -9]+ printf(“Integern”); [a-z. A-Z]+ printf(“Identifiern”); 38

Output Input 1234 test var 566 9800 78 Integer Identifier Integer 39

Output Input 1234 test var 566 9800 78 Integer Identifier Integer 39

%{ int linenum = 1; %} Another program %% [ t] n ; /*skip

%{ int linenum = 1; %} Another program %% [ t] n ; /*skip spaces*/ linenum++; [0 -9]+ prinf(“Integern”); [a-z. A-Z]+ printf(“Identifiern”); . printf(“Error in line: %dn”, 40 linenum);

Output Input 1234 test var 566 9800 + temp 78 Integer Identifier Integer Error

Output Input 1234 test var 566 9800 + temp 78 Integer Identifier Integer Error in line: 3 Identifier 41

Lex matches the longest input string Example: Regular Expressions Input: Matches: ifend if “ifend”

Lex matches the longest input string Example: Regular Expressions Input: Matches: ifend if “ifend” “if” “ifend” ifn nomatch 42

Internal Structure of Lex Regular expressions NFA DFA Minimal DFA The final states of

Internal Structure of Lex Regular expressions NFA DFA Minimal DFA The final states of the DFA are associated with actions 43