1[comment {-*- tcl -*- doctools manpage}]
2[manpage_begin grammar::fa::dexec n 0.2]
3[copyright {2004 Andreas Kupries <andreas_kupries@users.sourceforge.net>}]
4[copyright {2007 Bogdan <rftghost@users.sourceforge.net>}]
5[moddesc   {Finite automaton operations and usage}]
6[titledesc {Execute deterministic finite automatons}]
7[category  {Grammars and finite automata}]
8[require Tcl 8.4]
9[require snit]
10[require grammar::fa::dexec [opt 0.2]]
11[description]
12[keywords execution running grammar automaton {finite automaton}]
13[keywords state {regular expression} {regular grammar}]
14[keywords {regular languages} parsing transducer]
15[para]
16
17This package provides a class for executors constructed from
18deterministic [term {finite automatons}] (DFA). Executors are objects
19which are given a string of symbols in a piecemal fashion, perform
20state transitions and report back when they enter a final state, or
21find an error in the input.
22
23For the actual creation of the DFAs the executors are based on we have
24the packages [package grammar::fa] and [package grammar::fa::op].
25
26[para]
27
28The objects follow a push model. Symbols are pushed into the executor,
29and when something important happens, i.e. error occurs, a state transition,
30or a final state is entered this will be reported via the callback
31specified via the option [option -command]. Note that conversion of
32this into a pull model where the environment retrieves messages from
33the object and the object uses a callback to ask for more symbols is
34a trivial thing.
35
36
37[para]
38
39[emph {Side note}]:
40
41The acceptor objects provided by [package grammar::fa::dacceptor]
42could have been implemented on top of the executors provided here, but
43were not, to get a bit more performance (we avoid a number of method
44calls and the time required for their dispatch).
45
46[para]
47
48[section API]
49
50The package exports the API described here.
51
52[list_begin definitions]
53
54[call [cmd ::grammar::fa::dexec] [arg daName] [arg fa] [opt "[option -any] [arg any]"] [opt "[option -command] [arg cmdprefix]"]]
55
56Creates a new deterministic executor with an associated global Tcl
57command whose name is [arg daName]. This command may be used to invoke
58various operations on the executor. It has the following general form:
59
60[list_begin definitions]
61
62[call [cmd daName] [arg option] [opt [arg "arg arg ..."]]]
63
64[arg Option] and the [arg arg]s determine the exact behavior of the
65command. See section [sectref {EXECUTOR METHODS}] for more
66explanations.
67
68[para]
69
70The executor will be based on the deterministic finite automaton
71stored in the object [arg fa]. It will keep a copy of the relevant
72data of the FA in its own storage, in a form easy to use for its
73purposes. This also means that changes made to the [arg fa] after the
74construction of the executor [emph {will not}] influence the executor.
75
76[para]
77
78If [arg any] has been specified, then the executor will convert all
79symbols in the input which are unknown to the base FA to that symbol
80before proceeding with the processing.
81
82[list_end]
83[list_end]
84
85[section {EXECUTOR METHODS}]
86[para]
87
88All executors provide the following methods for their manipulation:
89
90[list_begin definitions]
91
92
93[call [arg daName] [method destroy]]
94
95Destroys the automaton, including its storage space and associated
96command.
97
98
99[call [arg daName] [method put] [arg symbol]]
100
101Takes the current state of the executor and the [arg symbol] and
102performs the appropriate state transition. Reports any errors
103encountered via the command callback, as well as entering a final
104state of the underlying FA.
105
106[para]
107
108When an error is reported all further invokations of [method put] will
109do nothing, until the error condition has been cleared via an
110invokation of method [method reset].
111
112
113[call [arg daName] [method reset]]
114
115Unconditionally sets the executor into the start state of the
116underlying FA. This also clears any error condition  [method put] may
117have encountered.
118
119[call [arg daName] [method state]]
120
121Returns the current state of the underlying FA. This allow for 
122introspection without the need to pass data from the callback command.
123
124[list_end]
125
126
127[section {EXECUTOR CALLBACK}]
128
129The callback command [arg cmdprefix] given to an executor via the
130option [option -command] will be executed by the object at the global
131level, using the syntax described below. Note that [arg cmdprefix] is
132not simply the name of a command, but a full command prefix. In other
133words it may contain additional fixed argument words beyond the
134command word.
135
136[list_begin definitions]
137
138[call [arg cmdprefix] [method error] [arg code] [arg message]]
139
140The executor has encountered an error, and [arg message] contains a
141human-readable text explaining the nature of the problem.
142
143The [arg code] on the other hand is a fixed machine-readable text.
144The following error codes can be generated by executor objects.
145
146[list_begin definitions]
147[def [const BADSYM]]
148
149An unknown symbol was found in the input. This can happen if and only
150if no [option -any] symbol was specified.
151
152[def [const BADTRANS]]
153
154The underlying FA has no transition for the current combination of
155input symbol and state. In other words, the executor was not able to
156compute a new state for this combination.
157
158[list_end]
159
160[call [arg cmdprefix] [method final] [arg stateid]]
161
162The executor has entered the final state [arg stateid].
163
164[call [arg cmdprefix] [method reset]]
165
166The executor was reset.
167
168[call [arg cmdprefix] [method state] [arg stateid]]
169
170The FA changed state due to a transition. [arg stateid] is the new state.
171
172[list_end]
173
174
175[para]
176
177[section EXAMPLES]
178[para]
179
180[section {BUGS, IDEAS, FEEDBACK}]
181
182This document, and the package it describes, will undoubtedly contain
183bugs and other problems.
184
185Please report such in the category [emph grammar_fa] of the
186[uri {http://sourceforge.net/tracker/?group_id=12883} {Tcllib SF Trackers}].
187
188Please also report any ideas for enhancements you may have for either
189package and/or documentation.
190
191
192[manpage_end]
193