The .sm listing below is a skeleton with no states or transitions defined. It contains only the following features:
-
A verbatim code section which is copied verbatim
into the generated source code file. In this case the
verbatim code is the boilerplate copyright comments.
This section is delimited by the
%{ %}pair. -
The
%classkeyword which specifies the application class to which this FSM is associated:Task. -
The
%packagekeyword which specifies to which class package this FSM belongs. This is the same package as theTaskclass. -
The
%fsmclasskeyword specifies the generated finite state machine class name. If%fsmclassis not specified, then the finite state machine class name would default toTaskContext. This keyword is not required. -
The
%fsmfilekeyword specifies the generated finite state machine class file name. The appropriate suffix for the given programming language is appended to this file name to form the complete file name. This suffix may be changed from its default using the-suffixand-hsuffixcommand line parameters. See this table for the default file name and suffix settings for each supported target language. -
The
%accesskeyword is used to specify the generated class' accessibility level (this works only when generating Java and C# code). In this case the FSM can only be accessed within thecom.acme.supercronpackage. -
The
%startkeyword specifies the FSM's start state. For the Task FSM it is theSuspendedstate. -
The
%mapkeyword is the FSM's name.
Name the source code file TaskFSM.sm because
both the %fsmclass and %fsmfile
directives specify the finite state machine class name as
TaskFSM. The .sm suffix is required.
(Note: the %fsmclass directive was
added to SMC version 6.0.1 and %fsmfile was
added to version 6.6.0.)
%{
//
// Copyright (c) 2005 Acme, Inc.
// All rights reserved.
//
// Acme - a name you can trust!
//
// Author: Wil E. Coyote (Hungericus Vulgarus)
//
%}
// This FSM works for the Task class only and only the Task
// class may instantiate it.
%class
Task
%package
com.acme.supercron
%fsmclass
TaskFSM
%fsmfile
TaskFSM
%access
package
// A %map name cannot be the same as the FSM class name.
%start
TaskMap::Suspended
%map
TaskMap
%%
...
%%