5 * This class represents a part of a production which contains an
6 * action. These are eventually eliminated from productions and converted
7 * to trailing actions by factoring out with a production that derives the
8 * empty string (and ends with this action).
10 * @see java_cup.production
11 * @version last update: 11/25/95
12 * @author Scott Hudson
15 public class action_part extends production_part {
17 /*-----------------------------------------------------------*/
18 /*--- Constructors ------------------------------------------*/
19 /*-----------------------------------------------------------*/
21 /** Simple constructor.
22 * @param code_str string containing the actual user code.
24 public action_part(String code_str)
26 super(/* never have a label on code */null);
27 _code_string = code_str;
30 /*-----------------------------------------------------------*/
31 /*--- (Access to) Instance Variables ------------------------*/
32 /*-----------------------------------------------------------*/
34 /** String containing code for the action in question. */
35 protected String _code_string;
37 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
39 /** String containing code for the action in question. */
40 public String code_string() {return _code_string;}
42 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
44 /** Set the code string. */
45 public void set_code_string(String new_str) {_code_string = new_str;}
47 /*-----------------------------------------------------------*/
48 /*--- General Methods ---------------------------------------*/
49 /*-----------------------------------------------------------*/
51 /** Override to report this object as an action. */
52 public boolean is_action() { return true; }
54 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
56 /** Equality comparison for properly typed object. */
57 public boolean equals(action_part other)
59 /* compare the strings */
60 return other != null && super.equals(other) &&
61 other.code_string().equals(code_string());
64 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
66 /** Generic equality comparison. */
67 public boolean equals(Object other)
69 if (!(other instanceof action_part))
72 return equals((action_part)other);
75 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
77 /** Produce a hash code. */
80 return super.hashCode() ^
81 (code_string()==null ? 0 : code_string().hashCode());
84 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
86 /** Convert to a string. */
87 public String toString()
89 return super.toString() + "{" + code_string() + "}";
92 /*-----------------------------------------------------------*/