-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ast.h
121 lines (100 loc) · 3.11 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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#pragma once
#include "Macro11Common.h"
#include <vector>
namespace AST
{
class AstVisitor;
class Node
{
public:
virtual void Accept(AstVisitor* visitor);
virtual ~Node() {}
};
class LabelNode : public Node
{
public:
LabelNode(const char* name);
virtual void Accept(AstVisitor* visitor);
virtual ~LabelNode() override;
public:
const char* Name;
LabelNode* Next;
};
class OperandNode : public Node
{
public:
OperandNode(const OperandType optype, const int value, const AddressingType addrType, const char* labelName = nullptr, const int indexedOffset = 0);
virtual void Accept(AstVisitor* visitor) override;
public:
OperandType OpType;
int Value;
AddressingType AddrType;
int IndexedOffset;
const char* LabelName;
};
class CommandNode : public Node
{
public:
CommandNode(const int opcode, const int line);
virtual ~CommandNode() override;
virtual void Accept(AstVisitor* visitor) override;
inline void SetInstructionNumber(const int number) const
{
InstructionNumber = number;
}
public:
const int Opcode;
const int Line;
mutable int InstructionNumber;
CommandNode* Next;
LabelNode* Labels;
};
class OneOperandCommandNode : public CommandNode
{
public:
OneOperandCommandNode(const int opcode, OperandNode* first, const int line);
virtual ~OneOperandCommandNode() override;
virtual void Accept(AstVisitor* visitor) override;
public:
OperandNode* First;
};
class DoubleOperandCommandNode : public CommandNode
{
public:
DoubleOperandCommandNode(const int opcide, OperandNode* first, OperandNode* second, const int line);
virtual ~DoubleOperandCommandNode() override;
virtual void Accept(AstVisitor* visitor) override;
public:
OperandNode* First;
OperandNode* Second;
};
class ProgramNode : public Node
{
public:
ProgramNode(CommandNode* commands);
virtual ~ProgramNode() override;
virtual void Accept(AstVisitor* visitor) override;
public:
CommandNode* Commands;
};
class AstVisitor
{
public:
virtual void Visit(Node* node) {}
virtual void Visit(LabelNode* node) {}
virtual void Visit(OperandNode* node) {}
virtual void Visit(CommandNode* node) {}
virtual void Visit(OneOperandCommandNode* node) {}
virtual void Visit(DoubleOperandCommandNode* node) {}
virtual void Visit(ProgramNode* node) {}
};
class AbstractSyntaxTree
{
public:
AbstractSyntaxTree();
void SetProgram(ProgramNode* node);
void Accept(AstVisitor* visitor);
private:
ProgramNode* Program;
};
}