Convert coroutine to state machine (FSM) and vice versa?

I am trying to find a generalized way to convert a coroutine written in a language such as go, python or javascript to a finite state machine (FSM). I need this in order to integrate several state machines into one big one, because people tend to more easily track the flow of instructions than jump through transitions. They show equivalent examples in both, but do not allow translating between them:

http://eli.thegreenplace.net/2009/08/29/co-routines-as-an-alternative-to-state-machines/

http://www.crystalclearsoftware.com/soc/coroutine/coroutine/finite_state_machines.html

So far, the closest I have found is Ragel , but it looks like it will convert a number of regular expressions to FSM, similar to how lex or yacc work.

If there is no existing tool for this with coroutines, is there one for generators? Perhaps they create an FSM inside that I could use:

http://almostobsolete.net/coffeescript-generators.html

https://www.npmjs.org/package/regenerator

Or does anyone know a general strategy to go through a coroutine, keep track of exits, and create a call tree that can be converted to FSM using goto or the switch command? This is normal if it only works on a subset of the language, for example, without structures, calls or function inclusions, which makes me wonder if the result of the parser work.

- FSM , .

: , . , , , FSM: FSM

+4

Source: https://habr.com/ru/post/1526435/


All Articles