78 try |
78 try |
79 { |
79 { |
80 ScriptVariable* globalvar; |
80 ScriptVariable* globalvar; |
81 mLexer->MustGetNext(); |
81 mLexer->MustGetNext(); |
82 |
82 |
83 Print ("Token type: %1\n", mLexer->DescribeTokenType (mLexer->GetTokenType())); |
|
84 |
|
85 if (mLexer->GetTokenType() == tkColon) |
83 if (mLexer->GetTokenType() == tkColon) |
86 return new ExpressionColon; |
84 return new ExpressionColon; |
87 |
85 |
88 // Check for operator |
86 // Check for operator |
89 for (const OperatorInfo& op : gOperators) |
87 for (const OperatorInfo& op : gOperators) |
219 ExpressionOperator* op = static_cast<ExpressionOperator*> (*it); |
217 ExpressionOperator* op = static_cast<ExpressionOperator*> (*it); |
220 |
218 |
221 // Unary minus with a value as the previous symbol cannot really be |
219 // Unary minus with a value as the previous symbol cannot really be |
222 // unary; replace with binary minus. |
220 // unary; replace with binary minus. |
223 if (op->GetID() == opUnaryMinus && (*(it - 1))->GetType() == eValueSymbol) |
221 if (op->GetID() == opUnaryMinus && (*(it - 1))->GetType() == eValueSymbol) |
224 { |
|
225 Print ("Changing symbol operator #%1 from %2 to %3\n", |
|
226 it - mSymbols.begin(), op->GetID(), opSubtraction); |
|
227 op->SetID (opSubtraction); |
222 op->SetID (opSubtraction); |
228 } |
|
229 } |
223 } |
230 } |
224 } |
231 |
225 |
232 // ============================================================================= |
226 // ============================================================================= |
233 // |
227 // |
262 if (mSymbols.Size() == 1) |
256 if (mSymbols.Size() == 1) |
263 { |
257 { |
264 if (mSymbols[0]->GetType() != eValueSymbol) |
258 if (mSymbols[0]->GetType() != eValueSymbol) |
265 Error ("bad expression"); |
259 Error ("bad expression"); |
266 |
260 |
267 Print ("Expression speedy-verified (1 expr symbol)\n"); |
|
268 return; |
261 return; |
269 } |
262 } |
270 |
263 |
271 if (mType == EStringType) |
264 if (mType == EStringType) |
272 Error ("Cannot perform operations on strings"); |
265 Error ("Cannot perform operations on strings"); |
361 |
354 |
362 for (int i = 0; i < mSymbols.Size(); ++i) |
355 for (int i = 0; i < mSymbols.Size(); ++i) |
363 if (verified[i] == false) |
356 if (verified[i] == false) |
364 Error ("malformed expression: expr symbol #%1 is was left unverified", i); |
357 Error ("malformed expression: expr symbol #%1 is was left unverified", i); |
365 |
358 |
366 Print ("Expression verified.\n"); |
|
367 delete verified; |
359 delete verified; |
368 } |
360 } |
369 |
361 |
370 |
362 |
371 // ============================================================================= |
363 // ============================================================================= |
401 // |
393 // |
402 ExpressionValue* Expression::EvaluateOperator (const ExpressionOperator* op, |
394 ExpressionValue* Expression::EvaluateOperator (const ExpressionOperator* op, |
403 const List<ExpressionValue*>& values) |
395 const List<ExpressionValue*>& values) |
404 { |
396 { |
405 const OperatorInfo* info = &gOperators[op->GetID()]; |
397 const OperatorInfo* info = &gOperators[op->GetID()]; |
406 Print ("Process operator %1\n", info - gOperators); |
|
407 bool isconstexpr = true; |
398 bool isconstexpr = true; |
408 |
399 |
409 for (ExpressionValue* val : values) |
400 for (ExpressionValue* val : values) |
410 { |
401 { |
411 if (val->IsConstexpr() == false) |
402 if (val->IsConstexpr() == false) |
449 buf->AddReference (mark2); // marked by mark2. |
440 buf->AddReference (mark2); // marked by mark2. |
450 buf->AdjustMark (mark1); // move mark1 at the end of the true case |
441 buf->AdjustMark (mark1); // move mark1 at the end of the true case |
451 buf->MergeAndDestroy (b2); // perform third operand (false case) |
442 buf->MergeAndDestroy (b2); // perform third operand (false case) |
452 buf->AdjustMark (mark2); // move the ending mark2 here |
443 buf->AdjustMark (mark2); // move the ending mark2 here |
453 |
444 |
454 Print ("Mark positions: %1 %2\n", mark1->pos, mark2->pos); |
|
455 |
|
456 for (int i = 0; i < 3; ++i) |
445 for (int i = 0; i < 3; ++i) |
457 values[i]->SetBuffer (null); |
446 values[i]->SetBuffer (null); |
458 } |
447 } |
459 else |
448 else |
460 { |
449 { |