1yacc(1)                          User Commands                         yacc(1)
2
3
4

NAME

6       yacc - yet another compiler-compiler
7

SYNOPSIS

9       yacc [-dltVv] [-b file_prefix] [-Q [y | n]]
10             [-P parser] [-p sym_prefix] file
11
12

DESCRIPTION

14       The  yacc  command converts a context-free grammar into a set of tables
15       for a simple automaton that executes an LALR(1) parsing algorithm.  The
16       grammar  can be ambiguous. Specified precedence rules are used to break
17       ambiguities.
18
19
20       The output file, y.tab.c, must be compiled by the C compiler to produce
21       a function yyparse(). This program must be loaded with the lexical ana‐
22       lyzer program, yylex(), as well as main() and yyerror(), an error  han‐
23       dling  routine. These routines must be supplied by the user. The lex(1)
24       command is useful for creating lexical analyzers usable by yacc.
25

OPTIONS

27       The following options are supported:
28
29       -b file_prefix    Uses file_prefix instead of y as the prefix  for  all
30                         output  files. The code file y.tab.c, the header file
31                         y.tab.h (created  when  -d  is  specified),  and  the
32                         description  file y.output (created when -v is speci‐
33                         fied), is  changed  to  file_prefix.tab.c,  file_pre‐
34                         fix.tab.h, and file_prefix.output, respectively.
35
36
37       -d                Generates  the  file  y.tab.h with the #define state‐
38                         ments that associate the  yacc  user-assigned  "token
39                         codes"  with  the  user-declared  "token names". This
40                         association allows source files other than y.tab.c to
41                         access the token codes.
42
43
44       -l                Specifies  that the code produced in y.tab.c does not
45                         contain any #line constructs. This option should only
46                         be  used after the grammar and the associated actions
47                         are fully debugged.
48
49
50       -p sym_prefix     Uses sym_prefix instead of yy as the prefix  for  all
51                         external  names  produced by yacc. The names affected
52                         include the functions yyparse(),  yylex()  and  yyer‐
53                         ror(),  and the variables yylval, yychar and yydebug.
54                         (In the remainder of this section,  the  six  symbols
55                         cited  are  referenced using their default names only
56                         as a notational convenience.) Local names can also be
57                         affected  by  the  -p  option. However, the -p option
58                         does not affect #define symbols generated by yacc.
59
60
61       -P parser         Allows you to  specify  the  parser  of  your  choice
62                         instead  of  /usr/share/lib/ccs/yaccpar. For example,
63                         you can specify:
64
65                           example% yacc -P ~/myparser parser.y
66
67
68
69
70       -Q[y|n]           The -Qy option puts the version stamping  information
71                         in  y.tab.c.  This allows you to know what version of
72                         yacc built the file. The  -Qn  option  (the  default)
73                         writes no version information.
74
75
76       -t                Compiles  runtime  debugging code by default. Runtime
77                         debugging code is always generated in  y.tab.c  under
78                         conditional  compilation  control.  By  default, this
79                         code  is  not  included  when  y.tab.c  is  compiled.
80                         Whether  or  not  the  -t option is used, the runtime
81                         debugging code is under the control of  YYDEBUG  ,  a
82                         preprocessor symbol. If YYDEBUG has a non-zero value,
83                         then the debugging code is included. If its value  is
84                         0, then the code is not included. The size and execu‐
85                         tion time of a program produced without  the  runtime
86                         debugging code is smaller and slightly faster.
87
88
89       -v                Prepares the file y.output, which contains a descrip‐
90                         tion of the parsing tables and a report on  conflicts
91                         generated by ambiguities in the grammar.
92
93
94       -V                Prints  on  the  standard  error  output  the version
95                         information for yacc.
96
97

OPERANDS

99       The following operand is required:
100
101       file    A path name of a  file  containing  instructions  for  which  a
102               parser is to be created.
103
104

EXAMPLES

106       Example 1 Accessing the yacc Library
107
108
109       Access  to the yacc library is obtained with library search operands to
110       cc. To use the yacc library main:
111
112
113         example% cc y.tab.c -ly
114
115
116
117
118       Both the lex library and the yacc library contain main. To  access  the
119       yacc main:
120
121
122         example% cc y.tab.c lex.yy.c -ly -ll
123
124
125
126
127       This  ensures that the yacc library is searched first, so that its main
128       is used.
129
130
131
132       The historical yacc libraries have contained two simple functions  that
133       are  normally  coded by the application programmer. These library func‐
134       tions are similar to the following code:
135
136
137         #include <locale.h>
138         int main(void)
139         {
140                 extern int yyparse();
141
142                 setlocale(LC_ALL, "");
143
144                 /* If the following parser is one created by lex, the
145                    application must be careful to ensure that LC_CTYPE
146                    and LC_COLLATE are set to the POSIX locale.  */
147                 (void) yyparse();
148                 return (0);
149         }
150
151         #include <stdio.h>
152
153         int yyerror(const char *msg)
154         {
155                 (void) fprintf(stderr, "%s\n", msg);
156                 return (0);
157         }
158
159

ENVIRONMENT VARIABLES

161       See environ(5) for descriptions of the following environment  variables
162       that affect the execution of yacc: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES,
163       and NLSPATH.
164
165
166       yacc can handle characters from EUC primary and supplementary  codesets
167       as  one-token  symbols.  EUC  codes can only be single character quoted
168       terminal symbols. yacc expects  yylex()  to  return  a  wide  character
169       (wchar_t) value for these one-token symbols.
170

EXIT STATUS

172       The following exit values are returned:
173
174       0     Successful completion.
175
176
177       >0    An error occurred.
178
179

FILES

181       y.output      state transitions of the generated parser
182
183
184       y.tab.c       source code of the generated parser
185
186
187       y.tab.h       header file for the generated parser
188
189
190       yacc.acts     temporary file
191
192
193       yacc.debug    temporary file
194
195
196       yacc.tmp      temporary file
197
198
199       yaccpar       parser prototype for C programs
200
201

ATTRIBUTES

203       See attributes(5) for descriptions of the following attributes:
204
205
206
207
208       ┌─────────────────────────────┬─────────────────────────────┐
209       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
210       ├─────────────────────────────┼─────────────────────────────┤
211       │Availability                 │SUNWbtool                    │
212       ├─────────────────────────────┼─────────────────────────────┤
213       │Interface Stability          │Committed                    │
214       ├─────────────────────────────┼─────────────────────────────┤
215       │Standard                     │See standards(5).            │
216       └─────────────────────────────┴─────────────────────────────┘
217

SEE ALSO

219       lex(1), attributes(5), environ(5), standards(5)
220

DIAGNOSTICS

222       The  number  of reduce-reduce and shift-reduce conflicts is reported on
223       the standard error output. A more  detailed  report  is  found  in  the
224       y.output  file.  Similarly,  if  some  rules are not reachable from the
225       start symbol, this instance is also reported.
226

NOTES

228       Because file names are fixed, at most one yacc process can be active in
229       a given directory at a given time.
230
231
232       Users are encouraged to avoid using $ as part of any identifier name.
233
234
235
236SunOS 5.11                        24 Aug 2009                          yacc(1)
Impressum