-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-ast.cpp
More file actions
36 lines (30 loc) · 1.43 KB
/
test-ast.cpp
File metadata and controls
36 lines (30 loc) · 1.43 KB
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
#include <iostream>
#include <vector>
#include <string>
#include "ast.hpp"
//#define CONCAT(a,b) (a)+std::string("_")+(b)
//#define CONCAT(a,b) (a)+"_"+(b)
std::string MakeName(std::string parent_name, const std::string suffix) {
std::string child_name = parent_name + std::string("_") + suffix;
return child_name;
}
int main() {
AST tree;
tree.root = new BlockNode("root");
BlockNode* root = dynamic_cast<BlockNode*>(tree.root);
root->childs.push_back(new BinaryNode(MakeName("root", "0"), "Assignment"));
// root->childs.push_back(new IfNode(MakeName("root", "1")));
BinaryNode* root_0 = dynamic_cast<BinaryNode*>(root->childs[0]);
root_0->left = new LiteralNode(MakeName(root_0->name, "left"), "Identifier", "pi");
// root_0->right = new LiteralNode(MakeName(root_0->name, "right"), "Identifier", "pi2");
root_0->right = new BinaryNode(MakeName(root_0->name, "right"), "TIMES");
BinaryNode* root_0_right = dynamic_cast<BinaryNode*>(root_0->right);
root_0_right->left = new LiteralNode(MakeName(root_0_right->name, "left"), "Identifier", "a");
root_0_right->right = new LiteralNode(MakeName(root_0_right->name, "right"), "Identifier", "b");
//
// IfNode* root_1 = dynamic_cast<IfNode*>(root->childs[1]);
// root_1->condition = new BinaryNode(MakeName(root_1->name, "cond"), "GT");
// root_1->if_block = new BlockNode(MakeName(root_1->name, "if"));
tree.Print();
return 0;
}