-
Notifications
You must be signed in to change notification settings - Fork 6
/
ast_functions.hpp
executable file
·83 lines (67 loc) · 1.46 KB
/
ast_functions.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef ast_functions_hpp
#define ast_functions_hpp
#include "ast_expression.hpp"
#include <cmath>
class Function
: public Expression
{
private:
ExpressionPtr arg;
protected:
Function(ExpressionPtr _arg)
: arg(_arg)
{}
public:
virtual ~Function()
{
delete arg;
}
virtual const char * getFunction() const =0;
ExpressionPtr getArg() const
{ return arg; }
virtual void print(std::ostream &dst) const override
{
dst<<getFunction()<<"( ";
arg->print(dst);
dst<<" )";
}
virtual double evaluate(
const std::map<std::string,double> &bindings
) const override
{
// NOTE : This should be implemented by the inheriting function nodes, e.g. LogFunction
throw std::runtime_error("FunctionOperator::evaluate is not implemented.");
}
};
class LogFunction
: public Function
{
public:
LogFunction(ExpressionPtr _arg)
: Function(_arg)
{}
virtual const char *getFunction() const
{ return "log"; }
// TODO-E : Override evaluate, and implement it
};
class ExpFunction
: public Function
{
public:
ExpFunction(ExpressionPtr _arg)
: Function(_arg)
{}
virtual const char *getFunction() const
{ return "exp"; }
};
class SqrtFunction
: public Function
{
public:
SqrtFunction(ExpressionPtr _arg)
: Function(_arg)
{}
virtual const char *getFunction() const
{ return "sqrt"; }
};
#endif