FSML

From UniMod Wiki

FSML, an initialism of Finite State Machine Language, is the programming language to describe finite state machines (FSMs). It is meant to be used in conjunction with the UniMod 1.3 tool that provides only a graphic representation of FSM models using diagrams. For this purpose it was created the specific plug-in for Eclipse IDE that realizes FSML editor and connects it with the UniMod tool. So FSML provides you with a textual representation of the same FSM models that can be viewed as diagrams.

FSML format data files use a file extension .fsml.

Contents

FSML syntax

Syntax of Finite State Machine Language includes special constructions to describe all necessary elements of UniMod model. They are FSMs, their event providers and controlled objects, states, their nested FSMs, transitions and so on.

Event provider declaration (keyword uses)

Event provider is a Java-class and is identified by its full path.

Syntax:

uses <package name>.<class name>;

Example:

uses trafficlight.provider.TrafficSignalProvider;

Finite state machine declaration (keyword statemachine)

This declaration introduces next nesting level and contains the rest of FSML program.

Syntax:

statemachine <FSM name> { <FSM description> }

Example:

statemachine TrafficLightWithTimer { ... }

Controlled object declaration

This declaration is similar to declaration of a variable in Java language. Controlled object is also a Java-class and is identified by its full path.

Syntax:

<package name>.<class name> <controlled object name>;

Example:

trafficlight.object.Timer timer;

State declaration

There are three types of states: initial, normal and final. Every state introduces next nesting level and contains its description.

Syntax:

initial <state name> { <state description> }
<state name> { <state description> }
final <state name> { }

Examples:

initial Init { ... }
Active { ... }
final Final { }

Every type has some restrictions on its description. Initial state must contain a single transition without events and guard condition. Normal state can contain nested FSMs declarations, transitions and nested states but can't be empty. Final state must be empty. It is left only for all states to be listed in FSML program.

States must be listed in the following order: single initial state, arbitrary number of normal states, single final state. In case of nested states initial and final states can be omitted.

Nested FSM declaration (keyword include)

This declaration must be placed in the very beginning of state description.

Syntax:

include <comma-separated list of FSM names>;

Example:

include TrafficLightWithTimer, AnotherAutomaton;

Transition declaration (keywords on, if, else, execute, transitto)

This declaration is rather complex and consists of several parts: events, guard condition, list of actions and target state.

Syntax:

on <events> <guard condition>
execute <list of actions>
transitto <target state>;

Example:

on tick if timer.value < 5
execute green.turnBlinking, timer.decrement
transitto GreenBlinking;

There are several types of events:

  • Normal event (from event provider). There can be specified several normal events in a comma-separated list.
  • Event on enter to the state - enter.
  • Any normal event - any.
  • Event on exit from the state - exit (will be in the version compatible with UniMod 2).
Examples:

on tick, switch, stop
on enter
on any

Guard condition adds dependence on controlled objects - transition will be used only if corresponding guard condition is true. Guard condition can be defined with the following grammar:

S → 'else'
S → 'if' I0
I0 → I0 '||' I1
I0 → I1
I1 → I1 '&&' I2
I1 → I2
I2 → '!' I3
I2 → I3
I3 → '(' S ')'
I3 → I4
I4 → I5 rel I5
I4 → ident_bool
I4 → const_bool
I5 → ident_number
I5 → const_number

Here rel means string representation of math relation: '>', '<', '>=', '<=', '!=', '=='; ident_bool and ident_number - input values of types boolean and int accordingly; const_bool - constant true or false, const_number - integer constant. Guard condition else - supplementary for all other guard conditions on the same events.

Example:

if (timer.value < 5) && (timer.value >= 0)

Actions can be specified using comma-separated list:

Example:

execute green.turnBlinking, timer.decrement

Target state defines where current transition will finish at:

Example:

transitto GreenBlinking

Some of the parts described above can be omitted. Let's view all cases in the table below where '+' means that part must be present, '-' means that part must be absent, '?' - its presence is optional.

State type Events Guard condition Actions Target state
Initial - - ? +
Normal + ? ? ?

In case when target state is omitted transition is considered to be a loop.

Comments

Comments in FSML are the same as in Java language. There are two types of comments: single-line and multiline.

Examples:

// Single-line comments
/* Multiline
comments */

FSML editor means

FSML editor includes the following means:

  • Syntax validation with error highlighting. Now it's basic validation without checking any semantic properties of the FSM. It's activated by saving the source of program.
  • Autocompletion. It assists you with the list of correct tokens that can be used in the specified place. It's activated by the hotkey Ctrl-Enter.
  • Generation of UniMod model file. It allowes you to view and edit created FSM model in the visual mode - using UniMod diagrams. Now the simple automatic layouter is used to layout diagrams. It's activated through the context popup menu from the program source area (Look at the example below).

Current limitation is the one-way transformation between FSML program and UniMod diagrams. Now you cannot generate FSML source from UniMod model (but it's planned to be added).

How to use

How to install

To use the FSML editor it is necessary to:

  • install the latest version of the UniMod 1.3 tool (1.3.39 currently);
  • install the FSMLEditor plug-in (just extract it into the directory Eclipse/plugins and restart Eclipse IDE).

Then FSML editor will be used by default for editing files with extension .fsml.

Example of use

FSML editor is supposed to be used in the way described below.

  • Write FSML program using preinstalled editor.

  • Generate UniMod model from program source through the popup context menu item "Generate UniMod xml file".

  • Update UniMod model just in one way later on, either in textual or in visual mode.

Using textual mode (FSML) will make you regenerate UniMod model. Using visual mode (diagrams) will make FSML program out-of-date and not useful any more.

Future plans

  1. Add two-way synchronization with automatic keeping both FSML program and UniMod diagrams up-to-date.
  2. Add validation of semantic properties.
  3. Realize a version compatible with UniMod 2.

Links