For off-line state machine generation, the parser generator is writing source code
that is later compiled as part of a project that needs a state machine. In this case
the action functions don't need to have been pre-written as with the inline
state machine. Hence there is an alternative way to write the action handler code that
is more in the style of traditional parser generators like Bison or Yacc.
Another advantage is that actions written in the format below do not need
entries in an actions
section of the FSM description.
In this alternative format, the action function code is written inline with the grammar rules. Instead of finishing a grammar rule with an '=' sign and a comma-separated list of function names, we follow the grammar rule immediately with C# code enclosed in curly braces.
The code below is equivalent to the action handlers described in the inline action section elsewhere in this documentation.
// Once the lights have gone green, there is a
// minimum interval they must remain green before
// the controller will respond to the next button press.
TimedGreen:
TIMERTICK[ButtonWasPressed] Yellow
{
SetLightYellow();
SetYellowTimer();
EarlyButtonPressCount++;
}
| BUTTONPRESS TimedGreen
= RecordButtonPressed
| TIMERTICK[!ButtonWasPressed] Green
;
Notice that it is still permitted to use the inline action handler syntax even for off-line state machines. You cannot however use the form described in this page when creating a grammar description to be used in an inline state machine, as source code compilation into the current application via a dynamically compiled assembly is not supported.