4 /** This class represents a reduce action within the parse table.
5 * The action simply stores the production that it reduces with and
6 * responds to queries about its type.
8 * @version last updated: 11/25/95
11 public class reduce_action extends parse_action {
13 /*-----------------------------------------------------------*/
14 /*--- Constructor(s) ----------------------------------------*/
15 /*-----------------------------------------------------------*/
17 /** Simple constructor.
18 * @param prod the production this action reduces with.
20 public reduce_action(production prod ) throws internal_error
24 throw new internal_error(
25 "Attempt to create a reduce_action with a null production");
30 /*-----------------------------------------------------------*/
31 /*--- (Access to) Instance Variables ------------------------*/
32 /*-----------------------------------------------------------*/
34 /** The production we reduce with. */
35 protected production _reduce_with;
37 /** The production we reduce with. */
38 public production reduce_with() {return _reduce_with;}
40 /*-----------------------------------------------------------*/
41 /*--- General Methods ---------------------------------------*/
42 /*-----------------------------------------------------------*/
44 /** Quick access to type of action. */
45 public int kind() {return REDUCE;}
47 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
50 public boolean equals(reduce_action other)
52 return other != null && other.reduce_with() == reduce_with();
55 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
57 /** Generic equality test. */
58 public boolean equals(Object other)
60 if (other instanceof reduce_action)
61 return equals((reduce_action)other);
66 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
68 /** Compute a hash code. */
71 /* use the hash code of the production we are reducing with */
72 return reduce_with().hashCode();
76 /** Convert to string. */
77 public String toString()
79 return "REDUCE(with prod " + reduce_with().index() + ")";
82 /*-----------------------------------------------------------*/