3 /** This class represents one part (either a symbol or an action) of a
4 * production. In this base class it contains only an optional label
5 * string that the user can use to refer to the part within actions.<p>
7 * This is an abstract class.
9 * @see java_cup.production
10 * @version last updated: 11/25/95
11 * @author Scott Hudson
13 public abstract class production_part {
15 /*-----------------------------------------------------------*/
16 /*--- Constructor(s) ----------------------------------------*/
17 /*-----------------------------------------------------------*/
19 /** Simple constructor. */
20 public production_part(String lab)
25 /*-----------------------------------------------------------*/
26 /*--- (Access to) Instance Variables ------------------------*/
27 /*-----------------------------------------------------------*/
29 /** Optional label for referring to the part within an action (null for
32 protected String _label;
34 /** Optional label for referring to the part within an action (null for
37 public String label() {return _label;}
39 /*-----------------------------------------------------------*/
40 /*--- General Methods ---------------------------------------*/
41 /*-----------------------------------------------------------*/
43 /** Indicate if this is an action (rather than a symbol). Here in the
44 * base class, we don't this know yet, so its an abstract method.
46 public abstract boolean is_action();
48 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
50 /** Equality comparison. */
51 public boolean equals(production_part other)
53 if (other == null) return false;
55 /* compare the labels */
57 return label().equals(other.label());
59 return other.label() == null;
62 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
64 /** Generic equality comparison. */
65 public boolean equals(Object other)
67 if (!(other instanceof production_part))
70 return equals((production_part)other);
73 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
75 /** Produce a hash code. */
78 return label()==null ? 0 : label().hashCode();
81 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
83 /** Convert to a string. */
84 public String toString()
92 /*-----------------------------------------------------------*/