Finite state machine grammar syntax

In this section we shall describe the syntax for the input grammar files that are to be converted into a finite state machine (FSM) for recognising input events with tested guard conditions.

The basic model is that you write a formal FSM specification and store it to a file with a '.g' extension to its name. The parselr command-line program is then run with the command line option -f and your FSM specification file as arguments. This causes a new file filled containing C# source code to be generated. That C# source file, along with a C# source file that you write providing an input event source are added to the project in Visual Studio or other C# development environment you are using. References to the Parsing.dll and ParserGenerator.dll libraries are added to the project, and the project compiled.

The process of constructing an input event source, and of setting up the project are described elsewhere. Here we focus on the contents of the input FSM specification file.

Structure of input FSM specification file

The input file contains between two and four discrete sections. These are in order:

All sections begin with a keyword as given in the list of section descriptions above. Some section types have alternative keywords that are aliases for each other, namely events or tokens, and guards or conditions. The fsm section takes an argument to the fsm keyword in parentheses where the argument is the name of the starting state in the FSM in which the machine will begin to execute. All four sections have bodies enclosed in curly braces.

Example


options
{
    ... options go here ...
}

events
{
    ... events or tokens go here ...
}

guards
{
    ... guard condition function names here ...
}

fsm(startingStateName)
{
    ... grammar description goes here ...
}