Go to the first, previous, next, last section, table of contents.

Invoking Zyacc

The command line needed to invoke Zyacc has the format:

zyacc [Options List] yacc-file [yacc-file...]

Here yacc-file specifies the name(s) of the grammar file, usually ending in `.y'. Unless the --output or --yacc options are specified, the name of the generated parser file is created by replacing the `.y' with `.tab.c'. Thus, the `zyacc foo.y' filename yields `foo.tab.c', and the `zyacc hack/foo.y' filename yields `hack/foo.tab.c'.

Option Conventions

A word which constitutes a command-line argument has two possible types: it is a option word if it begin with a `-' or `--' (with certain exceptions noted below), or if it follows an option word which requires an argument. Otherwise it is a non-option word. An option word specifies the value of a Zyacc option; a non-option word specifies a file name.

Option Sources

Besides the command-line, Zyacc can read its options from several different sources. In order of increasing priority these sources are the following:

Options specified by the environment variable ZYACC_OPTIONS overrides the options specified in the `zyacc.opt' file. Options specified in the Zyacc source file override options specified in the `zyacc.opt' file or ZLEX_OPTIONS environment variable. Finally, command-line options always override options specified by all other sources.

Zyacc Options

A list of the available options follows:

--build-display
Display the parameters used to build zyacc and exit.
--debug[=1|0]
-t[1|0]
Output a definition of the macro YYDEBUG into the parser file, so that the debugging facilities are compiled. See section Debugging Your Parser.
--defines[=1|0]
-d[1|0]
Output a .h definitions file containing the semantic value type YYSTYPE and C preprocessor macro definitions for all the token type names defined in the grammar (default: 0). If the parser output file is named `name.c' then this file is named `name.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 yylval. See section Semantic Values of Tokens.
--file-prefix prefix
-b prefix
Specify a prefix to use for all Zyacc output file names. The names are chosen as if the input file were named `prefix.c'.
--grammar[=1|0]
-g[1|0]
Output a reference grammar file to <stdout> and exit (default: 0).
--help
-h
Print summary of options and exit.
--HTML[=1|0]
-H[1|0]
Write a HTML parser description in .html file. This is similar to the --verbose option, but you can use any WWW browser like Netscape or Lynx to browse the parser description file and follow hot links within the file (default: 0).
--lines
Output #line directives in generated parser file (default: 1). If Zyacc puts these directives in the parser file then the C compiler and debuggers can associate errors with your source file, the grammar file. If this option is specified as 0, then errors will be associated with the parser file, treating it an independent source file in its own right.
--longer-rule-prefer[=1|0]
When resolving a reduce-reduce conflict prefer the longer rule (default: 0). If this option is specified as 0, then the reduce-reduce conflicts are resolved in favor of the rule which occurs earlier in the source file.
--output-file outFile
-o outFile
Specify the name outFile for the parser file. The other output files' names are constructed from outfile as described under the --defines and --verbose switches.
--name-prefix prefix
-p prefix
Specify prefix to be used for all external symbols. Rename the external symbols used in the parser so that they start with prefix instead of `yy'. The precise list of symbols renamed is yychar, yydebug, yyerror, yylex, yynerrs, yylval and yyparse. For example, if you use `-p c', the names become cchar, cdebug, and so on. See section Multiple Parsers in the Same Program.
--term-prefix suffix
Specify suffix string to be appended to all external terminal names (default ""). For example, if you specify --term-prefix _TOK, then the string _TOK will be appended to all terminal names exported from the grammar; if you use ID as a terminal name within your grammar, its external name will be ID_TOK.
--verbose[=1|0]
-v[1|0]
Write verbose parser description in .output file (default: 0). The extra output file contains descriptions of the parser states and what is done for each type of look-ahead 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 made by removing `.tab.c' or `.c' from the parser output file name, and adding `.output' instead. Therefore, if the input file is `foo.y', then the parser file is called `foo.tab.c' by default. As a consequence, the verbose output file is called `foo.output'.
--version
-V
Print version number and exit.
--yacc[=1|0]
-y[1|0]
Name output files like YACC (default: 0) Equivalent to `-o y.tab.c'; the parser output file is called `y.tab.c', and the other outputs are called `y.output' and `y.tab.h'. The purpose of this switch is to imitate Yacc's output file name conventions. Thus, the following shell script can substitute for Yacc:
zyacc -y $*

Data Search List

When Zyacc is run, it looks for certain data files (a skeleton file `zyaccskl.c' and an options file `zyacc.opt' (see section Option Sources)) in certain standard directories (the skeleton file must exist, but the option file need not exist). The search list specifying these standard directories is fixed when Zyacc is installed; it can be printed out using Zyacc's `--help' option (see section Zyacc Options).

The search list consists of a list of colon-separated directory names (the directory names may or may not have terminating slashes) or environment variables (starting with a `$'). If a directory name starts with a `$', then the first (only the first) `$' must be repeated. An empty component in the search list specifies the current directory. Typically the search list contains the current directory. Also typically, the environment variable ZYACC_SEARCH_PATH is present in the search list -- this causes Zyacc to check if the variable is set in the environment. If it is, then Zyacc expects it to specify a search list which it recursively searches.

Typically, the search list compiled into Zyacc looks something like the following:

$ZYACC_SEARCH_PATH:.:$HOME:/usr/local/share/zyacc

Since the search list will typically contain an environment variable like ZYACC_SEARCH_PATH it is possible to change the set of standard directories searched by Zyacc even after installation by specifying a value for the variable. For example, if with the above search list, ZYACC_SEARCH_PATH is set to /usr/lib:/usr/opt/lib, then the effective search list becomes:

/usr/lib:/usr/opt/lib:.:$HOME:/usr/local/share/zyacc

Feedback: Please email any feedback to zdu@acm.org.


Go to the first, previous, next, last section, table of contents.