dll M1.Factory.Create M2.Factory.Create
128 Structuring Model Programs with Features and Composition
Now we introduce another style, the FSM model program. Figure 7.12 shows
M1 coded in this style. It also uses C#, but instead of coding state variables and
action methods, we code the FSM as an array of strings where each string describes
one transistion, in the format "t(current state, action, next state)". The
current state in the first transition is the initial state. In the factory method, the array
of strings is passed to the FSM.Create method, which returns an instance of the FSM
class. Another method in this class can be used to identify the accepting states, if
any. The FSM instance is passed to the constructor for the FsmModelProgram class,
which is also derived from ModelProgram. An FSM model program is compiled and
displayed in exactly the same way as a library model program.
Now we introduce a third style, the FSM text file, which is the most compact
(Figure 7.13). This style dispenses with C# and assemblies altogether and just puts
the FSM in a text file, in a parenthesized format. The first element inside the outer
parentheses is the initial state. The second element is a sequence of accepting states
(which is left empty here, which indicates there are no accepting states). It is not
necessary to compile an FSM file. To display the FSM in the file, invoke mpv with
the /fsm option and name the file:
mpv /fsm:M1.
Pages:
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191