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