1. package com.sun.java_cup.internal;
  2. /** This class represents a shift action within the parse table.
  3. * The action simply stores the state that it shifts to and responds
  4. * to queries about its type.
  5. *
  6. * @version last updated: 11/25/95
  7. * @author Scott Hudson
  8. */
  9. public class shift_action extends parse_action {
  10. /*-----------------------------------------------------------*/
  11. /*--- Constructor(s) ----------------------------------------*/
  12. /*-----------------------------------------------------------*/
  13. /** Simple constructor.
  14. * @param shft_to the state that this action shifts to.
  15. */
  16. public shift_action(lalr_state shft_to) throws internal_error
  17. {
  18. /* sanity check */
  19. if (shft_to == null)
  20. throw new internal_error(
  21. "Attempt to create a shift_action to a null state");
  22. _shift_to = shft_to;
  23. }
  24. /*-----------------------------------------------------------*/
  25. /*--- (Access to) Instance Variables ------------------------*/
  26. /*-----------------------------------------------------------*/
  27. /** The state we shift to. */
  28. protected lalr_state _shift_to;
  29. /** The state we shift to. */
  30. public lalr_state shift_to() {return _shift_to;}
  31. /*-----------------------------------------------------------*/
  32. /*--- General Methods ---------------------------------------*/
  33. /*-----------------------------------------------------------*/
  34. /** Quick access to type of action. */
  35. public int kind() {return SHIFT;}
  36. /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
  37. /** Equality test. */
  38. public boolean equals(shift_action other)
  39. {
  40. return other != null && other.shift_to() == shift_to();
  41. }
  42. /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
  43. /** Generic equality test. */
  44. public boolean equals(Object other)
  45. {
  46. if (other instanceof shift_action)
  47. return equals((shift_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 state we are shifting to */
  56. return shift_to().hashCode();
  57. }
  58. /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
  59. /** Convert to a string. */
  60. public String toString() {return "SHIFT(to state " + shift_to().index() + ")";}
  61. /*-----------------------------------------------------------*/
  62. }