View mode: basic / threaded / horizontal-split · Log in · Help
September 27, 2012
Finite state machine in D
Hello
Could someone help me with FSM (like boost MSM but simpler and in D of 
course) - where should I start from? I found good paper about FSM 
implementation in c++ (with type list and so on), but I'm not sure it is 
applicable in D. What is the D-way to implement fsm with code generation?
September 27, 2012
Re: Finite state machine in D
> What is the D-way to implement fsm with code generation?

you might have a look at ragel:

http://www.complang.org/ragel/
September 27, 2012
Re: Finite state machine in D
27.09.2012 14:48, Mirko Pilger пишет:
>> What is the D-way to implement fsm with code generation?
>
> you might have a look at ragel:
>
> http://www.complang.org/ragel/
I had. It's good but is too fat for my purpose - simple fsm 
implementation in D without third party's instruments (for simple use). 
My question was inspired when I saw several fsm implementation in c++, 
but I didn't find D implementation to compare with. And now I'm writing 
my own. This writing seems to be very useful - I've found new advantages 
of D over C++ =)
September 27, 2012
Re: Finite state machine in D
On Thu, Sep 27, 2012 at 10:15 AM, Druzhinin Alexandr
<news@digitalmars.com> wrote:
> 27.09.2012 14:48, Mirko Pilger пишет:
>
>>> What is the D-way to implement fsm with code generation?

I'm not sure you need code generation. Using D functions literals or
closures already gives you a good part of a FSM:

States are functions, that accept a current 'payload' and return a
tuple consisting of another function and the new payload.
The FSM driver just call the current state on the current payload,
stores the new stat/payload pair and loop until it reaches a terminal
state.

I can search at home to see what I have (if I kept anything), if
you're interested. It's a FSM in 10-20 lines of code, IIRC.

If you really want code generation, could you give us some use case?
std.regex contains a compile-time regex engine that is, in a way, a
FSM on steroids. I have a parser generator project on github that also
does code generation, but both modules are for a particular type of
automata: parsers/matchers, not a generic FSM.
September 27, 2012
Re: Finite state machine in D
27.09.2012 18:15, Philippe Sigaud пишет:
>
> I'm not sure you need code generation. Using D functions literals or
> closures already gives you a good part of a FSM:
>
> States are functions, that accept a current 'payload' and return a
> tuple consisting of another function and the new payload.
> The FSM driver just call the current state on the current payload,
> stores the new stat/payload pair and loop until it reaches a terminal
> state.
>
> I can search at home to see what I have (if I kept anything), if
> you're interested. It's a FSM in 10-20 lines of code, IIRC.
>
yes, I'm interested. Thanks in advance.

What about code generation - I just want to learn how to do it, so
September 27, 2012
Re: Finite state machine in D
On Thu, Sep 27, 2012 at 2:39 PM, Druzhinin Alexandr
<news@digitalmars.com> wrote:
>>
> yes, I'm interested. Thanks in advance.

Here is an example:

http://dpaste.dzfl.pl/81a63163


> What about code generation - I just want to learn how to do it, so

Seeing your code in another thread, yes code generation could help
here. I have a template tutorial (a bit light on code generation) that
might help you on this.

https://github.com/PhilippeSigaud/D-templates-tutorial/blob/master/dtemplates.pdf?raw=true

(this will download a pdf)
September 29, 2012
Re: Finite state machine in D
28.09.2012 01:24, Philippe Sigaud пишет:
> Here is an example:
>
> http://dpaste.dzfl.pl/81a63163
it's really interesting for me.

> Seeing your code in another thread, yes code generation could help
> here. I have a template tutorial (a bit light on code generation) that
> might help you on this.
>
> https://github.com/PhilippeSigaud/D-templates-tutorial/blob/master/dtemplates.pdf?raw=true
>
> (this will download a pdf)
>
Oh, there's a lot to know. ) Thank you!
Top | Discussion index | About this forum | D home