Blob


1 .TH YACC 1
2 .SH NAME
3 yacc \- yet another compiler-compiler
4 .SH SYNOPSIS
5 .B yacc
6 [
7 .I option ...
8 ]
9 .I grammar
10 .SH DESCRIPTION
11 .I Yacc
12 converts a context-free grammar and translation code
13 into a set of
14 tables for an LR(1) parser and translator.
15 The grammar may be ambiguous;
16 specified precedence rules are used to break ambiguities.
17 .PP
18 The output file,
19 .BR y.tab.c ,
20 must be compiled by the C compiler
21 to produce a program
22 .LR yyparse .
23 This program must be loaded with a lexical analyzer function,
24 .B yylex(void)
25 (often generated by
26 .MR lex (1) ),
27 with a
28 .B main(int argc, char *argv[])
29 program, and with an error handling routine,
30 .BR yyerror(char*) .
31 .PP
32 The options are
33 .TP "\w'\fL-o \fIoutput\fLXX'u"
34 .BI -o " output
35 Direct output to the specified file instead of
36 .BR y.tab.c .
37 .TP
38 .BI -D n
39 Create file
40 .BR y.debug ,
41 containing diagnostic messages.
42 To incorporate them in the parser, compile it with preprocessor symbol
43 .B yydebug
44 defined.
45 The amount of
46 diagnostic output from the parser is regulated by
47 value
48 .IR n .
49 The value 0 reports errors; 1 reports reductions;
50 higher values (up to 4) include more information about
51 state transitions.
52 .TP
53 .B -v
54 Create file
55 .BR y.output ,
56 containing a description of the parsing tables and of
57 conflicts arising from ambiguities in the grammar.
58 .TP
59 .B -d
60 Create file
61 .BR y.tab.h ,
62 containing
63 .B #define
64 statements that associate
65 .IR yacc -assigned
66 `token codes' with user-declared `token names'.
67 Include it in source files other than
68 .B y.tab.c
69 to give access to the token codes.
70 .TP
71 .BI -s " stem
72 Change the prefix
73 .L y
74 of the file names
75 .BR y.tab.c ,
76 .BR y.tab.h ,
77 .BR y.debug ,
78 and
79 .B y.output
80 to
81 .IR stem .
82 .TP
83 .B -S
84 Write a parser that uses
85 Stdio
86 instead of the
87 .B print
88 routines in libc.
89 .TP
90 .BI -l
91 Disable #line directives in the generated parser.
92 .TP
93 .BI -a
94 Generate a parser that takes an argument of type Yyarg
95 and passes this argument to each invocation of the lexer
96 function, yylex. Yyarg contains per-instance state
97 and a single user-visible member, arg, of type void*.
98 .PP
99 The specification of
100 .I yacc
101 itself is essentially the same as the UNIX version
102 described in the references mentioned below.
103 Besides the
104 .B -D
105 option, the main relevant differences are:
106 .IP
107 The interface to the C environment is by default through
108 .B <libc.h>
109 rather than
110 .BR <stdio.h> ;
111 the
112 .B -S
113 option reverses this.
114 .IP
115 The parser accepts
116 .SM UTF
117 input text (see
118 .MR utf (7) ),
119 which has a couple of effects.
120 First, the return value of
121 .B yylex()
122 no longer fits in a
123 .BR short ;
124 second, the starting value for non-terminals is now 0xE000 rather than 257.
125 .IP
126 The generated parser can be recursive: actions can call
127 .IR yyparse ,
128 for example to implement a sort of
129 .B #include
130 statement in an interpreter.
131 .IP
132 Finally, some undocumented inner workings of the parser have been
133 changed, which may affect programs that know too much about its structure.
134 .SH FILES
135 .TF y.debug.xxxxx
136 .TP
137 .B y.output
138 .TP
139 .B y.tab.c
140 .TP
141 .B y.tab.h
142 .TP
143 .B y.debug
144 .TP
145 .B y.tmp.*
146 temporary file
147 .TP
148 .B y.acts.*
149 temporary file
150 .TP
151 .B \*9/lib/yaccpar
152 parser prototype
153 .TP
154 .B \*9/lib/yaccpars
155 parser prototype using stdio
156 .SH SOURCE
157 .B \*9/src/cmd/yacc.c
158 .SH "SEE ALSO"
159 .MR lex (1)
160 .br
161 S. C. Johnson and R. Sethi,
162 ``Yacc: A parser generator'',
163 .I
164 Unix Research System Programmer's Manual,
165 Tenth Edition, Volume 2
166 .br
167 B. W. Kernighan and Rob Pike,
168 .I
169 The UNIX Programming Environment,
170 Prentice Hall, 1984
171 .SH BUGS
172 The parser may not have full information when it writes to
173 .B y.debug
174 so that the names of the tokens returned by
175 .L yylex
176 may be missing.