FSM Actions - RopleyIT/GLRParser GitHub Wiki

The actions section

When writing an offline state machine, where the FSM generator creates a C# source file to be subsequently compiled with the standard parser DLLs, any actions to be taken on transition between states are written in-line in the grammar as fragments of C# source code. In this case no actions section needs to be provided.

When writing an in-line parser, the intention is that the grammar is read, converted into a state machine at run-time, and that the FSM then starts running immediately. There is clearly no opportunity to put source code inline here, as the compiler never runs as part of this process.

Instead, the author of the FSM should write a list of action functions inside the user's FSM class, each with the correct signature. The actions section is where we list the names of these action functions so that the grammar can make calls on them by name, as directed by the use of these action names later in the grammar.

Each action function must have the same name as one of the listed actions in the actions section. It must have the correct signature as follows:


namespace MyApplication
{
    public partial class MyFSM
    {
        ... other things ...
         
        public void InsertBolt()
        {
            ... perform some action compatible with
                recognition of a complete rule  ...
        }
        ... other action methods ...
    }
}

Note that there are no parameters to the action function. The action function is written within the body of the FSM class, and has access therefore to its private and public memebers.

Example of actions section


actions
{
    InsertBolt,
    AttachNut,
    PaintUndercoat,
    DrillHole
}
⚠️ **GitHub.com Fallback** ⚠️