KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ro > infoiasi > donald > compiler > cfg > Symbol


1 package ro.infoiasi.donald.compiler.cfg;
2
3 /** A symbol of the grammar, terminal or nonterminal */
4 public abstract class Symbol {
5     protected String JavaDoc name;
6     protected int index;
7     protected String JavaDoc type;
8     
9     public Symbol(String JavaDoc name, int index, String JavaDoc type) {
10         this.name = name;
11         this.index = index;
12         this.type = type;
13     }
14
15     public Symbol(String JavaDoc name, int index) {
16         this(name, index, null);
17     }
18     
19     public String JavaDoc getName() {
20         return name;
21     }
22     
23     public int getIndex() {
24         return index;
25     }
26
27     public String JavaDoc 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 JavaDoc o) {
37         return (o instanceof Symbol &&
38             name.equals(((Symbol)o).name) &&
39             index == ((Symbol)o).index);
40     }
41
42     public int hashCode() {
43         return isTerminal()? -index: +index;
44     }
45
46     public String JavaDoc toString() {
47         return getName();
48     }
49
50     public abstract boolean isTerminal();
51 }
52
Popular Tags