-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathASTNode.cpp
More file actions
113 lines (81 loc) · 2.38 KB
/
Copy pathASTNode.cpp
File metadata and controls
113 lines (81 loc) · 2.38 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
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
/***************************************************************************
ASTNode.cpp
Base class for all the nodes in the AST.
-------------------
begin : Tue Jun 25 09:52:11 CEST 2002
copyright : (C) 2002 by Manuel Astudillo
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
***************************************************************************/
#include "ASTNode.h"
#include "Terminal.h"
ASTNode::~ASTNode () {
for (unsigned int i = 0; i < children.size (); i++) {
delete children[i];
}
}
void ASTNode::init (const Symbol *s, ASTNode *parent) {
m_line = s->line;
m_col = s->col;
if (s->type == NON_TERMINAL) {
m_image = s->symbol;
} else {
m_image = ((Terminal*) s)->image;
}
m_symbol = s->symbol;
m_parent = parent;
}
void ASTNode::setImage (wstring image) {
m_image = image;
}
void ASTNode::setSymbol (wstring symbol) {
m_symbol = symbol;
}
wstring ASTNode::getImage () {
return m_image;
}
wstring ASTNode::getSymbol () {
return m_symbol;
}
void ASTNode::addChild (ASTNode *child) {
children.push_back (child);
}
vector <ASTNode*> *ASTNode::getChildren () {
return &children;
}
ASTNode *ASTNode::getParent () {
return m_parent;
}
/*!
Sets the parent for this node.
/sa getParent()
*/
void ASTNode::setParent (ASTNode *parent) {
m_parent = parent;
}
void ASTNode::print (int tabs) {
integer i,j;
for (i=0; i < tabs; i++) {
wprintf (L" ");
}
wprintf (m_symbol.c_str());
wprintf (L":");
wprintf (m_image.c_str());
wprintf (L"\n");
for (i=0; i < children.size(); i++) {
if (children[i] != NULL) {
children[i]->print (tabs+1);
} else {
for (j=0; j < tabs+1; j++) {
wprintf (L" ");
}
wprintf(L"NULL\n");
}
}
}