src/Parser.h

changeset 97
49e38433b9fd
parent 92
3a00d396bce2
child 98
ea02b78a737a
equal deleted inserted replaced
96:3384d7aa036a 97:49e38433b9fd
33 #include "Main.h" 33 #include "Main.h"
34 #include "Commands.h" 34 #include "Commands.h"
35 #include "LexerScanner.h" 35 #include "LexerScanner.h"
36 #include "Tokens.h" 36 #include "Tokens.h"
37 37
38 // TODO: get rid of this
39 #define MAX_SCOPE 32
40
41 // TODO: get rid of this too? 38 // TODO: get rid of this too?
42 #define MAX_CASE 64 39 #define MAX_CASE 64
43 40
44 // TODO: get rid of this 41 // TODO: get rid of this
45 #define MAX_MARKS 512 42 #define MAX_MARKS 512
89 EAssignDiv, 86 EAssignDiv,
90 EAssignMod, 87 EAssignMod,
91 }; 88 };
92 89
93 // ============================================================================ 90 // ============================================================================
91 //
92 struct CaseInfo
93 {
94 ByteMark* mark;
95 int number;
96 DataBuffer* data;
97 };
98
99 // ============================================================================
100 //
94 // Meta-data about scopes 101 // Meta-data about scopes
95 // 102 //
96 struct ScopeInfo 103 struct ScopeInfo
97 { 104 {
98 ByteMark* mark1; 105 ByteMark* mark1;
99 ByteMark* mark2; 106 ByteMark* mark2;
100 EScopeType type; 107 EScopeType type;
101 DataBuffer* buffer1; 108 DataBuffer* buffer1;
102 109
103 // switch-related stuff 110 // switch-related stuff
104 // Which case are we at? 111 List<CaseInfo>::Iterator casecursor;
105 int casecursor; 112 List<CaseInfo> cases;
106
107 // Marks to case-blocks
108 ByteMark* casemarks[MAX_CASE];
109
110 // Numbers of the case labels
111 int casenumbers[MAX_CASE];
112
113 // actual case blocks
114 DataBuffer* casebuffers[MAX_CASE];
115
116 // What is the current buffer of the block?
117 DataBuffer* recordbuffer;
118 }; 113 };
119 114
120 // ============================================================================ 115 // ============================================================================
121 // 116 //
122 struct ConstantInfo 117 struct ConstantInfo
131 class BotscriptParser 126 class BotscriptParser
132 { 127 {
133 PROPERTY (public, bool, ReadOnly, BOOL_OPS, STOCK_WRITE) 128 PROPERTY (public, bool, ReadOnly, BOOL_OPS, STOCK_WRITE)
134 129
135 public: 130 public:
136 // ==================================================================== 131 enum EReset
137 // METHODS 132 {
133 eNoReset,
134 eResetScope,
135 };
136
138 BotscriptParser(); 137 BotscriptParser();
139 ~BotscriptParser(); 138 ~BotscriptParser();
140 ConstantInfo* FindConstant (const String& tok); 139 ConstantInfo* FindConstant (const String& tok);
141 void ParseBotscript (String fileName); 140 void ParseBotscript (String fileName);
142 DataBuffer* ParseCommand (CommandInfo* comm); 141 DataBuffer* ParseCommand (CommandInfo* comm);
143 DataBuffer* ParseAssignment (ScriptVariable* var); 142 DataBuffer* ParseAssignment (ScriptVariable* var);
144 EAssignmentOperator ParseAssignmentOperator (); 143 EAssignmentOperator ParseAssignmentOperator ();
145 String ParseFloat(); 144 String ParseFloat();
146 void PushScope(); 145 void PushScope (EReset reset = eResetScope);
147 DataBuffer* ParseStatement(); 146 DataBuffer* ParseStatement();
148 void AddSwitchCase (DataBuffer* b); 147 void AddSwitchCase (DataBuffer* b);
149 void CheckToplevel(); 148 void CheckToplevel();
150 void CheckNotToplevel(); 149 void CheckNotToplevel();
151 bool TokenIs (EToken a); 150 bool TokenIs (EToken a);
195 194
196 // How many bytes have we written to file? 195 // How many bytes have we written to file?
197 int mNumWrittenBytes; 196 int mNumWrittenBytes;
198 197
199 // Scope data 198 // Scope data
200 // TODO: make a List 199 List<ScopeInfo> mScopeStack;
201 ScopeInfo mScopeStack[MAX_SCOPE];
202 200
203 DataBuffer* buffer(); 201 DataBuffer* buffer();
204 void ParseStateBlock(); 202 void ParseStateBlock();
205 void ParseEventBlock(); 203 void ParseEventBlock();
206 void ParseMainloop(); 204 void ParseMainloop();

mercurial