-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariable.java
More file actions
53 lines (42 loc) · 1.26 KB
/
Copy pathVariable.java
File metadata and controls
53 lines (42 loc) · 1.26 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
package dendron.tree;
import dendron.machine.Machine;
import java.util.LinkedList;
import java.util.List;
/**
* @author Liang,Yu(yxl5521)
*/
public class Variable implements ExpressionNode{
private String name;
private List<Machine.Instruction> list;
/**
* Set the name of this new Variable.
* @param name the name of this variable
*/
public Variable(String name){
this.name=name;
this.list=new LinkedList<>();
}
/**
* Print on standard output the Variable's name
*/
public void infixDisplay(){
System.out.print(name);
}
/**
* Evaluate a variable by fetching its values.
* @param symTab symbol table, if needed, to fetch variable values
* @return this variable's current value in the symbol table
*/
public int evaluate(java.util.Map<String,Integer> symTab){
return symTab.get(name);
}
/**
* Emit a LOAD instruction that pushes the Variable's value onto the stack.
* @return a list containing a single LOAD instruction
*/
public java.util.List<Machine.Instruction> emit(){
Machine.Load load = new Machine.Load(name);
list.add(load);
return list;
}
}