Regular expressions to fsms \hardware and software techniques Paul Cockshott.

15
Regular expressions to fsms \hardware and software techniques Paul Cockshott

Transcript of Regular expressions to fsms \hardware and software techniques Paul Cockshott.

Page 1: Regular expressions to fsms \hardware and software techniques Paul Cockshott.

Regular expressions to fsms\hardware and software techniquesPaul Cockshott

Page 2: Regular expressions to fsms \hardware and software techniques Paul Cockshott.

Extended regular grammars

• Sequence abe• Alternation a|b|E• Charset [a-z]• Zero or more x*• One or more x+

Page 3: Regular expressions to fsms \hardware and software techniques Paul Cockshott.

Reduced forms

• Sequence abe• Alternation a|b|E• Charset [a-z]• Zero or more x*• One or more x+

• Sequence• Alternation• -> a|b|c|d….• x+|ε• x+

- ε is the null character

Page 4: Regular expressions to fsms \hardware and software techniques Paul Cockshott.

Map to state machines

• Sequence abc

2

31 a

b

c

Page 5: Regular expressions to fsms \hardware and software techniques Paul Cockshott.

Map alternation

A|x|p

A

x

p

Page 6: Regular expressions to fsms \hardware and software techniques Paul Cockshott.

Map A+|b

A

A

b

Page 7: Regular expressions to fsms \hardware and software techniques Paul Cockshott.

FSM Implementations

PLA Hardware

State table in RAM Hardware Software

State table with class table

Software Software

Page 8: Regular expressions to fsms \hardware and software techniques Paul Cockshott.

Hardware and software FSMs

Hardware• Interpreting machine

code in a cpu• Interpreting network

addresses in a router chip

Software• Compilers• Software routers • Protocol analysers

Page 9: Regular expressions to fsms \hardware and software techniques Paul Cockshott.

PLA with latch

Input char State latch

clock

Next stateAction code

And planeOr plane

Productlines

Page 10: Regular expressions to fsms \hardware and software techniques Paul Cockshott.

AND plane

~a a ~b b

true and complement lines

a AND ~b

b

Page 11: Regular expressions to fsms \hardware and software techniques Paul Cockshott.

Or plane

p

q

P or q p

Page 12: Regular expressions to fsms \hardware and software techniques Paul Cockshott.

Advantage of PLA

• Very fast – uses the minimum logic• Lends itself to logic minimisation• Efficient layout on silicon• Method of choice for parsing simple

regular grammars at > cpu speeds in instruction decode units

Page 13: Regular expressions to fsms \hardware and software techniques Paul Cockshott.

RAM based FSM

1

Source data

+

Fsm table

First char index reg

Last char index

instruction

State sel

Current char

State line

Char col

hit

8 bits

6bits

8 bits

Page 14: Regular expressions to fsms \hardware and software techniques Paul Cockshott.

Add char class map

+Fsm table

First char index reg

Last char index

instruction

State sel

Current char

State line

Char col

hitChar class map

Page 15: Regular expressions to fsms \hardware and software techniques Paul Cockshott.

Advantages of char class map

• Reduces the size of the FSM table.• If we have n states we would otherwise

require 256n locations in table. With char class map we require c x n where c is the number of distinct character classes in the grammar.