01: package java_cup;
02:
03: /** This class represents a reduce action within the parse table.
04: * The action simply stores the production that it reduces with and
05: * responds to queries about its type.
06: *
07: * @version last updated: 11/25/95
08: * @author Scott Hudson
09: */
10: public class reduce_action extends parse_action {
11:
12: /*-----------------------------------------------------------*/
13: /*--- Constructor(s) ----------------------------------------*/
14: /*-----------------------------------------------------------*/
15:
16: /** Simple constructor.
17: * @param prod the production this action reduces with.
18: */
19: public reduce_action(production prod) throws internal_error {
20: /* sanity check */
21: if (prod == null)
22: throw new internal_error(
23: "Attempt to create a reduce_action with a null production");
24:
25: _reduce_with = prod;
26: }
27:
28: /*-----------------------------------------------------------*/
29: /*--- (Access to) Instance Variables ------------------------*/
30: /*-----------------------------------------------------------*/
31:
32: /** The production we reduce with. */
33: protected production _reduce_with;
34:
35: /** The production we reduce with. */
36: public production reduce_with() {
37: return _reduce_with;
38: }
39:
40: /*-----------------------------------------------------------*/
41: /*--- General Methods ---------------------------------------*/
42: /*-----------------------------------------------------------*/
43:
44: /** Quick access to type of action. */
45: public int kind() {
46: return REDUCE;
47: }
48:
49: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
50:
51: /** Equality test. */
52: public boolean equals(reduce_action other) {
53: return other != null && other.reduce_with() == reduce_with();
54: }
55:
56: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
57:
58: /** Generic equality test. */
59: public boolean equals(Object other) {
60: if (other instanceof reduce_action)
61: return equals((reduce_action) other);
62: else
63: return false;
64: }
65:
66: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
67:
68: /** Compute a hash code. */
69: public int hashCode() {
70: /* use the hash code of the production we are reducing with */
71: return reduce_with().hashCode();
72: }
73:
74: /** Convert to string. */
75: public String toString() {
76: return "REDUCE(with prod " + reduce_with().index() + ")";
77: }
78:
79: /*-----------------------------------------------------------*/
80:
81: }
|