-
Notifications
You must be signed in to change notification settings - Fork 0
/
scmath.h
37 lines (35 loc) · 955 Bytes
/
scmath.h
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
#pragma once
#include "scmath/ast.h"
#include "scmath/nodetype.h"
#include "scmath/output.h"
class scmath
{
public:
static void Simplificate(BasicNode *&now);
static BasicNode* Derivation(BasicNode* now, const string &value);
static BasicNode* toAST(string s)
{
return ast::ToAST(s);
}
static BasicNode* eval(BasicNode *tree)
{
return copyHelp::copyNode(tree)->eval();
}
static double getVal(BasicNode *tree)
{
if(tree->getType() == Num)
return ((NumNode*)tree)->getNum();
else
throw string("不是数字右值不可调用GetVal");
}
static void output(BasicNode *tree)
{
output::outputAST(tree);
}
static double caluExp(BasicNode* f,string name,double val)
{
record::globalScope.variableList[name]->setVal(new NumNode(val));
BasicNode* result=scmath::eval(f);
return scmath::getVal(result);
}
};