01: package java_cup;
02:
03: /** This class represents a transition in an LALR viable prefix recognition
04: * machine. Transitions can be under terminals for non-terminals. They are
05: * internally linked together into singly linked lists containing all the
06: * transitions out of a single state via the _next field.
07: *
08: * @see java_cup.lalr_state
09: * @version last updated: 11/25/95
10: * @author Scott Hudson
11: *
12: */
13: public class lalr_transition {
14:
15: /*-----------------------------------------------------------*/
16: /*--- Constructor(s) ----------------------------------------*/
17: /*-----------------------------------------------------------*/
18:
19: /** Full constructor.
20: * @param on_sym symbol we are transitioning on.
21: * @param to_st state we transition to.
22: * @param nxt next transition in linked list.
23: */
24: public lalr_transition(symbol on_sym, lalr_state to_st,
25: lalr_transition nxt) throws internal_error {
26: /* sanity checks */
27: if (on_sym == null)
28: throw new internal_error(
29: "Attempt to create transition on null symbol");
30: if (to_st == null)
31: throw new internal_error(
32: "Attempt to create transition to null state");
33:
34: /* initialize */
35: _on_symbol = on_sym;
36: _to_state = to_st;
37: _next = nxt;
38: }
39:
40: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
41:
42: /** Constructor with null next.
43: * @param on_sym symbol we are transitioning on.
44: * @param to_st state we transition to.
45: */
46: public lalr_transition(symbol on_sym, lalr_state to_st)
47: throws internal_error {
48: this (on_sym, to_st, null);
49: }
50:
51: /*-----------------------------------------------------------*/
52: /*--- (Access to) Instance Variables ------------------------*/
53: /*-----------------------------------------------------------*/
54:
55: /** The symbol we make the transition on. */
56: protected symbol _on_symbol;
57:
58: /** The symbol we make the transition on. */
59: public symbol on_symbol() {
60: return _on_symbol;
61: }
62:
63: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
64:
65: /** The state we transition to. */
66: protected lalr_state _to_state;
67:
68: /** The state we transition to. */
69: public lalr_state to_state() {
70: return _to_state;
71: }
72:
73: /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
74:
75: /** Next transition in linked list of transitions out of a state */
76: protected lalr_transition _next;
77:
78: /** Next transition in linked list of transitions out of a state */
79: public lalr_transition next() {
80: return _next;
81: }
82:
83: /*-----------------------------------------------------------*/
84: /*--- General Methods ---------------------------------------*/
85: /*-----------------------------------------------------------*/
86:
87: /** Convert to a string. */
88: public String toString() {
89: String result;
90:
91: result = "transition on " + on_symbol().name() + " to state [";
92: result += _to_state.index();
93: result += "]";
94:
95: return result;
96: }
97:
98: /*-----------------------------------------------------------*/
99: }
|