3 /** This class represents a part of a production which is a symbol (terminal
4 * or non terminal). This simply maintains a reference to the symbol in
7 * @see java_cup.production
8 * @version last updated: 11/25/95
11 public class symbol_part extends production_part {
13 /*-----------------------------------------------------------*/
14 /*--- Constructor(s) ----------------------------------------*/
15 /*-----------------------------------------------------------*/
18 * @param sym the symbol that this part is made up of.
19 * @param lab an optional label string for the part.
21 public symbol_part(symbol sym, String lab) throws internal_error
26 throw new internal_error(
27 "Attempt to construct a symbol_part with a null symbol");
31 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
33 /** Constructor with no label.
34 * @param sym the symbol that this part is made up of.
36 public symbol_part(symbol sym) throws internal_error
41 /*-----------------------------------------------------------*/
42 /*--- (Access to) Instance Variables ------------------------*/
43 /*-----------------------------------------------------------*/
45 /** The symbol that this part is made up of. */
46 protected symbol _the_symbol;
48 /** The symbol that this part is made up of. */
49 public symbol the_symbol() {return _the_symbol;}
51 /*-----------------------------------------------------------*/
52 /*--- General Methods ---------------------------------------*/
53 /*-----------------------------------------------------------*/
55 /** Respond that we are not an action part. */
56 public boolean is_action() { return false; }
58 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
60 /** Equality comparison. */
61 public boolean equals(symbol_part other)
63 return other != null && super.equals(other) &&
64 the_symbol().equals(other.the_symbol());
67 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
69 /** Generic equality comparison. */
70 public boolean equals(Object other)
72 if (!(other instanceof symbol_part))
75 return equals((symbol_part)other);
78 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
80 /** Produce a hash code. */
83 return super.hashCode() ^
84 (the_symbol()==null ? 0 : the_symbol().hashCode());
87 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
89 /** Convert to a string. */
90 public String toString()
92 if (the_symbol() != null)
93 return super.toString() + the_symbol();
95 return super.toString() + "$$MISSING-SYMBOL$$";
98 /*-----------------------------------------------------------*/