-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathVariable.java
More file actions
51 lines (40 loc) · 1.18 KB
/
Copy pathVariable.java
File metadata and controls
51 lines (40 loc) · 1.18 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
/**
* Used for the variable declaration.
*/
public class Variable{
private Type type;
private int offset;
public Variable(){
this.reset();
}
public void reset(){
this.offset = -2;
}
/**
* Set the type used for the next variables declarations.
* @param t
*/
public void setType(Type t){
this.type = t;
}
/**
* Add a variable in the tab.
* It will have the type of the lastType variable.
* The offset is automagically managed.
* @param name name of the variable.
*/
public void addVar(String name){
Ident id = new Ident(true, name, this.type, this.offset);
this.offset -= 2;
Yaka.tabIdent.putIdent(name, id);
}
/**
* Add the ouvrePrinc -nbVar*2.
* Is called at the end of the variables declaration.
* It is the command used in the yvm to reserve space for the variables.
*/
public void end(){
// Yaka.yvm.add(new Instruction("ouvrePrinc", -(this.offset+2)));
Yaka.yvm.add(new Instruction("ouvreBloc", -(this.offset+2)));
}
}