The list of input events or tokens

The tokens or events section (the names are synonyms) contains a definitive list of the recognised input event types that the FSM consumes. This is the list of names of event types that the input event source object (or tokeniser) must provide. Arrival of any other value than those in this list will cause the FSM engine to report an error.  An input event source is an object that provides the stream of input events that the state machine responds to.

Each event has a name and an integer code, however the value can be left out if you are happy for the parser generator to provide a code value automatically. If providing a code value of your own, it must be an integer value between zero and 16383 inclusive. The auto-generated event code values lie outside this range, so it is possible to mix defined and auto-generated event code values within the same grammar.

Once the state machine has been created from your grammar, it is possible for your input event source class to look up the code values that have been assigned to each event name. Parser generation causes the FSMFactory for a given FSM class to contain a dictionary-like property whose name is Tokens. If you want to look up the value that was allocated to the token with name SQUIGGLE, the following code will obtain the token value:


int squiggleCodeValue = FSMFactory<MyFSMClass>.Tokens["SQUIGGLE"];

Note that the above process will be quite inefficient if called to look up token values repeatedly while scanning input. It might be better to look these up and cache them into named read-only integers, or perhaps assign values to the tokens in the grammar that match those in the tokeniser.

Entries in the tokens/events section of the grammar are separated by commas. There is no comma between the final entry and the closing curly brace. Each entry consists of the token name, and optionally an equals sign followed by an integer numeric value.

Example


events
{
	BUTTONPRESSED = 1, // Has a user-specified token value
	TIMEOUT = 2,       // Also has a user=specified value
	ALARMACTIVATED,    // Will be allocated a value beyond 16384
	POWERDOWN
}

Note that there are some reserved token names used internally by the FSM generator, which you should not use. These are currently: EOF, SOF, ERR, and _Start.