-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariableReferenceNode.java
More file actions
62 lines (56 loc) · 1.59 KB
/
VariableReferenceNode.java
File metadata and controls
62 lines (56 loc) · 1.59 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
package icsi311;
import java.util.Optional;
public class VariableReferenceNode extends Node{
private String name;
private Optional<Node> Index = Optional.empty();
private Optional<Node> Index2 = Optional.empty();
public VariableReferenceNode(String n){
name = n;
Index = Optional.empty();
}
public VariableReferenceNode(String n, Optional<Node> o){
name = n;
Index = o;
}
public VariableReferenceNode(String n, Optional<Node> o, Optional<Node> o2){
name = n;
Index = o;
Index2 = o2;
}
public String toString(){
if (!Index.isEmpty() && Index2.isEmpty())
return name + "[\"" + Index.get().toString() + "\"]";
else if (!Index2.isEmpty())
return "Variable(NAME=" + name + ", VALUE=(" + Index.get().toString() + ", " + Index2.get().toString() + "))";
else
return name;
}
public String getName(){
return name;
}
public boolean isNum(String s){
try{
float f = Float.parseFloat(s);
return true;
}
catch(Exception e){
return false;}
}
public boolean hasValue(){
if(!Index.isEmpty() || !Index2.isEmpty())
return true;
return false;
}
public boolean isArray(){
if(!Index.isEmpty())
return true;
return false;
}
public String fixNum(String s){
return s.substring(0,s.length()-2);
}
public String getIndex(){
return Index.get().toString();
}
public Node getIndexNode(){ return Index.get();}
}