1. package com.sun.java_cup.internal;
  2. /** This class represents one part (either a symbol or an action) of a
  3. * production. In this base class it contains only an optional label
  4. * string that the user can use to refer to the part within actions.<p>
  5. *
  6. * This is an abstract class.
  7. *
  8. * @see com.sun.java_cup.internal.production
  9. * @version last updated: 11/25/95
  10. * @author Scott Hudson
  11. */
  12. public abstract class production_part {
  13. /*-----------------------------------------------------------*/
  14. /*--- Constructor(s) ----------------------------------------*/
  15. /*-----------------------------------------------------------*/
  16. /** Simple constructor. */
  17. public production_part(String lab)
  18. {
  19. _label = lab;
  20. }
  21. /*-----------------------------------------------------------*/
  22. /*--- (Access to) Instance Variables ------------------------*/
  23. /*-----------------------------------------------------------*/
  24. /** Optional label for referring to the part within an action (null for
  25. * no label).
  26. */
  27. protected String _label;
  28. /** Optional label for referring to the part within an action (null for
  29. * no label).
  30. */
  31. public String label() {return _label;}
  32. /*-----------------------------------------------------------*/
  33. /*--- General Methods ---------------------------------------*/
  34. /*-----------------------------------------------------------*/
  35. /** Indicate if this is an action (rather than a symbol). Here in the
  36. * base class, we don't this know yet, so its an abstract method.
  37. */
  38. public abstract boolean is_action();
  39. /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
  40. /** Equality comparison. */
  41. public boolean equals(production_part other)
  42. {
  43. if (other == null) return false;
  44. /* compare the labels */
  45. if (label() != null)
  46. return label().equals(other.label());
  47. else
  48. return other.label() == null;
  49. }
  50. /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
  51. /** Generic equality comparison. */
  52. public boolean equals(Object other)
  53. {
  54. if (!(other instanceof production_part))
  55. return false;
  56. else
  57. return equals((production_part)other);
  58. }
  59. /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
  60. /** Produce a hash code. */
  61. public int hashCode()
  62. {
  63. return label()==null ? 0 : label().hashCode();
  64. }
  65. /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
  66. /** Convert to a string. */
  67. public String toString()
  68. {
  69. if (label() != null)
  70. return label() + ":";
  71. else
  72. return " ";
  73. }
  74. /*-----------------------------------------------------------*/
  75. }