5 public class SymbolTable {
7 private Hashtable table;
8 private SymbolTable parent;
9 private HashSet valueset;
11 private Vector<SymbolTable> parentIFs;
13 public SymbolTable() {
14 table = new Hashtable();
15 valueset = new HashSet();
17 this.parentIFs = null;
20 public SymbolTable(SymbolTable parent) {
21 table = new Hashtable();
25 public void add(Descriptor d) {
26 add(d.getSymbol(), d);
29 public void add(String name, Descriptor d) {
30 if (!table.containsKey(name))
31 table.put(name, new HashSet());
32 HashSet hs=(HashSet)table.get(name);
37 public Set getSet(String name) {
41 private HashSet getPSet(String name) {
44 hs=parent.getPSet(name);
47 if(this.parentIFs != null) {
48 for(int i = 0; i < this.parentIFs.size(); i++) {
49 if(this.parentIFs.elementAt(i).contains(name)) {
50 hs.addAll((HashSet)(this.parentIFs.elementAt(i).getPSet(name)));
54 if (table.containsKey(name)) {
55 hs.addAll((HashSet)table.get(name));
60 public Set getSetFromSameScope(String name) {
61 return getPSetFromSameScope(name);
64 private HashSet getPSetFromSameScope(String name) {
65 if (table.containsKey(name)) {
66 HashSet hs=(HashSet)table.get(name);
72 public Descriptor get(String name) {
73 Descriptor d = getFromSameScope(name);
78 if((d == null) && (this.parentIFs != null)) {
79 for(int i = 0; i < this.parentIFs.size(); i++) {
80 d = this.parentIFs.elementAt(i).get(name);
90 public Descriptor getFromSameScope(String name) {
91 if (table.containsKey(name)) {
92 HashSet hs=(HashSet) table.get(name);
93 return (Descriptor) hs.iterator().next();
99 public Enumeration getNames() {
103 public Iterator getNamesIterator() {
104 return table.keySet().iterator();
107 public Set getValueSet() {
111 public Iterator getDescriptorsIterator() {
112 return getValueSet().iterator();
115 public Set getAllValueSet() {
118 hs=(HashSet) parent.getAllValueSet();
121 if (this.parentIFs != null) {
122 for(int i = 0; i < this.parentIFs.size(); i++) {
123 hs.addAll(this.parentIFs.elementAt(i).getAllValueSet());
130 public Iterator getAllDescriptorsIterator() {
131 return getAllValueSet().iterator();
134 public boolean contains(String name) {
135 return (get(name) != null);
138 public SymbolTable getParent() {
142 public void setParent(SymbolTable parent) {
143 this.parent = parent;
146 public Vector<SymbolTable> getParentIFs() {
147 return this.parentIFs;
150 public void addParentIF(SymbolTable parentif) {
151 if(this.parentIFs == null) {
152 this.parentIFs = new Vector<SymbolTable>();
154 this.parentIFs.addElement(parentif);
158 public String toString() {
159 return "ST: " + table.toString();