01: package java_cup;
02:
03: /** This class represents one part (either a symbol or an action) of a
04: * production. In this base class it contains only an optional label
05: * string that the user can use to refer to the part within actions.<p>
06: *
07: * This is an abstract class.
08: *
09: * @see java_cup.production
10: * @version last updated: 11/25/95
11: * @author Scott Hudson
12: */
13: public abstract class production_part {
14:
15: /*-----------------------------------------------------------*/
16: /*--- Constructor(s) ----------------------------------------*/
17: /*-----------------------------------------------------------*/
18:
19: /** Simple constructor. */
20: public production_part(String lab) {
21: _label = lab;
22: }
23:
24: /*-----------------------------------------------------------*/
25: /*--- (Access to) Instance Variables ------------------------*/
26: /*-----------------------------------------------------------*/
27:
28: /** Optional label for referring to the part within an action (null for
29: * no label).
30: */
31: protected String _label;
32:
33: /** Optional label for referring to the part within an action (null for
34: * no label).
35: */
36: public String label() {
37: return _label;
38: }
39:
40: /*-----------------------------------------------------------*/
41: /*--- General Methods ---------------------------------------*/
42: /*-----------------------------------------------------------*/
43:
44: /** Indicate if this is an action (rather than a symbol). Here in the
45: * base class, we don't this know yet, so its an abstract method.
46: */
47: public abstract boolean is_action();
48:
49: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
50:
51: /** Equality comparison. */
52: public boolean equals(production_part other) {
53: if (other == null)
54: return false;
55:
56: /* compare the labels */
57: if (label() != null)
58: return label().equals(other.label());
59: else
60: return other.label() == null;
61: }
62:
63: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
64:
65: /** Generic equality comparison. */
66: public boolean equals(Object other) {
67: if (!(other instanceof production_part))
68: return false;
69: else
70: return equals((production_part) other);
71: }
72:
73: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
74:
75: /** Produce a hash code. */
76: public int hashCode() {
77: return label() == null ? 0 : label().hashCode();
78: }
79:
80: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
81:
82: /** Convert to a string. */
83: public String toString() {
84: if (label() != null)
85: return label() + ":";
86: else
87: return " ";
88: }
89:
90: /*-----------------------------------------------------------*/
91:
92: }
|