1. package com.sun.java_cup.internal;
  2. /** This class represents a transition in an LALR viable prefix recognition
  3. * machine. Transitions can be under terminals for non-terminals. They are
  4. * internally linked together into singly linked lists containing all the
  5. * transitions out of a single state via the _next field.
  6. *
  7. * @see com.sun.java_cup.internal.lalr_state
  8. * @version last updated: 11/25/95
  9. * @author Scott Hudson
  10. *
  11. */
  12. public class lalr_transition {
  13. /*-----------------------------------------------------------*/
  14. /*--- Constructor(s) ----------------------------------------*/
  15. /*-----------------------------------------------------------*/
  16. /** Full constructor.
  17. * @param on_sym symbol we are transitioning on.
  18. * @param to_st state we transition to.
  19. * @param nxt next transition in linked list.
  20. */
  21. public lalr_transition(symbol on_sym, lalr_state to_st, lalr_transition nxt)
  22. throws internal_error
  23. {
  24. /* sanity checks */
  25. if (on_sym == null)
  26. throw new internal_error("Attempt to create transition on null symbol");
  27. if (to_st == null)
  28. throw new internal_error("Attempt to create transition to null state");
  29. /* initialize */
  30. _on_symbol = on_sym;
  31. _to_state = to_st;
  32. _next = nxt;
  33. }
  34. /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
  35. /** Constructor with null next.
  36. * @param on_sym symbol we are transitioning on.
  37. * @param to_st state we transition to.
  38. */
  39. public lalr_transition(symbol on_sym, lalr_state to_st) throws internal_error
  40. {
  41. this(on_sym, to_st, null);
  42. }
  43. /*-----------------------------------------------------------*/
  44. /*--- (Access to) Instance Variables ------------------------*/
  45. /*-----------------------------------------------------------*/
  46. /** The symbol we make the transition on. */
  47. protected symbol _on_symbol;
  48. /** The symbol we make the transition on. */
  49. public symbol on_symbol() {return _on_symbol;}
  50. /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
  51. /** The state we transition to. */
  52. protected lalr_state _to_state;
  53. /** The state we transition to. */
  54. public lalr_state to_state() {return _to_state;}
  55. /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
  56. /** Next transition in linked list of transitions out of a state */
  57. protected lalr_transition _next;
  58. /** Next transition in linked list of transitions out of a state */
  59. public lalr_transition next() {return _next;}
  60. /*-----------------------------------------------------------*/
  61. /*--- General Methods ---------------------------------------*/
  62. /*-----------------------------------------------------------*/
  63. /** Convert to a string. */
  64. public String toString()
  65. {
  66. String result;
  67. result = "transition on " + on_symbol().name() + " to state [";
  68. result += _to_state.index();
  69. result += "]";
  70. return result;
  71. }
  72. /*-----------------------------------------------------------*/
  73. }