01: package java_cup;
02:
03: /** This class serves as the base class for entries in a parse action table.
04: * Full entries will either be SHIFT(state_num), REDUCE(production), NONASSOC,
05: * or ERROR. Objects of this base class will default to ERROR, while
06: * the other three types will be represented by subclasses.
07: *
08: * @see java_cup.reduce_action
09: * @see java_cup.shift_action
10: * @version last updated: 7/2/96
11: * @author Frank Flannery
12: */
13:
14: public class parse_action {
15:
16: /*-----------------------------------------------------------*/
17: /*--- Constructor(s) ----------------------------------------*/
18: /*-----------------------------------------------------------*/
19:
20: /** Simple constructor. */
21: public parse_action() {
22: /* nothing to do in the base class */
23: }
24:
25: /*-----------------------------------------------------------*/
26: /*--- (Access to) Static (Class) Variables ------------------*/
27: /*-----------------------------------------------------------*/
28:
29: /** Constant for action type -- error action. */
30: public static final int ERROR = 0;
31:
32: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
33:
34: /** Constant for action type -- shift action. */
35: public static final int SHIFT = 1;
36:
37: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
38:
39: /** Constants for action type -- reduce action. */
40: public static final int REDUCE = 2;
41:
42: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
43:
44: /** Constants for action type -- reduce action. */
45: public static final int NONASSOC = 3;
46:
47: /*-----------------------------------------------------------*/
48: /*--- General Methods ---------------------------------------*/
49: /*-----------------------------------------------------------*/
50:
51: /** Quick access to the type -- base class defaults to error. */
52: public int kind() {
53: return ERROR;
54: }
55:
56: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
57:
58: /** Equality test. */
59: public boolean equals(parse_action other) {
60: /* we match all error actions */
61: return other != null && other.kind() == ERROR;
62: }
63:
64: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
65:
66: /** Generic equality test. */
67: public boolean equals(Object other) {
68: if (other instanceof parse_action)
69: return equals((parse_action) other);
70: else
71: return false;
72: }
73:
74: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
75:
76: /** Compute a hash code. */
77: public int hashCode() {
78: /* all objects of this class hash together */
79: return 0xCafe123;
80: }
81:
82: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
83:
84: /** Convert to string. */
85: public String toString() {
86: return "ERROR";
87: }
88:
89: /*-----------------------------------------------------------*/
90: }
|