yacc - Use the yacc compiler

Format

yacc [-dhlmqtv] [-b file.prefix] [-D file.h] [-o file.c] [-p prefix] [-P yyparse.c] [-v stats] gram.y

Description

yacc converts a context-free LALR(1) grammar that is found in the input file gram.y into a set of tables that together with additional C code constitute a parser to recognize that grammar. If you specify an input file that is named -, yacc reads the grammar from the standard input. By default, yacc places the parsing tables and associated C code into the file y.tab.c.

For more information about writing parsers that use yacc, see Generating a parser using yacc in z/OS UNIX System Services Programming Tools.

Options

-b file_prefix
Uses file_prefix instead of y as the prefix for all output file names. For example, yacc names the parsing table file_prefix.tab.c rather than y.tab.h.
-D file.h
Generates the file file.h, which contains the constant definition statements for token names. This lets other modules of a multimodule program access these symbolic names. This is the same as -d, except that the user specifies the include file name.
-d
Generates the file y.tab.h, which contains the constant definition statements for token names. This lets other modules of a multimodule program access these symbolic names. This is the same as -D, except that the user does not specify the header file name.
-h
Displays a brief list of the options and quits.
-l
Disables the generation of #line statements in the parser output file, which are used to produce correct line numbers in compiler error messages from gram.y.
-m
Displays memory usage, timing, and table size statistics on the standard output.
-o file.c
Places the generated parser tables into file.c instead of the default y.tab.c.
-P yyparse.c
Indicates that the C parser template is found in the file yyparse.c. If you do not specify this option, this parser template is located in /etc/yyparse.c.
-p prefix
By default, yacc prefixes all variables and defined parameters in the generated parser code with the two letters yy (or YY). In order to have more than one yacc-generated parser in a single program, each parser must have unique variable names. -p uses the string prefix to replace the yy prefix in variable names. prefix should be entirely in lowercase because yacc uses an uppercase version of the string to replace all YY variables. We recommend a short prefix (such as zz) because some C compilers have name length restrictions for identifiers. You can also set this identifier with a %prefix directive in the grammar file.
-q
Disables the printing of warning messages.
-t
Enables debugging code in the generated parser. yacc does not normally compile this code because it is under the control of the preprocessor symbol YYDEBUG.

This option is therefore equivalent to either setting YYDEBUG on the C compiler command line or specifying #define YYDEBUG statement in the first section of the grammar.

-V stats
Writes a verbose description of the parsing tables and any possible conflicts to the file stats.

This is the same as -v except that the user specifies the file name.

-v
writes a verbose description of the parsing tables and any possible conflicts to the file y.output.

Files

yacc uses the following files:

/usr/lib/liby.a
yacc function library.
/usr/lib/libyxp.a
yacc archive library with functions that are compiled with XPLINK. Includes two versions: 64-bit addressing mode and 31-bit addressing mode.
y.output
Default statistics file when you specify -v.
y.tab.c
Default file for the generated parser.
y.tab.h
Default header file when you specify -d.
/etc/yyparse.c
Default parser template.

Localization

yacc uses the following localization environment variables:
  • LANG
  • LC_ALL
  • LC_CTYPE
  • LC_MESSAGES
  • LC_SYNTAX
  • NLSPATH

Usage notes

In a double-byte environment, yacc can use double-byte characters, although this practice is possibly nonportable.

  1. Comments and rule names can contain double-byte characters.
  2. double-byte characters can be used in symbolic token names (generated by %token statements only if the C preprocessor and compiler will interpret them correctly. Symbolic token names are converted directly into #define statements and are then interpreted by the preprocessor and the compiler.
  3. You can use double-byte characters as literal token definitions (a double-byte character that is surrounded by apostrophes), although this will generate a warning and might create a conflict with an assigned token name.

Exit values

0
Successful completion
1
Failure due to any of the following reasons:
  • number rules never reduced
  • Reduce-reduce conflict
  • Shift-reduce conflict
  • NAME should have been defined earlier
  • \000 not permitted
  • EOF encountered while processing %union
  • EOF in string or character constant
  • EOF inside comment
  • Use of $number not permitted
  • Nonterminal number, entry at number
  • Action does not terminate
  • Bad %start construction
  • Bad syntax in %type
  • Bad syntax on $<ident> clause
  • Bad syntax on first rule
  • Inability to find parser
  • Inability to open input file
  • Inability to open table file
  • Inability to open temporary file
  • Inability to open y.output
  • Inability to place goto
  • Inability to reopen action temporary file
  • Default action causes potential type clash
  • EOF before %}
  • %prec syntax not permitted
  • \nnn construction not permitted
  • Comment not permitted
  • Option not permitted
  • Incorrect or missing ' or "
  • Incorrect rule: missing semicolon, or |?
  • Internal yacc error
  • Incorrect escape, or incorrect reserved word
  • Item too big
  • More than number rules
  • Must return a value, since LHS has a type
  • Must specify type for name
  • Must specify type of $number
  • Newline in string.
  • No space in action table
  • Nonterminal symbol not permitted after %prec
  • Nonterminal symbol never derives any token string
  • Nonterminal symbol not defined
  • Optimizer cannot open temporary file
  • Out of space in optimizer
  • Out of state space
  • Redeclaration of precedence of symbol
  • Redeclaration of type of symbol
  • Syntax error
  • Token incorrect on LHS of grammar rule
  • Too many characters in ID's and literals
  • Too many look-ahead sets
  • Too many nonterminals
  • Too many states
  • Too many terminals
  • Type redeclaration of nonterminal symbol
  • Type redeclaration of token symbol
  • Unexpected EOF before %
  • Unterminated <...> clause
  • Working set overflow
  • yacc state or nolook error

Messages

Possible error messages include:
No input file
You did not specify a grammar file gram.y on the command line.
No parser produced
Analysis of the input grammar shows that it contains inaccessible or ungrounded nonterminal symbols. Check the preceding report and revise the grammar.
Out of memory at size bytes
The specified grammar is too complex to process within the memory resources of the current configuration.

Limits

yacc dynamically allocates all internal tables so that grammar size and complexity are limited only by available memory.

Portability

POSIX.2, POSIX.2 C-Language Development Utilities Option, X/Open Portability Guide, UNIX systems.

The -D, -h, -m, -p, -q, -S, -s, and -v options are extensions of the POSIX standard.

Related information

lex