-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeclaration.java
82 lines (72 loc) · 2.29 KB
/
Declaration.java
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
import java.util.ArrayList;
import java.util.Stack;
//import com.modeliosoft.modelio.javadesigner.annotations.objid;
public class Declaration implements Constante {
public String identLu;
public type typeLu;
public YVM yvm;
public YVMasm asm;
public ArrayList<type> paramType;
public Stack<type> typeStack;
public Stack<String> nomStack;
public type typeFonct;
public Declaration (YVM yvm, YVMasm asm){
this.yvm = yvm;
this.asm = asm;
paramType = new ArrayList<type>();
typeStack = new Stack<type>();
nomStack = new Stack<String>();
}
public void placerVariable(String nom, int val, type type, TabIdent tab) {
if (tab.existeIdentLocaux(nom)){
if(tab.chercheIdentLocaux(nom).estVariable()){
System.out.println("ERROR : IDENT ALREADY EXISTS");
}
else{System.out.println("ERROR : Attention vous affectez une constante.");}
}
else {
tab.rangeIdentLocaux(nom, new IdVar(type, val));
//yvm.istore(val); asm.istore(val);
}
}
public void placerConst(String nom, int val, type type, TabIdent tab) {
if (tab.existeIdentLocaux(nom)){
System.out.println("ERROR : IDENT ALREADY EXISTS");
} else {
tab.rangeIdentLocaux(nom, new IdConst(type, val));
//yvm.iconst(val); asm.iconst(val);
}
}
public void placerFonct(TabIdent tab){
if (tab.existeIdentGlobaux(identLu)){
System.out.println("ERREUR: Nom fonction déjà utilisé.");
}
else {
tab.rangeIdentGlobaux(identLu, new IdFonct(type.FONCTION, typeFonct, paramType));
}
yvm.ecrireFonction(identLu);
asm.ecrireFonction(identLu);
}
public void placerParam(TabIdent tab){
while (!typeStack.isEmpty()){
if(tab.existeIdentLocaux(nomStack.peek())){
nomStack.pop();
typeStack.pop();
System.out.println("ERREUR: Les paramètres doivent avoir des noms différents.");
}
else {
tab.rangeIdentLocaux(nomStack.pop(), new IdParam(typeStack.pop(), tab.getIterateurParametre()));
}
}
}
/* public void empileType(String s) {
switch(s){
case "BOOLEEN":
this.typeStack.push(type.BOOL);
break;
case "ENTIER":
this.typeStack.push(type.ENTIER);
break;
}
}*/
}