-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringFSM.h
More file actions
29 lines (21 loc) · 1001 Bytes
/
stringFSM.h
File metadata and controls
29 lines (21 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include "genericFSM.h"
#include "eventClass.h"
#define SX(x) (static_cast<void (genericFSM::*)(genericEvent*)>(&stringFSM::x))
class stringFSM : public genericFSM
{
public:
stringFSM() : genericFSM(&stringTable[0][0], 3, 4, INS_STRING, SX(assignValue)){}
private:
enum stringStates : stateType { INIT, INS_STRING, CTRL_CHAR};
typedef enum { VALID_CHAR, BACKSLASH, QUOTES, _EOF } stringEvents;
const fsmCell stringTable[3][4] =
{ // Event validChar, Event '\\', Event '"', Event EOF
{{INS_STRING, SX(nothing)}, {CTRL_CHAR, SX(nothing)}, {END, SX(end)}, {ERROR, SX(error)}}, //State INIT
{{INS_STRING, SX(nothing)}, {CTRL_CHAR, SX(nothing)}, {END, SX(end)}, {ERROR, SX(error)}}, //State INS_STRING
{{INS_STRING, SX(nothing)}, {INS_STRING, SX(nothing)}, {INS_STRING, SX(nothing)}, {ERROR, SX(error)}} //State CTRL_CHAR
};
void error(genericEvent* ev);
void end(genericEvent* ev);
void assignValue(genericEvent* ev);
};