Regular expressions to fsms
description
Transcript of Regular expressions to fsms
Regular expressions to fsms\hardware and software techniquesPaul Cockshott
Extended regular grammars
• Sequence abe• Alternation a|b|E• Charset [a-z]• Zero or more x*• One or more x+
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
Map to state machines
• Sequence abc
2
31 a
b
c
Map alternation
A|x|p
A
x
p
Map A+|b
A
A
b
FSM Implementations
PLA Hardware
State table in RAM Hardware Software
State table with class table
Software Software
Hardware and software FSMs
Hardware• Interpreting machine
code in a cpu• Interpreting network
addresses in a router chip
Software• Compilers• Software routers • Protocol analysers
PLA with latch
Input char State latch
clock
Next stateAction code
And planeOr plane
Productlines
AND plane
~a a ~b b
true and complement lines
a AND ~b
b
Or plane
p
q
P or q p
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
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
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
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.