-
Notifications
You must be signed in to change notification settings - Fork 0
/
ast.h
57 lines (51 loc) · 1.41 KB
/
ast.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
/*
* @name ast.h
* @description Hierachy of AST
* @date 03/31/2020
* @author Lrq
* |---------|
* | AstNode |
* |---------|
* |
* |
* |--------------|
* | Expression |
* |--------------|
* | |
* | |
* | |
* |-------| |-------|
* | BinOp | | Num |
* |-------| |-------|
*/
#ifndef _AST_H
#define _AST_H
#include <iostream>
#include "visitor.h"
class AstNode{
public:
AstNode(){ }
virtual double accept( Visitor* v ) = 0;
};
class Expression : public AstNode{
public:
std::string type;
Expression* left;
Expression* right;
Expression(){ }
Expression(std::string type): type(type) { }
Expression(std::string type, Expression* left, Expression* right) : type(type), left(left), right(right) { }
};
class BinOp : public Expression{
public:
double accept( Visitor* v) {return v->visit(this);}
BinOp( std::string type, Expression* left, Expression* right ) :
Expression(type, left, right){ }
};
class Num : public Expression{
public:
double val;
double accept( Visitor* v){ return v->visit(this); }
Num( std::string type, double val ): Expression(type), val(val){}
};
#endif