1. package com.sun.java_cup.internal;
  2. /** This class represents a reduce action within the parse table.
  3. * The action simply stores the production that it reduces with and
  4. * responds to queries about its type.
  5. *
  6. * @version last updated: 11/25/95
  7. * @author Scott Hudson
  8. */
  9. public class reduce_action extends parse_action {
  10. /*-----------------------------------------------------------*/
  11. /*--- Constructor(s) ----------------------------------------*/
  12. /*-----------------------------------------------------------*/
  13. /** Simple constructor.
  14. * @param prod the production this action reduces with.
  15. */
  16. public reduce_action(production prod ) throws internal_error
  17. {
  18. /* sanity check */
  19. if (prod == null)
  20. throw new internal_error(
  21. "Attempt to create a reduce_action with a null production");
  22. _reduce_with = prod;
  23. }
  24. /*-----------------------------------------------------------*/
  25. /*--- (Access to) Instance Variables ------------------------*/
  26. /*-----------------------------------------------------------*/
  27. /** The production we reduce with. */
  28. protected production _reduce_with;
  29. /** The production we reduce with. */
  30. public production reduce_with() {return _reduce_with;}
  31. /*-----------------------------------------------------------*/
  32. /*--- General Methods ---------------------------------------*/
  33. /*-----------------------------------------------------------*/
  34. /** Quick access to type of action. */
  35. public int kind() {return REDUCE;}
  36. /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
  37. /** Equality test. */
  38. public boolean equals(reduce_action other)
  39. {
  40. return other != null && other.reduce_with() == reduce_with();
  41. }
  42. /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
  43. /** Generic equality test. */
  44. public boolean equals(Object other)
  45. {
  46. if (other instanceof reduce_action)
  47. return equals((reduce_action)other);
  48. else
  49. return false;
  50. }
  51. /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
  52. /** Compute a hash code. */
  53. public int hashCode()
  54. {
  55. /* use the hash code of the production we are reducing with */
  56. return reduce_with().hashCode();
  57. }
  58. /** Convert to string. */
  59. public String toString()
  60. {
  61. return "REDUCE(with prod " + reduce_with().index() + ")";
  62. }
  63. /*-----------------------------------------------------------*/
  64. }