Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the...

68
Lexical Analysis Arial Font Family

Transcript of Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the...

Page 1: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Lexical Analysis

Arial Font Family

Page 2: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.1: Interactions between the lexical analyzer and the parser

Page 3: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.2: Examples of tokens

Page 4: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.3: Using a pair of input buffers

Page 5: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.4: Sentinels at the end of each buffer

Page 6: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.5: Lookahead code with sentinels

Page 7: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.6: Definitions of operations on languages

Page 8: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.7: Algebraic laws for regular expressions

Page 9: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.8: Lex regular expressions

Page 10: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.9: Filename expressions used by the shell command sh

Page 11: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.10: A grammar for branching statements

Page 12: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.11: Patterns for tokens of Example 3.8

Page 13: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.12: Tokens, their patterns, and attribute values

Page 14: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.13: Transition diagram for relop

Page 15: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.14: A transition diagram for id's and keywords

Page 16: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.15: Hypothetical transition diagram for the keyword then

Page 17: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.16: A transition diagram for unsigned numbers

Page 18: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.17: A transition diagram for whitespace

Page 19: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.18: Sketch of implementation of relop transition diagram

Page 20: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.19: Algorithm to compute the failure function for keyword blb2 . . . bn

Page 21: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.20: The KMP algorithm tests whether string ala2 . . a, contains a single keyword bl b2 . . .

bn as a substring in O(m + n) time

Page 22: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.21: Trie for keywords he, she, his, hers

Page 23: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.22: Creating a lexical analyzer with Lex

Page 24: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.23: Lex program for the

tokens of Fig. 3.12

Page 25: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.24: A nondeterministic finite automaton

Page 26: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.25: Transition table for the NFA of Fig. 3.24

Page 27: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.26: NFA accepting aa* 1 bb*

Page 28: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.27: Simulating a DFA

Page 29: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.28: DFA accepting (aJb)*abb

Page 30: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.29: NFA for Exercise 3.6.3

Page 31: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.30: NFA for Exercise 3.6.4

Page 32: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.31: Operations on NFA states

Page 33: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.32: The subset construction

Page 34: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.33: Computing E- closure(T)

Page 35: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.34: NFA N for (alb)*abb

Page 36: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.35: Transition table Dtran for DFA D

Page 37: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.36: Result of applying the subset

construction to Fig. 3.34

Page 38: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.37: Simulating an NFA

Page 39: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.38: Adding a new state s, which is known not to be on newstates

Page 40: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.39: Implementation of step (4) of Fig. 3.37

Page 41: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.40: NFA for the union of two regular expressions

Page 42: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.41: NFA for the concatenation of two regular expressions

Page 43: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.42: NFA for the closure of a regular expression

Page 44: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.43: Parse

tree for (alb)*abb

Page 45: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.44: NFA for r3

Page 46: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.45: NFA for r5

Page 47: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.46: NFA for r

Page 48: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.47: An NFA that has many fewer states than the smallest equivalent DFA

Page 49: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.48: Initial cost and per-string-cost of various methods of recognizing the language of a regular expression

Page 50: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.49: A Lex program is turned into a transition table and actions, which are used

by a finite-automaton simulator

Page 51: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.50: An NFA constructed from a Lex program

Page 52: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.51: NFA's for a, abb, and a*b+

Page 53: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.52: Combined NFA

Page 54: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.53: Sequence of sets of states entered when processing

input aaba

Page 55: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.54: Transition graph for DFA handling the patterns a, abb, and a*b+

Page 56: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.55: NFA recognizing the keyword IF

Page 57: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.56:

Syntax tree for

(aJb)*abb#

Page 58: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.57: NFA constructed by Algorithm 3.23 for (a(b)*abb#

Page 59: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.58: Rules for computing nullable and firstpos

Page 60: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.59:

firstpos and

lastpos for nodes in

the syntax tree for

(alb)*abb#

Page 61: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.60: The function followpos

Page 62: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.61: Directed graph for the function followpos

Page 63: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.62: Construction of a DFA directly from a regular expression

Page 64: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.63: DFA constructed from Fig. 3.57

Page 65: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.64: Construction of Π new

Page 66: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.65: Transition table of minimum-state DFA

Page 67: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Figure 3.66: Data structure for representing transition tables

Page 68: Lexical Analysis Arial Font Family. Figure 3.1: Interactions between the lexical analyzer and the parser.

Terima Kasih