-
Notifications
You must be signed in to change notification settings - Fork 1
/
lalr_transition.cs
122 lines (102 loc) · 3.38 KB
/
lalr_transition.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
namespace CUP
{
using System;
/// <summary>This class represents a transition in an LALR viable prefix recognition
/// machine. Transitions can be under terminals for non-terminals. They are
/// internally linked together into singly linked lists containing all the
/// transitions out of a single state via the _next field.
/// *
/// </summary>
/// <seealso cref=" CUP.lalr_state
/// "/>
/// <version> last updated: 11/25/95
/// </version>
/// <author> Scott Hudson
/// *
///
/// </author>
public class lalr_transition
{
/*-----------------------------------------------------------*/
/*--- Constructor(s) ----------------------------------------*/
/*-----------------------------------------------------------*/
/// <summary>Full constructor.
/// </summary>
/// <param name="on_sym"> symbol we are transitioning on.
/// </param>
/// <param name="to_st"> state we transition to.
/// </param>
/// <param name="nxt"> next transition in linked list.
///
/// </param>
public lalr_transition(symbol on_sym, lalr_state to_st, lalr_transition nxt)
{
/* sanity checks */
if (on_sym == null)
throw new internal_error("Attempt to create transition on null symbol");
if (to_st == null)
throw new internal_error("Attempt to create transition to null state");
/* initialize */
_on_symbol = on_sym;
_to_state = to_st;
_next = nxt;
}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/// <summary>Constructor with null next.
/// </summary>
/// <param name="on_sym"> symbol we are transitioning on.
/// </param>
/// <param name="to_st"> state we transition to.
///
/// </param>
public lalr_transition(symbol on_sym, lalr_state to_st):this(on_sym, to_st, null)
{
}
/*-----------------------------------------------------------*/
/*--- (Access to) Instance Variables ------------------------*/
/*-----------------------------------------------------------*/
/// <summary>The symbol we make the transition on.
/// </summary>
protected symbol _on_symbol;
/// <summary>The symbol we make the transition on.
/// </summary>
public virtual symbol on_symbol()
{
return _on_symbol;
}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/// <summary>The state we transition to.
/// </summary>
protected lalr_state _to_state;
/// <summary>The state we transition to.
/// </summary>
public virtual lalr_state to_state()
{
return _to_state;
}
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
/// <summary>Next transition in linked list of transitions out of a state
/// </summary>
protected lalr_transition _next;
/// <summary>Next transition in linked list of transitions out of a state
/// </summary>
public virtual lalr_transition next()
{
return _next;
}
/*-----------------------------------------------------------*/
/*--- General Methods ---------------------------------------*/
/*-----------------------------------------------------------*/
/// <summary>Convert to a string.
/// </summary>
public override string ToString()
{
System.String result;
result = "transition on " + on_symbol().name_Renamed_Method() + " to state [";
result += _to_state.index();
result += "]";
return result;
}
/*-----------------------------------------------------------*/
}
}