| 1 package ro.infoiasi.donald.compiler.cfg; 2 3 4 public abstract class Symbol { 5 protected String name; 6 protected int index; 7 protected String type; 8 9 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 32 void setIndex(int index) { 33 this.index = index; 34 } 35 36 public boolean equals(Object 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 toString() { 47 return getName(); 48 } 49 50 public abstract boolean isTerminal(); 51 } 52 | Popular Tags |