Docsity

DFA Minimization and Lexical Analyzers, Slides of Compiler Construction

Partial preview of the text

Download DFA Minimization and Lexical Analyzers and more Slides Compiler Construction in PDF only on Docsity!

Compiler

Compiler

Construction

Construction

Compiler

Compiler

Construction

Construction

Lecture 9

DFA Minimization

DFA Minimization DFA Minimization

DFA Minimization

The generated DFA may

have a large number of

states.

DFA Minimization

DFA Minimization DFA Minimization

DFA Minimization

Idea: find groups of

equivalent states.

All transitions from

states in one group G

1

go to states in the same

group G

2

DFA Minimization

DFA Minimization DFA Minimization

DFA Minimization

Idea: find groups of

equivalent states.

All transitions from

states in one group G

1

go to states in the same

group G

2

DFA Minimization

DFA Minimization DFA Minimization

DFA Minimization

DFA for (a | b )abb*

A

a

b a

b b

E

B D

C

a

b

b

a

a

DFA Minimization

DFA Minimization DFA Minimization

DFA Minimization

Minimized DFA for (a | b )abb*

A,C

a

b

b b

E

B D

a

b

a

a

Lexical Analyzers

Lexical Analyzers Lexical Analyzers

Lexical Analyzers

Lexical analyzers (scanners)

use the same mechanism

but they:

Have multiple RE descriptions

for multiple tokens

Have a character stream at the

input

Lexical Analyzers

Lexical Analyzers Lexical Analyzers

Lexical Analyzers

Lexical analyzers (scanners)

use the same mechanism

but they:

Have multiple RE descriptions

for multiple tokens

Have a character stream at the

input

Lexical Analyzers

Lexical Analyzers Lexical Analyzers

Lexical Analyzers

Return a sequence of matching

tokens at the output (or an

error)

Always return the longest

matching token

Lexical Analyzers

Lexical Analyzers Lexical Analyzers

Lexical Analyzers

Return a sequence of matching

tokens at the output (or an

error)

Always return the longest

matching token

Lexical Analyzer Generators

Lexical Analyzer Generators Lexical Analyzer Generators

Lexical Analyzer Generators

The lexical analysis process

can automated

We only need to specify

Regular expressions for tokens

Rule priorities for multiple

longest match cases

Lexical Analyzer Generators

Lexical Analyzer Generators Lexical Analyzer Generators

Lexical Analyzer Generators

The lexical analysis process

can automated

We only need to specify

Regular expressions for tokens

Rule priorities for multiple

longest match cases

Lexical Analyzer Generators

Lexical Analyzer Generators Lexical Analyzer Generators

Lexical Analyzer Generators

Flex

generates lexical analyzer in C

or C++

Jlex

written in Java. Generates

lexical analyzer in Java

Using Flex

Using Flex Using Flex

Using Flex

Provide a specification file

Flex reads this file and

produces C or C++ output file

contains the scanner.

The file consists of three

sections