00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <iostream>
00020 #include <string>
00021 using namespace std;
00022
00023 #include "fsm.h"
00024 using namespace FSM;
00025
00026
00028 enum Events
00029 {
00030 letter = 0,
00031 digit = 1
00032 };
00033
00034
00035
00036
00037 int main( int argc, char ** argv )
00038 {
00039
00040
00041
00042 #define FSMStateType string
00043 #define FSMEventType Events
00044
00045 SStateMachine< FSMStateType,
00046 FSMEventType,
00047 SEmptyFunctor< FSMStateType, FSMEventType >,
00048 SThrowStrategy< FSMEventType >
00049 >
00050 MyMachine(
00051
00052 FSM_BEGIN( "empty" )
00053
00054 FSM_STATES "empty" << "number" << "identifier" << "unknown"
00055
00056 FSM_EVENT(letter) "identifier" << "unknown" << "identifier" << "unknown"
00057 FSM_EVENT(digit) "number" << "number" << "identifier" << "unknown"
00058
00059 FSM_END
00060
00061 );
00062
00063 #undef FSMStateType
00064 #undef FSMEventType
00065
00066
00067
00068 cout << "StartState is: " << MyMachine << endl;
00069
00070 MyMachine << digit << digit << letter;
00071 cout << "The 'unknown' state is expected. Current state is: " << MyMachine << endl;
00072
00073
00074
00075
00076 cout << "Reset the machine. Current state is: " << (MyMachine << ResetMachine) << endl;
00077
00078 MyMachine << letter << digit << letter;
00079 cout << "The 'identifier' state is expected. Current state is: " << MyMachine << endl;
00080
00081 return 0;
00082 }
00083