01: package java_cup;
02:
03: /**
04: * This class represents a part of a production which contains an
05: * action. These are eventually eliminated from productions and converted
06: * to trailing actions by factoring out with a production that derives the
07: * empty string (and ends with this action).
08: *
09: * @see java_cup.production
10: * @version last update: 11/25/95
11: * @author Scott Hudson
12: */
13:
14: public class action_part extends production_part {
15:
16: /*-----------------------------------------------------------*/
17: /*--- Constructors ------------------------------------------*/
18: /*-----------------------------------------------------------*/
19:
20: /** Simple constructor.
21: * @param code_str string containing the actual user code.
22: */
23: public action_part(String code_str) {
24: super (/* never have a label on code */null);
25: _code_string = code_str;
26: }
27:
28: /*-----------------------------------------------------------*/
29: /*--- (Access to) Instance Variables ------------------------*/
30: /*-----------------------------------------------------------*/
31:
32: /** String containing code for the action in question. */
33: protected String _code_string;
34:
35: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
36:
37: /** String containing code for the action in question. */
38: public String code_string() {
39: return _code_string;
40: }
41:
42: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
43:
44: /** Set the code string. */
45: public void set_code_string(String new_str) {
46: _code_string = new_str;
47: }
48:
49: /*-----------------------------------------------------------*/
50: /*--- General Methods ---------------------------------------*/
51: /*-----------------------------------------------------------*/
52:
53: /** Override to report this object as an action. */
54: public boolean is_action() {
55: return true;
56: }
57:
58: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
59:
60: /** Equality comparison for properly typed object. */
61: public boolean equals(action_part other) {
62: /* compare the strings */
63: return other != null && super .equals(other)
64: && other.code_string().equals(code_string());
65: }
66:
67: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
68:
69: /** Generic equality comparison. */
70: public boolean equals(Object other) {
71: if (!(other instanceof action_part))
72: return false;
73: else
74: return equals((action_part) other);
75: }
76:
77: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
78:
79: /** Produce a hash code. */
80: public int hashCode() {
81: return super .hashCode()
82: ^ (code_string() == null ? 0 : code_string().hashCode());
83: }
84:
85: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
86:
87: /** Convert to a string. */
88: public String toString() {
89: return super .toString() + "{" + code_string() + "}";
90: }
91:
92: /*-----------------------------------------------------------*/
93: }
|