Regular expressions to fsms

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

description

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+. Sequence abe Alternation a|b|E Charset [a-z] Zero or more x* One or more x+. Sequence Alternation - PowerPoint PPT Presentation

Transcript of Regular expressions to fsms

Page 1: Regular expressions to fsms

Regular expressions to fsms\hardware and software techniquesPaul Cockshott

Page 2: Regular expressions to fsms

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

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

Map to state machines

• Sequence abc

2

31 a

b

c

Page 5: Regular expressions to fsms

Map alternation

A|x|p

A

x

p

Page 6: Regular expressions to fsms

Map A+|b

A

A

b

Page 7: Regular expressions to fsms

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

PLA with latch

Input char State latch

clock

Next stateAction code

And planeOr plane

Productlines

Page 10: Regular expressions to fsms

AND plane

~a a ~b b

true and complement lines

a AND ~b

b

Page 11: Regular expressions to fsms

Or plane

p

q

P or q p

Page 12: Regular expressions to fsms

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

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

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

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.