Presentation is loading. Please wait.

Presentation is loading. Please wait.

Costas Busch - RPI1 More Applications of the Pumping Lemma.

Similar presentations


Presentation on theme: "Costas Busch - RPI1 More Applications of the Pumping Lemma."— Presentation transcript:

1 Costas Busch - RPI1 More Applications of the Pumping Lemma

2 Costas Busch - RPI2 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 Costas Busch - RPI3 Regular languages Non-regular languages

4 Costas Busch - RPI4 Theorem: The language is not regular Proof: Use the Pumping Lemma

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

6 Costas Busch - RPI6 We pick Let be the integer in the Pumping Lemma Pick a string such that: length and

7 Costas Busch - RPI7 Write it must be that length From the Pumping Lemma Thus:

8 Costas Busch - RPI8 From the Pumping Lemma: Thus:

9 Costas Busch - RPI9 From the Pumping Lemma: Thus:

10 Costas Busch - RPI10 BUT: CONTRADICTION!!!

11 Costas Busch - RPI11 Our assumption that is a regular language is not true Conclusion: is not a regular language Therefore:

12 Costas Busch - RPI12 Regular languages Non-regular languages

13 Costas Busch - RPI13 Theorem: The language is not regular Proof: Use the Pumping Lemma

14 Costas Busch - RPI14 Assume for contradiction that is a regular language Since is infinite we can apply the Pumping Lemma

15 Costas Busch - RPI15 We pick Let be the integer in the Pumping Lemma Pick a string such that: length and

16 Costas Busch - RPI16 Write it must be that length From the Pumping Lemma Thus:

17 Costas Busch - RPI17 From the Pumping Lemma: Thus:

18 Costas Busch - RPI18 From the Pumping Lemma: Thus:

19 Costas Busch - RPI19 BUT: CONTRADICTION!!!

20 Costas Busch - RPI20 Our assumption that is a regular language is not true Conclusion: is not a regular language Therefore:

21 Costas Busch - RPI21 Regular languages Non-regular languages

22 Costas Busch - RPI22 Theorem: The language is not regular Proof: Use the Pumping Lemma

23 Costas Busch - RPI23 Assume for contradiction that is a regular language Since is infinite we can apply the Pumping Lemma

24 Costas Busch - RPI24 We pick Let be the integer in the Pumping Lemma Pick a string such that: length

25 Costas Busch - RPI25 Write it must be that length From the Pumping Lemma Thus:

26 Costas Busch - RPI26 From the Pumping Lemma: Thus:

27 Costas Busch - RPI27 From the Pumping Lemma: Thus:

28 Costas Busch - RPI28 Since: There must exist such that:

29 Costas Busch - RPI29 However:for for any

30 Costas Busch - RPI30 BUT: CONTRADICTION!!!

31 Costas Busch - RPI31 Our assumption that is a regular language is not true Conclusion: is not a regular language Therefore:

32 Costas Busch - RPI32 Lex

33 Costas Busch - RPI33 Lex: a lexical analyzer A Lex program recognizes strings For each kind of string found the lex program takes an action

34 Costas Busch - RPI34 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.... Input Output

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

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

37 Costas Busch - RPI37 integers [0-9]+(0|1|2|3|4|5|6|7|8|9)+

38 Costas Busch - RPI38 (a|b|..|z|A|B|...|Z)+ [a-zA-Z]+ identifiers

39 Costas Busch - RPI39 Each regular expression has an associated action (in C code) Examples: \n Regular expressionAction linenum++; [a-zA-Z]+ printf(“identifier”); [0-9]+ prinf(“integer”);

40 Costas Busch - RPI40 Default action: ECHO; Prints the string identified to the output

41 Costas Busch - RPI41 A small lex program % [a-zA-Z]+printf(“Identifier\n”); [0-9]+printf(“Integer\n”); [ \t\n] ; /*skip spaces*/

42 Costas Busch - RPI42 1234 test var 566 78 9800 Input Output Integer Identifier Integer

43 Costas Busch - RPI43 % [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++;

44 Costas Busch - RPI44 1234 test var 566 78 9800 + temp Input Output Integer Identifier Integer Error in line: 3 Identifier

45 Costas Busch - RPI45 Lex matches the longest input string “if” “ifend” Regular Expressions Input: ifend if Matches: “ifend” “if” Example:

46 Costas Busch - RPI46 Internal Structure of Lex Lex Regular expressions NFADFA Minimal DFA The final states of the DFA are associated with actions


Download ppt "Costas Busch - RPI1 More Applications of the Pumping Lemma."

Similar presentations


Ads by Google