1pt_peg_op(i)                     Parser Tools                     pt_peg_op(i)
2
3
4
5______________________________________________________________________________
6

NAME

8       pt_peg_op - Parser Tools PE Grammar Utility Operations
9

SYNOPSIS

11       package require Tcl  8.5
12
13       package require pt::peg::op  ?1.1.0?
14
15       ::peg::peg::op called container
16
17       ::peg::peg::op dechain container
18
19       ::peg::peg::op drop unreachable container
20
21       ::peg::peg::op drop unrealizable container
22
23       ::peg::peg::op flatten container
24
25       ::peg::peg::op minimize container
26
27       ::peg::peg::op modeopt container
28
29       ::peg::peg::op reachable container
30
31       ::peg::peg::op realizable container
32
33______________________________________________________________________________
34

DESCRIPTION

36       Are  you  lost ?  Do you have trouble understanding this document ?  In
37       that case please read the overview  provided  by  the  Introduction  to
38       Parser  Tools.  This document is the entrypoint to the whole system the
39       current package is a part of.
40
41       This package provides a number of utility commands  manipulating  a  PE
42       grammar (container) in various ways.
43

API

45       ::peg::peg::op called container
46              This  command  determines the static call structure for the non‐
47              terminal symbols of the grammar stored in the container.
48
49              The result of the command is a dictionary mapping from each sym‐
50              bol to the symbols it calls. The empty string is the key used to
51              represent the start expression of the grammar.
52
53              The grammar in the container is not modified.
54
55              The container instance has to expose a method API as is provided
56              by the package pt::peg::container.
57
58       ::peg::peg::op dechain container
59              This  command  simplifies all symbols which just chain to a dif‐
60              ferent symbol by inlining the right hand side of the called sym‐
61              bol in its callers. This works if and only the modes match prop‐
62              erly, per the decision table below.
63
64
65
66              caller called | dechain | notes
67              --------------+---------+-----------------------
68              value  value  |  yes    |  value is passed
69              value  leaf   |  yes    |  value is passed
70              value  void   |  yes    |  caller is implied void
71              leaf   value  |  no     |  generated value was discarded, inlined would not. called may be implied void.
72              leaf   leaf   |  no     |  s.a.
73              leaf   void   |  no     |  s.a.
74              void   value  |  no     |  caller drops value, inlined would not.
75              void   leaf   |  no     |  s.a.
76              void   void   |  yes    |
77
78
79       The result of the command is the empty string.
80
81       The grammar in the container is  directly  modified.  If  that  is  not
82       wanted, a copy of the original container has to be used.
83
84       The container instance has to expose a method API as is provided by the
85       package pt::peg::container.
86
87       ::peg::peg::op drop unreachable container
88              This command removes all symbols from the grammar which are  not
89              reachable.
90
91              The result of the command is the empty string.
92
93              The  grammar  in  the container is directly modified. If that is
94              not wanted, a copy of the original container has to be used.
95
96              The container instance has to expose a method API as is provided
97              by the package pt::peg::container.
98
99       ::peg::peg::op drop unrealizable container
100              This  command removes all symbols from the grammar which are not
101              realizable.
102
103              The result of the command is the empty string.
104
105              The grammar in the container is directly modified.  If  that  is
106              not wanted, a copy of the original container has to be used.
107
108              The container instance has to expose a method API as is provided
109              by the package pt::peg::container.
110
111       ::peg::peg::op flatten container
112              This command flattens (see pt::pe::op) all  expressions  in  the
113              grammar,  i.e.  the start expression and the right hand sides of
114              all nonterminal symbols.
115
116              The result of the command is the empty string.
117
118              The grammar in the container is directly modified.  If  that  is
119              not wanted, a copy of the original container has to be used.
120
121              The container instance has to expose a method API as is provided
122              by the package pt::peg::container.
123
124       ::peg::peg::op minimize container
125              This command reduces the provided grammar by  applying  most  of
126              the other methods of this package.
127
128              After  flattening the expressions it removes unreachable and un‐
129              realizable symbols, flattens the expressions again,  then  opti‐
130              mizes  the  symbol modes before collapsing symbol chains as much
131              as possible.
132
133              The result of the command is the empty string.
134
135              The grammar in the container is directly modified.  If  that  is
136              not wanted, a copy of the original container has to be used.
137
138              The container instance has to expose a method API as is provided
139              by the package pt::peg::container.
140
141       ::peg::peg::op modeopt container
142              This command optimizes the semantic modes of  non-terminal  sym‐
143              bols according to the two rules below.
144
145              [1]    If  a  symbol  X  with mode value calls no other symbols,
146                     i.e. uses only terminal symbols in whatever  combination,
147                     then this can be represented simpler by using mode leaf.
148
149              [2]    If a symbol X is only called from symbols with modes leaf
150                     or void then this symbol should have mode void  also,  as
151                     any AST it could generate will be discarded anyway.
152
153       The result of the command is the empty string.
154
155       The  grammar  in  the  container  is  directly modified. If that is not
156       wanted, a copy of the original container has to be used.
157
158       The container instance has to expose a method API as is provided by the
159       package pt::peg::container.
160
161       ::peg::peg::op reachable container
162              This  command  computes the set of all nonterminal symbols which
163              are reachable from the start expression of the grammar. This  is
164              essentially  the transitive closure over called and the symbol's
165              right hand sides, beginning with the start expression.
166
167              The result of the command is the list of reachable symbols.
168
169              The grammar in the container is not modified.
170
171              The container instance has to expose a method API as is provided
172              by the package pt::peg::container.
173
174       ::peg::peg::op realizable container
175              This  command  computes the set of all nonterminal symbols which
176              are realizable, i.e. can derive pure terminal phrases.  This  is
177              done  iteratively,  starting with state unrealizable for all and
178              any, and then updating all symbols which are realizable,  propa‐
179              gating changes, until nothing changes any more.
180
181              The result of the command is the list of realizable symbols.
182
183              The grammar in the container is not modified.
184
185              The container instance has to expose a method API as is provided
186              by the package pt::peg::container.
187

BUGS, IDEAS, FEEDBACK

189       This document, and the package it describes, will  undoubtedly  contain
190       bugs  and other problems.  Please report such in the category pt of the
191       Tcllib Trackers  [http://core.tcl.tk/tcllib/reportlist].   Please  also
192       report  any  ideas  for  enhancements  you  may have for either package
193       and/or documentation.
194
195       When proposing code changes, please provide unified diffs, i.e the out‐
196       put of diff -u.
197
198       Note  further  that  attachments  are  strongly  preferred over inlined
199       patches. Attachments can be made by going  to  the  Edit  form  of  the
200       ticket  immediately  after  its  creation, and then using the left-most
201       button in the secondary navigation bar.
202

KEYWORDS

204       EBNF, LL(k), PEG, TDPL, context-free  languages,  expression,  grammar,
205       matching,  parser, parsing expression, parsing expression grammar, push
206       down automaton, recursive descent, state, top-down  parsing  languages,
207       transducer
208

CATEGORY

210       Parsing and Grammars
211
213       Copyright (c) 2009 Andreas Kupries <andreas_kupries@users.sourceforge.net>
214
215
216
217
218tcllib                               1.1.0                        pt_peg_op(i)
Impressum