01: /*
02: * Symbol.java
03: *
04: * Copyright 1997 Massachusetts Institute of Technology.
05: * All Rights Reserved.
06: *
07: * Author: Ora Lassila
08: *
09: * $Id: Symbol.java,v 1.2 1998/01/22 13:09:34 bmahe Exp $
10: */
11:
12: package org.w3c.tools.sexpr;
13:
14: import java.io.PrintStream;
15: import java.util.Dictionary;
16:
17: /**
18: * Base class for lisp-like symbols.
19: */
20: public class Symbol implements SExpr {
21:
22: private String name;
23:
24: /**
25: * Creates a symbol and potentially interns it in a symbol table.
26: */
27: public static Symbol makeSymbol(String name, Dictionary symbols) {
28: if (symbols == null)
29: return new Symbol(name);
30: else {
31: String key = name.toLowerCase();
32: Symbol s = (Symbol) symbols.get(key);
33: if (s == null) {
34: s = new Symbol(name);
35: symbols.put(key, s);
36: }
37: return s;
38: }
39: }
40:
41: protected Symbol(String name) {
42: this .name = name;
43: }
44:
45: public String toString() {
46: return name;
47: }
48:
49: public void printExpr(PrintStream out) {
50: out.print(toString());
51: }
52:
53: }
|