-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParseNode.java
More file actions
86 lines (72 loc) · 1.36 KB
/
ParseNode.java
File metadata and controls
86 lines (72 loc) · 1.36 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
import java.util.LinkedList;
public class ParseNode
{
NodeType type;
LinkedList<ParseNode> children;
String data;
ParseNode parent = null;
static int id;
int num;
boolean visited = false;
int tabs;
LinkedList<Integer> scopes;
boolean hasValue = false;
ParseNode thenBranch = null;
public ParseNode(NodeType type)
{
this.type = type;
children = new LinkedList<ParseNode>();
num = id++;
}
public ParseNode(NodeType type, String data)
{
this(type);
this.data = data;
}
//adds child and returns it
public ParseNode addChild(ParseNode node)
{
node.parent=this;
children.add(node);
return node;
}
public String toString()
{
String out = num+"|"+type+"|"+data;
for(ParseNode n : children)
out += "|" + n.num;
return out;
}
public String printPruned()
{
return num+"|"+type+"|"+data;
}
public String printWithTabs()
{
String tabStr = "";
for(int i = 0; i < tabs; i++)
tabStr+="\t";
return tabStr+num+"|"+type+"|"+data;
}
public String getTabs()
{
String tabStr = "";
for(int i = 0; i < tabs; i++)
tabStr+="\t";
return tabStr;
}
public String printWithScopes()
{
String out = "";
for(Integer i: scopes)
out+=" "+i;
return printWithTabs() + out;
}
public void addScopeToNode(Integer s)
{
if(scopes==null)
scopes = new LinkedList<Integer>();
if(!scopes.contains(s))
scopes.add(s);
}
}