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