-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathParsenode.h
82 lines (66 loc) · 1.69 KB
/
Parsenode.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
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
#ifndef PARSENODE_H
#define PARSENODE_H
#include "Context.h"
#include <cmath>
#include <iostream>
#include <memory>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
//!!! Maybe turn off warnings in this file wrt using double as bool and comparing double ==
class Parsenode {
public:
Parsenode() = default;
virtual ~Parsenode() = default;
Parsenode(const Parsenode&) = delete;
Parsenode& operator=(const Parsenode&) = delete;
Parsenode(Parsenode&&) = delete;
Parsenode& operator=(Parsenode&&) = delete;
virtual double eval(const Context & cc) = 0;
private:
static bool lastconstruct;
};
using ParsenodePtr = std::unique_ptr<Parsenode>;
class Ternopnode : public Parsenode {
public:
Ternopnode(ParsenodePtr _p, ParsenodePtr _t, ParsenodePtr _f);
double eval(const Context& cc) override;
private:
ParsenodePtr pred;
ParsenodePtr trueval;
ParsenodePtr falseval;
};
class Binopnode : public Parsenode {
public:
Binopnode(char _o, ParsenodePtr _l, ParsenodePtr _r);
double eval(const Context& cc) override;
private:
char op;
ParsenodePtr left;
ParsenodePtr right;
};
class Unopnode : public Parsenode {
public:
Unopnode(char _o, ParsenodePtr _c);
double eval(const Context& cc) override;
private:
char op;
ParsenodePtr child;
};
class Numnode : public Parsenode {
public:
explicit Numnode(double _v);
double eval(const Context& cc) override;
private:
double val;
};
class Idnode : public Parsenode {
public:
Idnode(std::string _n, std::vector<ParsenodePtr> _p);
double eval(const Context& cc) override;
private:
std::string name;
std::vector<ParsenodePtr> pp;
};
#endif