1 #ifndef PATH_INTERPRETER
2 #define PATH_INTERPRETER
3
4 #define WIN32_LEAN_AND_MEAN
5 #include <windows.h>
6 #include <string.h>
7 #include <stdlib.h>
8 #include <ctype.h>
9 #include <string>
10 #include <list>
11
12 using std::string;
13 using std::list;
14
15 #define MAX_WORD_LEN 8 // 8 Bytes
16
17 class ContexScan;
18
19 // CPathScriptLoader
20 class CPathScriptLoader
21 {
22 public:
23 string Context;
24
25 void LoadScript( const char *szFile );
26 };
27
28 //
29 // Contex Lex
30 //
31 //
32 // ContexScan
33 class ContexScan
34 {
35 public:
36 enum ScanState { WORD, NOPRINT, };
37
38 public:
39 ContexScan();
40 ~ContexScan();
41
42 void SetExpression( const char *szExpr );
43
44 bool SkipWord( const char *szWord );
45 char * GetNextWord();
46 char * CurrentWord() { return m_szCurrWord; }
47 bool NextWord();
48 void RebackWordByCount( int n ); // 退几个?
49 void RebackNearestWordByName( const char *szWord ); // 退到哪个?
50
51 private:
52 char * m_szExpr;
53 char * m_pLastChar;
54 char * m_pCurrChar;
55 char m_szCurrWord[MAX_WORD_LEN];
56 ScanState m_eState;
57 };
58
59 //
60 // Syntax Tree Nodes
61 //
62 // AbstractNode
63 class AbstractNode
64 {
65 public:
66 AbstractNode( ContexScan& contex );
67 virtual ~AbstractNode();
68
69 virtual void Parse() = 0;
70
71 protected:
72 ContexScan& m_RefContexScan;
73 list<AbstractNode *> m_Nodes;
74 };
75
76 // ProgramNode
77 class ProgramNode : public AbstractNode
78 {
79 public:
80 ProgramNode( ContexScan& contex );
81 virtual ~ProgramNode();
82
83 virtual void Parse();
84 };
85
86 // CommandListNode
87 class CommandListNode : public AbstractNode
88 {
89 public:
90 CommandListNode( ContexScan& contex );
91 virtual ~CommandListNode();
92
93 virtual void Parse();
94 };
95
96 // CommandNode
97 class CommandNode : public AbstractNode
98 {
99 public:
100 CommandNode( ContexScan& contex );
101 virtual ~CommandNode();
102
103 virtual void Parse();
104 };
105
106 // RepeatNode
107 class RepeatNode : public AbstractNode
108 {
109 public:
110 RepeatNode( ContexScan& contex );
111 virtual ~RepeatNode();
112
113 virtual void Parse();
114 };
115
116 // BlockNode
117 class BlockNode : public AbstractNode
118 {
119 public:
120 BlockNode( ContexScan& contex );
121 virtual ~BlockNode();
122
123 virtual void Parse();
124 };
125
126 // PrimitiveNode
127 class PrimitiveNode : public AbstractNode
128 {
129 public:
130 PrimitiveNode( ContexScan& contex );
131 virtual ~PrimitiveNode();
132
133 virtual void Parse();
134 };
135
136 // CPathInterpret
137 // The Interpreter Facade interface
138 class CPathInterpret
139 {
140 public:
141 enum InterpretMode { NDEBUG, DEBUG, };
142
143 public:
144 static InterpretMode m_Mode;
145
146 public:
147 void LoadScript( const char *szFile );
148 void Interpret( InterpretMode mode = NDEBUG );
149
150 private:
151 CPathScriptLoader m_ScriptLoader;
152 ContexScan m_ContexScaner;
153
154 };
155
156 #endif // PATH_INTERPRETER
157