01: package java_cup;
02:
03: /** This class represents a part of a production which is a symbol (terminal
04: * or non terminal). This simply maintains a reference to the symbol in
05: * question.
06: *
07: * @see java_cup.production
08: * @version last updated: 11/25/95
09: * @author Scott Hudson
10: */
11: public class symbol_part extends production_part {
12:
13: /*-----------------------------------------------------------*/
14: /*--- Constructor(s) ----------------------------------------*/
15: /*-----------------------------------------------------------*/
16:
17: /** Full constructor.
18: * @param sym the symbol that this part is made up of.
19: * @param lab an optional label string for the part.
20: */
21: public symbol_part(symbol sym, String lab) throws internal_error {
22: super (lab);
23:
24: if (sym == null)
25: throw new internal_error(
26: "Attempt to construct a symbol_part with a null symbol");
27: _the_symbol = sym;
28: }
29:
30: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
31:
32: /** Constructor with no label.
33: * @param sym the symbol that this part is made up of.
34: */
35: public symbol_part(symbol sym) throws internal_error {
36: this (sym, null);
37: }
38:
39: /*-----------------------------------------------------------*/
40: /*--- (Access to) Instance Variables ------------------------*/
41: /*-----------------------------------------------------------*/
42:
43: /** The symbol that this part is made up of. */
44: protected symbol _the_symbol;
45:
46: /** The symbol that this part is made up of. */
47: public symbol the_symbol() {
48: return _the_symbol;
49: }
50:
51: /*-----------------------------------------------------------*/
52: /*--- General Methods ---------------------------------------*/
53: /*-----------------------------------------------------------*/
54:
55: /** Respond that we are not an action part. */
56: public boolean is_action() {
57: return false;
58: }
59:
60: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
61:
62: /** Equality comparison. */
63: public boolean equals(symbol_part other) {
64: return other != null && super .equals(other)
65: && the_symbol().equals(other.the_symbol());
66: }
67:
68: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
69:
70: /** Generic equality comparison. */
71: public boolean equals(Object other) {
72: if (!(other instanceof symbol_part))
73: return false;
74: else
75: return equals((symbol_part) other);
76: }
77:
78: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
79:
80: /** Produce a hash code. */
81: public int hashCode() {
82: return super .hashCode()
83: ^ (the_symbol() == null ? 0 : the_symbol().hashCode());
84: }
85:
86: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
87:
88: /** Convert to a string. */
89: public String toString() {
90: if (the_symbol() != null)
91: return super .toString() + the_symbol();
92: else
93: return super .toString() + "$$MISSING-SYMBOL$$";
94: }
95:
96: /*-----------------------------------------------------------*/
97:
98: }
|