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