PorygonLang/src/Evaluator/EvalValues/EvalValue.hpp

51 lines
1.2 KiB
C++
Raw Normal View History

#ifndef PORYGONLANG_EVALVALUE_HPP
#define PORYGONLANG_EVALVALUE_HPP
#include "../../ScriptType.hpp"
#include "../EvaluationException.hpp"
#include <string>
class EvalValue{
public:
virtual ~EvalValue() = default;
virtual ScriptType* GetType() = 0;
virtual long EvaluateInteger(){
throw EvaluationException("Can't evaluate this EvalValue as integer.");
}
virtual double EvaluateFloat(){
throw EvaluationException("Can't evaluate this EvalValue as float.");
}
virtual bool EvaluateBool(){
throw EvaluationException("Can't evaluate this EvalValue as bool.");
}
virtual std::string EvaluateString(){
throw EvaluationException("Can't evaluate this EvalValue as string.");
}
};
class BooleanEvalValue : public EvalValue{
bool _value;
ScriptType* _type;
public:
explicit BooleanEvalValue(bool val){
_value = val;
_type = new ScriptType(TypeClass::Bool);
}
~BooleanEvalValue() final{
delete _type;
}
ScriptType* GetType() final{
return _type;
};
bool EvaluateBool() final{
return _value;
}
};
#endif //PORYGONLANG_EVALVALUE_HPP