89 EAssignDecrement, |
89 EAssignDecrement, |
90 }; |
90 }; |
91 |
91 |
92 // ============================================================================ |
92 // ============================================================================ |
93 // |
93 // |
|
94 struct Variable |
|
95 { |
|
96 enum EWritability |
|
97 { |
|
98 WRITE_Mutable, // normal read-many-write-many variable |
|
99 WRITE_Const, // write-once const variable |
|
100 WRITE_Constexpr, // const variable whose value is known to compiler |
|
101 }; |
|
102 |
|
103 String name; |
|
104 String statename; |
|
105 EType type; |
|
106 int index; |
|
107 EWritability writelevel; |
|
108 int value; |
|
109 String origin; |
|
110 |
|
111 inline bool IsGlobal() const |
|
112 { |
|
113 return statename.IsEmpty(); |
|
114 } |
|
115 }; |
|
116 |
|
117 // ============================================================================ |
|
118 // |
94 struct CaseInfo |
119 struct CaseInfo |
95 { |
120 { |
96 ByteMark* mark; |
121 ByteMark* mark; |
97 int number; |
122 int number; |
98 DataBuffer* data; |
123 DataBuffer* data; |
106 { |
131 { |
107 ByteMark* mark1; |
132 ByteMark* mark1; |
108 ByteMark* mark2; |
133 ByteMark* mark2; |
109 EScopeType type; |
134 EScopeType type; |
110 DataBuffer* buffer1; |
135 DataBuffer* buffer1; |
|
136 int globalVarIndexBase; |
|
137 int localVarIndexBase; |
111 |
138 |
112 // switch-related stuff |
139 // switch-related stuff |
113 List<CaseInfo>::Iterator casecursor; |
140 List<CaseInfo>::Iterator casecursor; |
114 List<CaseInfo> cases; |
141 List<CaseInfo> cases; |
|
142 List<Variable*> localVariables; |
|
143 List<Variable*> globalVariables; |
115 }; |
144 }; |
116 |
145 |
117 // ============================================================================ |
146 // ============================================================================ |
118 // |
147 // |
119 class BotscriptParser |
148 class BotscriptParser |
129 |
158 |
130 BotscriptParser(); |
159 BotscriptParser(); |
131 ~BotscriptParser(); |
160 ~BotscriptParser(); |
132 void ParseBotscript (String fileName); |
161 void ParseBotscript (String fileName); |
133 DataBuffer* ParseCommand (CommandInfo* comm); |
162 DataBuffer* ParseCommand (CommandInfo* comm); |
134 DataBuffer* ParseAssignment (ScriptVariable* var); |
163 DataBuffer* ParseAssignment (Variable* var); |
135 EAssignmentOperator ParseAssignmentOperator (); |
164 EAssignmentOperator ParseAssignmentOperator (); |
136 String ParseFloat(); |
165 String ParseFloat(); |
137 void PushScope (EReset reset = eResetScope); |
166 void PushScope (EReset reset = eResetScope); |
138 DataBuffer* ParseStatement(); |
167 DataBuffer* ParseStatement(); |
139 void AddSwitchCase (DataBuffer* b); |
168 void AddSwitchCase (DataBuffer* b); |
141 void CheckNotToplevel(); |
170 void CheckNotToplevel(); |
142 bool TokenIs (EToken a); |
171 bool TokenIs (EToken a); |
143 String GetTokenString(); |
172 String GetTokenString(); |
144 String DescribePosition() const; |
173 String DescribePosition() const; |
145 void WriteToFile (String outfile); |
174 void WriteToFile (String outfile); |
|
175 Variable* FindVariable (const String& name); |
|
176 bool IsInGlobalState() const; |
|
177 |
|
178 inline ScopeInfo& GetScope (int offset) |
|
179 { |
|
180 return mScopeStack[mScopeCursor - offset]; |
|
181 } |
146 |
182 |
147 inline int GetNumEvents() const |
183 inline int GetNumEvents() const |
148 { |
184 { |
149 return mNumEvents; |
185 return mNumEvents; |
150 } |
186 } |
177 EParserMode mCurrentMode; |
213 EParserMode mCurrentMode; |
178 String mCurrentState; |
214 String mCurrentState; |
179 bool mStateSpawnDefined; |
215 bool mStateSpawnDefined; |
180 bool mGotMainLoop; |
216 bool mGotMainLoop; |
181 int mScopeCursor; |
217 int mScopeCursor; |
182 DataBuffer* mIfExpression; |
|
183 bool mCanElse; |
218 bool mCanElse; |
184 List<UndefinedLabel> mUndefinedLabels; |
219 List<UndefinedLabel> mUndefinedLabels; |
185 |
220 |
186 // How many bytes have we written to file? |
221 // How many bytes have we written to file? |
187 int mNumWrittenBytes; |
222 int mNumWrittenBytes; |
211 void ParseEventdef(); |
246 void ParseEventdef(); |
212 void ParseFuncdef(); |
247 void ParseFuncdef(); |
213 void writeMemberBuffers(); |
248 void writeMemberBuffers(); |
214 void WriteStringTable(); |
249 void WriteStringTable(); |
215 DataBuffer* ParseExpression (EType reqtype, bool fromhere = false); |
250 DataBuffer* ParseExpression (EType reqtype, bool fromhere = false); |
216 EDataHeader GetAssigmentDataHeader (EAssignmentOperator op, ScriptVariable* var); |
251 EDataHeader GetAssigmentDataHeader (EAssignmentOperator op, Variable* var); |
217 }; |
252 }; |
218 |
253 |
219 #endif // BOTC_PARSER_H |
254 #endif // BOTC_PARSER_H |