码迷,mamicode.com
首页 > 其他好文 > 详细

FSM之SMC使用总结

时间:2017-05-26 19:35:57      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:efi   min   wap   graph   data   amp   .exe   org   mod   

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!




FSM之SMC使用总结

标签:efi   min   wap   graph   data   amp   .exe   org   mod   

原文地址:http://www.cnblogs.com/llguanli/p/6910090.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!