Download presentation

Presentation is loading. Please wait.

1
1 More Applications of the Pumping Lemma

2
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
3 Regular languages Non-regular languages

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

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

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

7
7 Write it must be that length From the Pumping Lemma

8
8 From the Pumping Lemma: Thus: We have:

9
9 Therefore: BUT: CONTRADICTION!!!

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

11
11 Regular languages Non-regular languages

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

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

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

15
15 Write it must be that length From the Pumping Lemma

16
16 From the Pumping Lemma: Thus: We have:

17
17 Therefore: BUT: CONTRADICTION!!!

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

19
19 Regular languages Non-regular languages

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

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

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

23
23 Write it must be that length From the Pumping Lemma

24
24 From the Pumping Lemma: Thus: We have:

25
25 Therefore: And since: There is :

26
26 However:for for any

27
27 Therefore: BUT: CONTRADICTION!!! and

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

29
29 Lex

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

31
31 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

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

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

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

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

36
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
37 Default action: ECHO; Prints the string identified to the output

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

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

40
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++;

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

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

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

Similar presentations

© 2021 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google