mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
31 lines
826 B
C++
31 lines
826 B
C++
#include "evaluate_context.h"
|
|
#include <string.h>
|
|
|
|
namespace Calculation {
|
|
|
|
EvaluateContext::EvaluateContext(::Context * parentContext, CalculationStore * calculationStore) :
|
|
m_ansValue(nullptr),
|
|
m_calculationStore(calculationStore),
|
|
m_context(parentContext)
|
|
{
|
|
}
|
|
|
|
Expression * EvaluateContext::ansValue() {
|
|
if (m_calculationStore->numberOfCalculations() == 0) {
|
|
return defaultExpression();
|
|
}
|
|
Calculation * lastCalculation = m_calculationStore->calculationAtIndex(m_calculationStore->numberOfCalculations()-1);
|
|
m_ansValue = lastCalculation->evaluation();
|
|
return m_ansValue;
|
|
}
|
|
|
|
const Expression * EvaluateContext::expressionForSymbol(const Symbol * symbol) {
|
|
if (symbol->name() == Symbol::SpecialSymbols::Ans) {
|
|
return ansValue();
|
|
} else {
|
|
return m_context->expressionForSymbol(symbol);
|
|
}
|
|
}
|
|
|
|
}
|