FSM之SMC使用总结

23 篇文章 2 订阅

FSM之SMC使用总结


 Part1: Smc.jar state machine compiler usage

 Reference:
     http://smc.sourceforge.net/

   (Updated February 16, 2015)
   
 Downloads:
     http://sourceforge.net/projects/smc/files/
 

 1) show help:

   

$ java -jar ./Smc.jar -help

  2) generate java (c, cpp, js, python, object-c ...) classes from user_defined.sm file:

  

$ java -jar Smc.jar -c++ user_defined.sm
$ java -jar Smc.jar -graph -glevel 1 user_defined.sm

 A Filename.dot file also generated (Filename should replaced by actural dot filename).
  
$ java -jar ./Smc.jar -java7 user_defined.sm

3) generate a workflow map

You need graphviz installed first, and add path to .../bin/dot.exe into system environments. in my pc, that is:

       C:\DEVPACK\graphviz-2.38\release\bin

   Now enter folder of Filename.dot generated in step 2), and type:
 

 $ dot Filename.dot -Tpng -o Filename.png

 Enjoy it!


 Part2: Example

1) user_defined.sm. The only file we should created by hands

///
// ColorTable.sm
//   -- ColorTable State Map for C++ classes auto-generation
//
// 1) generate c++ classes:
//   $ java -jar Smc.jar -c++ ColorTable.sm
//
// 2) generate graphviz dot graph:
//   $ java -jar Smc.jar -graph -glevel 1 ColorTable.sm
//
// see also:
//   http://graphviz.org/
//
// Author: cheungmine
// Copyright 2015-?, All rights reserved.
//
///
%class ColorTable
%header ColorTable.h
%start ColorTableMap::Shuffle
%map ColorTableMap
%%
/**
* State {
*     Transition [Guard Condition]
*         EndState {
*             Action(s)
*         }
*
*     Transition [context.getOwner().is_valid()]
*         EndState {
*             Action(s)
*         }
*     ...
* }
*/
Shuffle
Entry {
    enterShuffle();
}
Exit {
    leaveShuffle();
}
{
    Next [ context.getOwner().shuffleDone() ]
        Swappable {
			//=>user swap actions
        }
}


Swappable
Entry {
    enterSwappable();
}
Exit {
    leaveSwappable();
}
{
	Next [context.getOwner().swapDone() && context.getOwner().canErase()]
        Erasable {
        }
	Next [context.getOwner().swapDone()]
		Shuffle {
		}
}


Erasable
Entry {
    enterErasable();
}
Exit {
    leaveErasable();
}
{
	Next [ context.getOwner().eraseDone() ]
        Collapse {
        }
}


Collapse
Entry {
    enterCollapse();
}
Exit {
    leaveCollapse();
}
{
	Next [context.getOwner().collapseDone() && context.getOwner().canErase()]
		Erasable {
		}
	Next [context.getOwner().collapseDone()]
		Crash {
		}
}


Crash
Entry {
    enterCrash();
}
Exit {
    leaveCrash();
}
{
    Next [ context.getOwner().crashDone() && context.getOwner().canErase() ]
        Erasable {
        }
    Next [ context.getOwner().crashDone() ]
        Swappable {
			//=>user swap actions
        }
}
%%

2) generate all derived files(default is c++):

$ java -jar Smc.jar -graph -glevel 1 ColorTable.sm

3) generate flow map using graphviz:

$ dot ColorTable.dot -Tpng -o ColorTable.png

没图你说个毛! 下面上图:


Game Over!




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

车斗

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值