-
Notifications
You must be signed in to change notification settings - Fork 0
/
TableSymboles.java
37 lines (30 loc) · 1.1 KB
/
TableSymboles.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
import java.util.*;
public class TableSymboles {
// A hash table to recall global variables that have been declared so far
// A variable is represented by its name.
// We assume that named are not reused, i.e. we can not have a variable x that
// is both an int and a float.
private HashMap<String, AdresseType> table = new HashMap<String, AdresseType>();
public AdresseType getAdresseType(String s) {
return table.get(s);
}
// n is a short hand for next free address :)
private int n = 0;
// returns the next available address that is available to store a global
// variable (initially 0).
public Integer getSize() {
return n;
}
public void putVar(String s, String t) {
if (table.get(s) != null)
System.err.println("Erreur : Variable \"" + s + "\" de type " + table.get(s).type + " déjà définie");
else {
AdresseType at = new AdresseType(n, t);
table.put(s, at);
n += AdresseType.getSize(t);
}
}
public String toString() {
return table.toString();
}
}