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
|
.TH YACC 1
.SH NAME
yacc \- yet another compiler-compiler
.SH SYNOPSIS
.B yacc
[
.I option ...
]
.I grammar
.SH DESCRIPTION
.I Yacc
converts a context-free grammar and translation code
into a set of
tables for an LR(1) parser and translator.
The grammar may be ambiguous;
specified precedence rules are used to break ambiguities.
.PP
The output file,
.BR y.tab.c ,
must be compiled by the C compiler
to produce a program
.LR yyparse .
This program must be loaded with a lexical analyzer function,
.B yylex(void)
(often generated by
.IR lex (1)),
with a
.B main(int argc, char *argv[])
program, and with an error handling routine,
.BR yyerror(char*) .
.PP
The options are
.TP "\w'\fL-o \fIoutput\fLXX'u"
.BI -o " output
Direct output to the specified file instead of
.BR y.tab.c .
.TP
.BI -D n
Create file
.BR y.debug ,
containing diagnostic messages.
To incorporate them in the parser, compile it with preprocessor symbol
.B yydebug
defined.
The amount of
diagnostic output from the parser is regulated by
value
.IR n .
The value 0 reports errors; 1 reports reductions;
higher values (up to 4) include more information about
state transitions.
.TP
.B -v
Create file
.BR y.output ,
containing a description of the parsing tables and of
conflicts arising from ambiguities in the grammar.
.TP
.B -d
Create file
.BR y.tab.h ,
containing
.B #define
statements that associate
.IR yacc -assigned
`token codes' with user-declared `token names'.
Include it in source files other than
.B y.tab.c
to give access to the token codes.
.TP
.BI -s " stem
Change the prefix
.L y
of the file names
.BR y.tab.c ,
.BR y.tab.h ,
.BR y.debug ,
and
.B y.output
to
.IR stem .
.TP
.B -S
Write a parser that uses
Stdio
instead of the
.B print
routines in libc.
.PP
The specification of
.I yacc
itself is essentially the same as the UNIX version
described in the references mentioned below.
Besides the
.B -D
option, the main relevant differences are:
.IP
The interface to the C environment is by default through
.B <libc.h>
rather than
.BR <stdio.h> ;
the
.B -S
option reverses this.
.IP
The parser accepts
.SM UTF
input text (see
.IR utf (7)),
which has a couple of effects.
First, the return value of
.B yylex()
no longer fits in a
.BR short ;
second, the starting value for non-terminals is now 0xE000 rather than 257.
.IP
The generated parser can be recursive: actions can call
.IR yyparse ,
for example to implement a sort of
.B #include
statement in an interpreter.
.IP
Finally, some undocumented inner workings of the parser have been
changed, which may affect programs that know too much about its structure.
.SH FILES
.TF y.debug.xxxxx
.TP
.B y.output
.TP
.B y.tab.c
.TP
.B y.tab.h
.TP
.B y.debug
.TP
.B y.tmp.*
temporary file
.TP
.B y.acts.*
temporary file
.TP
.B \*9/lib/yaccpar
parser prototype
.TP
.B \*9/lib/yaccpars
parser prototype using stdio
.SH SOURCE
.B \*9/src/cmd/yacc.c
.SH "SEE ALSO"
.IR lex (1)
.br
S. C. Johnson and R. Sethi,
``Yacc: A parser generator'',
.I
Unix Research System Programmer's Manual,
Tenth Edition, Volume 2
.br
B. W. Kernighan and Rob Pike,
.I
The UNIX Programming Environment,
Prentice Hall, 1984
.SH BUGS
The parser may not have full information when it writes to
.B y.debug
so that the names of the tokens returned by
.L yylex
may be missing.
|