01: package ro.infoiasi.donald.compiler.cfg;
02:
03: /** A symbol of the grammar, terminal or nonterminal */
04: public abstract class Symbol {
05: protected String name;
06: protected int index;
07: protected String type;
08:
09: public Symbol(String name, int index, String type) {
10: this .name = name;
11: this .index = index;
12: this .type = type;
13: }
14:
15: public Symbol(String name, int index) {
16: this (name, index, null);
17: }
18:
19: public String getName() {
20: return name;
21: }
22:
23: public int getIndex() {
24: return index;
25: }
26:
27: public String getType() {
28: return type;
29: }
30:
31: /** Used to remove useless nonterminals (package access) */
32: void setIndex(int index) {
33: this .index = index;
34: }
35:
36: public boolean equals(Object o) {
37: return (o instanceof Symbol && name.equals(((Symbol) o).name) && index == ((Symbol) o).index);
38: }
39:
40: public int hashCode() {
41: return isTerminal() ? -index : +index;
42: }
43:
44: public String toString() {
45: return getName();
46: }
47:
48: public abstract boolean isTerminal();
49: }
|