-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhyaccmanpage.html
406 lines (292 loc) · 14.5 KB
/
hyaccmanpage.html
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
<html>
<head><title>Hyaccmanpage</title></head>
<body>
<pre>
HYACC(1) HYACC(1)
NAME
hyacc - LR(0)/LALR(1)/LR(1)/LR(k) parser generator. Similar utility as
yacc and bison.
SYNOPSIS
hyacc -?
hyacc -h
hyacc --help
hyacc -V
hyacc --version
hyacc [-bcCdDghKlmnoOPQRStvV]
[-b file-name-prefix] [--file-prefix==file-name-prefix]
[-c] [--no-compiler]
[-C] [--keep-unit-production-with-action]
[-d] [--defines]
[-Di] (i = 0~15)
[-g] [--graphviz]
[-h] [--help]
[-K] [--lrk]
[-l] [--no-lines]
[-m] [--man-page]
[-o output-file-name] [--output-file==output-file-name]
[-Oi] (i = 0~3)
[-P] [--lane-tracing-pgm]
[-Q] [--lane-tracing-ltt]
[-R] [--lalr1]
[-S] [--lr0]
[-t] [--debug]
[-v] [--verbose]
[-V] [--version]
DESCRIPTION
Hyacc is a program similar to yacc(1) and bison (LALR(1) parser genera-
tors), but which accepts all LR(1) grammars and thus are more powerful
than yacc(1) and bison. It is backward compatible with input files of
yacc(1) and bison. Hyacc also contains LR(0) algorithm, LALR(1) algo-
rithm (based on lane-tracing) and a partially working LR(k) algorithm
(also based on lane-tracing).
Input files should better follow the yacc convention of ending in .y,
but don't have to. By default, the output file is y.tab.c. When you use
-d you also get y.tab.h, and when you use -v you also get y.output,
same as yacc. The user can use the -b or -o switches to specify the
output file names.
Hyacc supports both traditional single letter options and mnemonic long
option names. Long option names are indicated with -- instead of -.
When a long option takes an argument, like file-prefix, connect the
option name and the argument with ==.
OPTIONS
Command line options are decribed below.
Most options may be give in one of two forms: either a dash followed by
a single letter, or two dashes followed by a long option name.
-b fileprefix
--file-prefix==fileprefix
Specify a prefix to use for all hyacc output file names. The
names are chosen as if the input file were named fileprefix.c.
-c
Use this switch to not generate parser files (y.tab.c and
y.tab.h). This is useful when the user only wants to use the -v
and -D switches to parse the grammar and check the y.output file
about the grammar's information.
-c generally is used with -v, -D and -C.
-C
For the unit production removal optimization (when -O2 or -O3 is
used), if a unit production rule has semantic action, when it is
removed the semantic action won't be preserved, so the output
compiler will miss some code.
To solve this problem, by default HYACC adds a placeholder non-
terminal to unit production rules with actions, so they won't be
removed. E.g., from
program : expression {printf("answer = %d\n", $1);}
;
to
program : expression $PlaceHolder {printf("answer = %d\n", $1);}
;
$PlaceHolder : /* empty */
;
If the -C switch is used, this default action will not be taken.
This is used when the user wants to just parse the grammar and
does not care about generating a useful compiler. Specifically,
-C is used together with switch -c.
-d
--define
Write an extra output file containing macro definitions for the
token type names defined in the grammar.
The file is named y.tab.h.
This output file is essential if you wish to put the definition
of yylex in a separate source file, because yylex needs to be
able to refer to token type codes and the variable yylaval. In
such case y.tab.h should be included into the file containing
yylex.
-D
Change the print option to debug file y.output. A user who
checks the debug file should assume certain degree of knowledge
to the LR(1) compiler theory and optimization algorithms.
If the -v options is used, a debug file y.output will be gener-
ated when hyacc parses the grammar file. Use of -D switch will
automatically turn on the -v switch, and will allow to specify
what kind of information to be included into y.output.
By default, use -v will output the information about the states,
plus a short statistics summary of the number of the grammar's
terminals, nonterminals, grammar rules and states. like the
y.output file of yacc.
-D should be followed by a parameter from 0 ~ 14:
-D0
Include all the information available.
-D1
Include the grammar.
-D2
Include the parsing table.
-D3
Include the process of generating the parsing machine, basi-
cally, the number of states and the current state in each cycle.
-D4
This is useful only if at the time of compilation, in y.h
USE_CONFIG_QUEUE_FOR_GET_CLOSURE is set to 0. This then will
include the information of combining compatible configurations:
the number of configurations before and after the combination.
-D4 can be used together with -D3.
-D5
Include the information of the multi-rooted tree(s) built for
the optimization of removing unit productions.
-D6
Include the information in the optimization of removing unit
productions. Specifically, the new states created and the origi-
nal states from which the new states are combined from.
-D7
Include the information of the step 4 in the optimization of
removing unit productions. Specifically, this shows the states
reachable from state 0.
-D8
Show the entire parsing table after removing unit productions,
including those states that will be removed.
-D9
Show a list of configurations and the theads of the strings
after the scanning symbol.
-D10
Include information of the symbol hash table.
-D11
Include the information of shift/shift conflicts if any. This
happens when the input grammar is not LR(1) or ambiguous, and
the optimization of removing unit production is used. The occur-
rence of shift/shift conflicts means the optimization of remov-
ing unit productions (-O2 and -O3) cannot be applied to this
grammar.
-D12
NOT to include the default information about states when the -v
option is used. Use -D12 to show only the short statistics sum-
mary, and not the states list.
-D13
Include the statistics of configurations for each state, and
also dump the state hash table.
-D14
Include the information of actual/pseudo states. An actual
state number is the row number of that state in the parsing ta-
ble. After the step of unit production removal, some states are
removed but their rows still remain in the parsing table, thus
the state's pseudo state number (counted by ignoring those
removed states/rows) will be different.
-D15
Shows the originator and transitor list of each configuration,
as well as the parent state list of each state. This is rele-
vant when lane-tracing is used.
-g
--graphviz
Generate a graphviz input file for the parsing machine.
-h
--help Print a usage summary of hyacc.
-K
--lrk Apply the LR(k) algorithm. The LR(k) algorithm is called the
edge-pushing algorithm, which is based on lane-tracing, using a
lane-tracing table based method to split states. In other words,
this is extension of the option -Q (--lane-tracing-ltt) for
LR(k) where k > 1. So far this works for those LR(K) grammars
where lanes involved in lane-tracing upon increasing k do not
contain cycle.
-l
--nolines
Don't put any #line preprocessor commands in the parser file.
Ordinarily hyacc puts them in the parser file so that the C com-
piler and debuggers will associate errors with your source file,
the grammar file. This options causes them to associate errors
with the parser file, treating it as an independent source file
in its own right.
-m
--man-page
Show man page. Same as "man hyacc". This is used when the man
page file exists in the same directory as the hyacc executable.
So if installation moves this man page file to another location,
you must use "man hyacc".
-o outfile
--output-file==outfile
Specify the name outfile for the parser file.
The other output files' names are constructed from outfile as
described under the v and d switches.
-O
Specify the kind of optimization used to parse the yacc input
file.
Basically, three optimizations are used: 1) Combine compatible
states based on weak compatibility. 2) Remove unit productions.
3) Remove repeated states after optimization 2).
The -O switch should be followed by a parameter from 0 to 3:
-O0
No optimization is used.
-O1
Optimization 1) is used.
-O2
Optimizations 1) and 2) are used.
-O3
Optimizations 1), 2) and 3) are used.
By default, when -O switch is not specified, the optimization 1)
of combining compatible states is used. So "hyacc file.y" is
equivalent to "hyacc file.y -O1" or "hyacc -O1 file.y".
-P
--lane-tracing-pgm
Use LR(1) based on the lane-tracing algorithm. The lane-tracing
algorithm first obtains the LR(0) parsing machine, then use
lane-tracing to obtain the contexts for those states where
shift/reduce or reduce/reduce conflicts exist. If conflicts are
not resolved for some states, then the involved states are
splitted using the practical general method.
-Q
--lane-tracing-ltt
Use LR(1) based on the lane-tracing algorithm. The lane-tracing
algorithm first obtains the LR(0) parsing machine, then use
lane-tracing to obtain the contexts for those states where
shift/reduce or reduce/reduce conflicts exist. If conflicts are
not resolved for some states, then the involved states are
splitted using a lane-tracing table based method.
-R
--lalr1
Use LALR(1) algorithm based on lane-tracing phase 1.
-S
--lr0 Use LR(0) algorithm.
-t
--debug
In the parser files, define the macro YYDEBUG to 1 if it is not
already defined, so that the debugging facilities are compiled.
When the generated compiler parses an input yacc file, the parse
process will be recorded in an output file y.parse, which
includes all the shift/reduce actions, associated state number
and lookahead, as well as the content of state stack and symbol
stack.
-v
--verbose
Write an extra output file containing verbose descriptions of
the parser states and what is done for each type of lookahead
token in that state.
This file also describes all the conflicts, both those resolved
by operator precedence and the unresolved ones.
The file's name is y.output.
-V
--version
Print the version number of hyacc and exit.
EXAMPLES
Assume the input grammar file is arith.y.
The user wants y.tab.c only:
hyacc arith.y
The user wants y.tab.c and y.tab.h:
hyacc -d arith.y
The user wants the generated compiler create y.parse when parsing a
program:
hyacc -dt arith.y
or
hyacc arith.y -d -t
The user wants y.ta.b, y.tab.h, and create a y.output file when parsing
the grammar:
hyacc -dv arith.y
The user wants, y.tab.c, y.tab.h, y.output and wants to include no
other information than the short statistics summary in y.output:
hyacc -dD12 arith.y
Here -D12 will suppress the states list.
The user wants y.tab.c and y.tab.h, use optimization 1) only, and wants
a default y.output:
hyacc -d -O1 -v arith.y
or
hyacc -dO1v arith.y
The user wants to parse the grammar and check y.output for information,
and doesn't need a compiler. While use all the optimizations, he wants
to keep those unit productions with semantic actions:
hyacc -cCv arith.y
DIAGNOSITICS
Self explanatory.
AUTHOR
Xin Chen <[email protected]>
Send bug report or comments to the above address.
Version 0.97: 28 March 2009 HYACC(1)
</pre>
</body>
</html>