1grammar::fa::dexec(n)Finite automaton operations and usagegrammar::fa::dexec(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       grammar::fa::dexec - Execute deterministic finite automatons
9

SYNOPSIS

11       package require Tcl  8.4
12
13       package require snit
14
15       package require grammar::fa::dexec  ?0.2?
16
17       ::grammar::fa::dexec daName fa ?-any any? ?-command cmdprefix?
18
19       daName option ?arg arg ...?
20
21       daName destroy
22
23       daName put symbol
24
25       daName reset
26
27       daName state
28
29       cmdprefix error code message
30
31       cmdprefix final stateid
32
33       cmdprefix reset
34
35       cmdprefix state stateid
36
37______________________________________________________________________________
38

DESCRIPTION

40       This  package provides a class for executors constructed from determin‐
41       istic finite automatons (DFA). Executors are objects which are given  a
42       string  of symbols in a piecemal fashion, perform state transitions and
43       report back when they enter a final state, or find an error in the  in‐
44       put.  For the actual creation of the DFAs the executors are based on we
45       have the packages grammar::fa and grammar::fa::op.
46
47       The objects follow a push model. Symbols are pushed into the  executor,
48       and  when something important happens, i.e. error occurs, a state tran‐
49       sition, or a final state is entered this will be reported via the call‐
50       back  specified  via  the option -command. Note that conversion of this
51       into a pull model where the environment retrieves messages from the ob‐
52       ject  and the object uses a callback to ask for more symbols is a triv‐
53       ial thing.
54
55       Side note: The  acceptor  objects  provided  by  grammar::fa::dacceptor
56       could  have been implemented on top of the executors provided here, but
57       were not, to get a bit more performance (we avoid a  number  of  method
58       calls and the time required for their dispatch).
59

API

61       The package exports the API described here.
62
63       ::grammar::fa::dexec daName fa ?-any any? ?-command cmdprefix?
64              Creates  a  new deterministic executor with an associated global
65              Tcl command whose name is daName. This command may  be  used  to
66              invoke  various operations on the executor. It has the following
67              general form:
68
69              daName option ?arg arg ...?
70                     Option and the args determine the exact behavior  of  the
71                     command.  See  section EXECUTOR METHODS for more explana‐
72                     tions.
73
74                     The executor will be based on  the  deterministic  finite
75                     automaton stored in the object fa. It will keep a copy of
76                     the relevant data of the FA in its own storage, in a form
77                     easy  to  use  for  its  purposes.  This  also means that
78                     changes made to the fa after the construction of the  ex‐
79                     ecutor will not influence the executor.
80
81                     If any has been specified, then the executor will convert
82                     all symbols in the input which are unknown to the base FA
83                     to that symbol before proceeding with the processing.
84

EXECUTOR METHODS

86       All executors provide the following methods for their manipulation:
87
88       daName destroy
89              Destroys  the automaton, including its storage space and associ‐
90              ated command.
91
92       daName put symbol
93              Takes the current state of the executor and the symbol and  per‐
94              forms  the  appropriate state transition. Reports any errors en‐
95              countered via the command callback, as well as entering a  final
96              state of the underlying FA.
97
98              When an error is reported all further invokations of put will do
99              nothing, until the error condition has been cleared via  an  in‐
100              vokation of method reset.
101
102       daName reset
103              Unconditionally  sets  the  executor into the start state of the
104              underlying FA. This also clears any  error  condition   put  may
105              have encountered.
106
107       daName state
108              Returns  the  current state of the underlying FA. This allow for
109              introspection without the need to pass data  from  the  callback
110              command.
111

EXECUTOR CALLBACK

113       The  callback  command  cmdprefix  given  to an executor via the option
114       -command will be executed by the object at the global level, using  the
115       syntax described below. Note that cmdprefix is not simply the name of a
116       command, but a full command prefix. In other words it may contain addi‐
117       tional fixed argument words beyond the command word.
118
119       cmdprefix error code message
120              The  executor  has  encountered an error, and message contains a
121              human-readable text explaining the nature of the  problem.   The
122              code  on  the  other hand is a fixed machine-readable text.  The
123              following error codes can be generated by executor objects.
124
125              BADSYM An unknown symbol was found in the input. This can happen
126                     if and only if no -any symbol was specified.
127
128              BADTRANS
129                     The  underlying FA has no transition for the current com‐
130                     bination of input symbol and state. In other  words,  the
131                     executor  was  not  able  to compute a new state for this
132                     combination.
133
134       cmdprefix final stateid
135              The executor has entered the final state stateid.
136
137       cmdprefix reset
138              The executor was reset.
139
140       cmdprefix state stateid
141              The FA changed state due to a transition.  stateid  is  the  new
142              state.
143

EXAMPLES

BUGS, IDEAS, FEEDBACK

146       This  document,  and the package it describes, will undoubtedly contain
147       bugs and other problems.  Please report such in the category grammar_fa
148       of  the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist].  Please
149       also report any ideas for enhancements you may have for either  package
150       and/or documentation.
151
152       When proposing code changes, please provide unified diffs, i.e the out‐
153       put of diff -u.
154
155       Note further that  attachments  are  strongly  preferred  over  inlined
156       patches.  Attachments  can  be  made  by  going to the Edit form of the
157       ticket immediately after its creation, and  then  using  the  left-most
158       button in the secondary navigation bar.
159

KEYWORDS

161       automaton,  execution,  finite automaton, grammar, parsing, regular ex‐
162       pression, regular grammar, regular languages,  running,  state,  trans‐
163       ducer
164

CATEGORY

166       Grammars and finite automata
167
169       Copyright (c) 2004 Andreas Kupries <andreas_kupries@users.sourceforge.net>
170       Copyright (c) 2007 Bogdan <rftghost@users.sourceforge.net>
171
172
173
174
175tcllib                                0.2                grammar::fa::dexec(n)
Impressum