source: trunk/yao/share/antlr-2.7.7/examples/java/pascal/Scope.java @ 1

Last change on this file since 1 was 1, checked in by lnalod, 15 years ago

Initial import of YAO sources

File size: 733 bytes
Line 
1import java.util.Hashtable;
2import java.util.Enumeration;
3import java.io.*;
4
5/** A set of symbols (type defs and/or variables) */
6public class Scope implements Serializable {
7        protected Scope parent;
8
9        protected Hashtable symbols = new Hashtable();
10
11        public Scope(Scope parent) {
12                this.parent = parent;
13        }
14
15        public void addSymbol(Symbol s) {
16                if ( s.getName() != null ) {
17                        symbols.put(s.getName(), s);
18                }
19        }
20
21        /** Look up name in this scope or parent */
22        public Symbol resolve(String name) {
23                Symbol s = (Symbol)symbols.get(name);
24                if ( s==null ) {
25                        return parent.resolve(name);
26                }
27                return s;
28        }
29
30        public String toString() {
31                return "Scope=["+symbols+"]"+(parent==null?"<root>":"");
32        }
33}
Note: See TracBrowser for help on using the repository browser.