1. package com.sun.java_cup.internal;
  2. /** This class represents a part of a production which is a symbol (terminal
  3. * or non terminal). This simply maintains a reference to the symbol in
  4. * question.
  5. *
  6. * @see com.sun.java_cup.internal.production
  7. * @version last updated: 11/25/95
  8. * @author Scott Hudson
  9. */
  10. public class symbol_part extends production_part {
  11. /*-----------------------------------------------------------*/
  12. /*--- Constructor(s) ----------------------------------------*/
  13. /*-----------------------------------------------------------*/
  14. /** Full constructor.
  15. * @param sym the symbol that this part is made up of.
  16. * @param lab an optional label string for the part.
  17. */
  18. public symbol_part(symbol sym, String lab) throws internal_error
  19. {
  20. super(lab);
  21. if (sym == null)
  22. throw new internal_error(
  23. "Attempt to construct a symbol_part with a null symbol");
  24. _the_symbol = sym;
  25. }
  26. /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
  27. /** Constructor with no label.
  28. * @param sym the symbol that this part is made up of.
  29. */
  30. public symbol_part(symbol sym) throws internal_error
  31. {
  32. this(sym,null);
  33. }
  34. /*-----------------------------------------------------------*/
  35. /*--- (Access to) Instance Variables ------------------------*/
  36. /*-----------------------------------------------------------*/
  37. /** The symbol that this part is made up of. */
  38. protected symbol _the_symbol;
  39. /** The symbol that this part is made up of. */
  40. public symbol the_symbol() {return _the_symbol;}
  41. /*-----------------------------------------------------------*/
  42. /*--- General Methods ---------------------------------------*/
  43. /*-----------------------------------------------------------*/
  44. /** Respond that we are not an action part. */
  45. public boolean is_action() { return false; }
  46. /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
  47. /** Equality comparison. */
  48. public boolean equals(symbol_part other)
  49. {
  50. return other != null && super.equals(other) &&
  51. the_symbol().equals(other.the_symbol());
  52. }
  53. /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
  54. /** Generic equality comparison. */
  55. public boolean equals(Object other)
  56. {
  57. if (!(other instanceof symbol_part))
  58. return false;
  59. else
  60. return equals((symbol_part)other);
  61. }
  62. /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
  63. /** Produce a hash code. */
  64. public int hashCode()
  65. {
  66. return super.hashCode() ^
  67. (the_symbol()==null ? 0 : the_symbol().hashCode());
  68. }
  69. /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
  70. /** Convert to a string. */
  71. public String toString()
  72. {
  73. if (the_symbol() != null)
  74. return super.toString() + the_symbol();
  75. else
  76. return super.toString() + "$$MISSING-SYMBOL$$";
  77. }
  78. /*-----------------------------------------------------------*/
  79. }