-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.h
63 lines (53 loc) · 1.31 KB
/
Node.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
#pragma once
#include "Token.h"
#include <unordered_map>
#include <string>
using namespace std;
class Node{
public:
enum class Id{
error,
program,
func_decl,
statement_list,
statement,
basic_statement,
if_statement,
while_statement,
var_decl,
assignment_like,
expression,
type_name,
func_name,
var_name,
func_call,
return_statement,
built_in_func,
built_in_procedure,
literal,
uint_literal,
string_literal,
};
Id id = Id::error;
string name;
Token token;
vector<Node> leaves;
Node(){}
Node(const string&);
Node(const string&, const Token&);
void add_leaf(const Node&);
Token get_first_token() const;
string to_string(const int indent = 0) const;
int size() const;
friend ostream& operator<<(ostream& os, const Node& node){
os << node.to_string();
return os;
}
Node& operator[](const int n);
vector<Node>::const_iterator begin() const noexcept;
vector<Node>::const_iterator end() const noexcept;
// 文字列をNodeのIDに変換
static unordered_map<string, Id> str_to_id;
// NodeのIDを文字列に変換
static unordered_map<Id, string> id_to_str;
};