static class Symbol implements CharSequence, Comparable { S text; MasterSymbol master; *() {} *(S *text, bool dummy) {} // weird signature to prevent accidental calling *(S *text, MasterSymbol *master) {} bool isMaster() { ret master == this; } public int hashCode() { ret main.hashCode(lowerCase()); } toString { ret text; } S lowerCase() { ret master.lowerCase; } public bool equals(O o) { if (!(o instanceof Symbol)) false; bool result = o instanceof Symbol && master == o/Symbol.master; ifdef symbol_debug print("Symbol.equals: " + this + " vs " + o + " => " + result); endifdef ret result; } public int length() { ret text.length(); } public char charAt(int index) { ret text.charAt(index); } public CharSequence subSequence(int start, int end) { ret text.substring(start, end); } // This really has to be correct for TreeMap // equals() <=> compareTo() == 0 or at least // equals() => compareTo() == 0. public int compareTo(Symbol s) { ret lowerCase().compareTo(s.lowerCase()); } } static class MasterSymbol extends Symbol { S lowerCase; bool dollarVar; *() {} *(S *text, bool dummy) { master = this; lowerCase = lower(text); dollarVar = isDollarVar(lowerCase); } }