views:

652

answers:

5

Given a regular expression, I'm looking for a package which will dynamically generate the code for a finite state machine that implements the RE.

C/C++ and Python preferred, but other languages are of interest as well.

+1  A: 

It might not be exactly what you're looking for, but the Xerox Finite State Transducer supports regular expressions, builds the machine, and even can create a graphical representation using GraphViz.

It's really nifty for things like morphology, but otherwise, I'd suggest it mainly if you're looking something to explore the theoretical side of finite state machines.

Two caveats: it uses its own syntax, so it's not necessarily going to translate over to your languages of choice easily, and I'm pretty sure you have to get a license for it. It comes with Karttunnen and Beesley's book "Finite State Morphology", which is a very interesting read in its own right.

Robert Elwell
+1  A: 

re2c generates C code. I'm not sure what you mean by 'dynamically' -- AFAIK you'd have to compile and dynamic-load the output, if you want to call on the generated code during the same run that you generated it.

Darius Bacon
A: 

sorry i dont speak english verry well but i have some qustion on state works. i’m trainee and i have a project on finit state machine. i search a tool who can do this applications.i evaluate some tools and i want knowledge if state works do it: 1-stateworks can generate a code C from a model of FSM? 2-state works can generate a documentation. 3-state works can give a debug 4-state works can give interface with the target? 5-rétroengeneering 6-state works can manage the hierarchical automat? i wait your answer thank’s

A: 

What you're asking for is a lexer... There are plenty of them for a plethora of programming languages. For a start you can have a look here.

Tal Pressman
+2  A: 

Ragel may be what your are looking for.

It generates C/C++/D/Ruby/Java code for state machines. These are described using both regular expressions and operators.

Check the website, its front page is quite explicit.

bltxd