-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgramNode.java
More file actions
67 lines (54 loc) · 1.69 KB
/
ProgramNode.java
File metadata and controls
67 lines (54 loc) · 1.69 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
package icsi311;
import java.util.LinkedList;
public class ProgramNode {
private LinkedList<BlockNode> BEGIN = new LinkedList<BlockNode>();
private LinkedList<BlockNode> END = new LinkedList<BlockNode>();
private LinkedList<FunctionDefinitionNode> functions = new LinkedList<FunctionDefinitionNode>();
private LinkedList<BlockNode> OTHER = new LinkedList<BlockNode>();
public void addBegin(BlockNode b) throws Exception{
if(!functions.isEmpty())
throw new Exception("Not a valid program structure! Must define a function after a BEGIN Block!");
BEGIN.add(b);
}
public void addEnd(BlockNode b){
END.add(b);
}
public void addFunction(FunctionDefinitionNode f){
functions.add(f);
}
public void addOther(BlockNode b){
OTHER.add(b);
}
public boolean beginIsEmpty(){
if(BEGIN.isEmpty())
return true;
return false;
}
public boolean functionsIsEmpty(){
if(functions.isEmpty())
return true;
return false;
}
public String toString(){
try{
return "BEGIN{" + betterParams(BEGIN.toString()) + "}\n" + betterParams(OTHER.toString()) + "\nEND{" + betterParams(END.toString()) + "}\nFunctions:\n" + betterParams(functions.toString());}
catch(Exception e){
return "toString not valid";
}
}
public LinkedList<FunctionDefinitionNode> getFuncs(){
return functions;
}
public String betterParams(String s){
return s.substring(1,s.length()-1);
}
public LinkedList<BlockNode> getBegin(){
return BEGIN;
}
public LinkedList<BlockNode> getEnd(){
return END;
}
public LinkedList<BlockNode> getOther(){
return OTHER;
}
}