©2004 brooks/cole figures for chapter 2 scanning click the mouse to move to the next page. use the...

61
©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book includes: 2.1 The Scanning Process 2.2 Regular Expressions 2.3 Finite Automata 2.4 From Regular Expressions to DFAs 2.5 Implementation of a TINY Scanner 2.6 Use of Lex to Generate a Scanner Automatically Exercises Programming Exercises Notes and References

Upload: regina-lyons

Post on 18-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

FIGURES FOR CHAPTER 2

SCANNING

Click the mouse to move to the next page.Use the ESC key to exit this chapter.

This chapter in the book includes:2.1 The Scanning Process2.2 Regular Expressions2.3 Finite Automata2.4 From Regular Expressions to DFAs2.5 Implementation of a TINY Scanner2.6 Use of Lex to Generate a Scanner Automatically

ExercisesProgramming ExercisesNotes and References

Page 2: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.1 The Scanning Process, page 34 (1)

Page 3: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.1 The Scanning Process, page 34 (2)

Page 4: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

Figure 2.1: A finite automaton for identifiers

Page 5: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.3 Finite Automata, page 49 (1)

Page 6: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.3 Finite Automata, page 49 (2)

Page 7: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

Figure 2.2: A finite automaton for identifiers with error transitions

Page 8: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.3 Finite Automata, Example 2.6

Page 9: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.3 Finite Automata, Example 2.7

Page 10: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.3 Finite Automata, Example 2.8 (1)

Page 11: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.3 Finite Automata, Example 2.8 (2)

Page 12: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.3 Finite Automata, Example 2.8 (3)

Page 13: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

Figure 2.3: A finite automaton forfloating-point numbers

Page 14: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.3 Finite Automata, Example 2.9

Page 15: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

Figure 2.4: A finite automaton for C-style comments

Page 16: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

Figure 2.5: Finite automaton for an identifier with delimiter and return value

Page 17: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.3 Finite Automata, page 54

Page 18: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.3 Finite Automata, page 55 (1)

Page 19: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.3 Finite Automata, page 55 (2)

Page 20: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.3 Finite Automata, page 55 (3)

Page 21: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.3 Finite Automata, page 56 (1)

Page 22: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.3 Finite Automata, page 56 (2)

Page 23: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.3 Finite Automata, page 56 (3)

Page 24: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.3 Finite Automata, page 57 (1)

Page 25: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.3 Finite Automata, page 57 (2)

Page 26: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.3 Finite Automata, Example 2.10 (1)

Page 27: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.3 Finite Automata, Example 2.10 (2)

Page 28: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.3 Finite Automata, Example 2.11 (1)

Page 29: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.3 Finite Automata, Example 2.11 (2)

Page 30: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.3 Finite Automata, page 59

Page 31: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs, page 64 (1)

Page 32: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs, page 64 (2)

Page 33: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs, page 65 (1)

Page 34: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs, page 65 (2)

Page 35: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs, page 65 (3)

Page 36: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs, page 66 (1)

Page 37: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs, page 66 (2)

Page 38: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs, page 66 (3)

Page 39: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs, Example 2.12 (1)

Page 40: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs, Example 2.12 (2)

Page 41: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

Figure 2.8: NFA for the regular expression ab|a using Thompson’s construction

Page 42: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs, Example 2.13 (1)

Page 43: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs, Example 2.13 (2)

Page 44: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs, Example 2.14

Page 45: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

Figure 2.9: NFA for the regular expression letter(letter|digit) * using Thompson’s

construction

Page 46: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs, Example 2.14

Page 47: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs, Example 2.15

Page 48: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs, Example 2.16 (1)

Page 49: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs, Example 2.16 (2)

Page 50: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs, Example 2.17 (1)

Page 51: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs, Example 2.17 (2)

Page 52: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs, page 73 (1)

Page 53: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs, page 73 (2)

Page 54: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs, Example 2.18

Page 55: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs,

Example 2.19 (1)

Page 56: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.4 From Regular Expressions to DFAs, Example 2.19 (2)

Page 57: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.5 Implementation of a TINY Scanner,

page 76 (1)

Page 58: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

2.5 Implementation of a TINY Scanner, page 76 (2)

Page 59: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

Figure 2.10: DFA of the TINY scanner

Page 60: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

Chapter 2, Exercise 2.16 (a)

Page 61: ©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book

©2004 Brooks/Cole

Chapter 2, Exercise 2.16 (b)