yacc

parser generator language 

Command


SYNOPSIS

yacc [-dlhmqstvw] [-LC] [-b prefix] [-D definitions] [-o codefile] [-p prefix] [-P proto] [-S statesfile] [-V stats] [-W filename] gram.y


DESCRIPTION

The yacc utitlity converts a context-free LALR(1) grammar found in the input file gram.y into a set of tables that, together with additional prototype code, constitute a parser to recognize that grammar. If you give - as the input file, yacc reads the grammar from the standard input.

yacc can generate parsers in C or C++ and supports loadable resources for Microsoft Windows. The language in use determines the name of the file containing the prototype code, and the name of the code file. With the -d option, or when C++ code is requested, an additional definitions file is written.

Language Codefile Definitions Prototype

C ytab.c ytab.h ROOTDIR/etc/yyparse.c
C++ ytab.cpp ytab.hpp ROOTDIR/etc/yyparse.cpp

For detailed information on writing parsers using yacc, see the

YACC Programming Guide

.

By default, yacc generates C code. When you specify the -LC option, it generates C++ code. Since the interfaces to the code depend on the language being used, you should see the miscellaneous reference pages for yacc and mks_yaccplus for interfaces to the C and C++ parsers, respectively.

Options

-b prefix 

uses prefix instead of y as the prefix for all output file names. For example, the parsing table would be named prefixtab.c rather than ytab.c.

-d 

generates the definitions file which contains the definitions for token names. This allows other modules of a multi-module program to access these symbolic names. With C++ output, the -d option is automatically enabled and a definitions file is always generated.

-D file 

similar to -d, except that the definition is written to file instead of the default definitions file name.

-h 

prints a brief list of the options and quits.

-LC 

generates C++ code.

-l 

disables the generation of #line directives in the parser output file, which YACC uses to produce correct line numbers in compiler error messages from gram.y.

-m 

prints memory usage, timing, and table size statistics on the standard output.

-o file 

places the generated parser tables into file instead of the default code file.

-p prefix 

changes the prefix. By default, YACC prefixes all variables and defined parameters in the generated parser code by the two letters yy (or YY). To have more than one yacc-generated parser in a single program, it is necessary that each parser 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 to replace all YY variables. You can also set the prefix with a %prefix directive in the grammar file.

-P proto 

tells YACC to use the parser template code in the proto file instead of the language default.

-q 

disables the printing of warning messages.

-s 

write a State Description to the states.out file. This file is indexed by pointers in the table yyStates, so that any state can be quickly read and displayed. For more information, see

Tracing Your YACC Parser

in the

YACC Programming Guide

.

-S statesfile 

is identical to -s except that the State Description is written to statesfile.

-t 

enables debugging code in the generated parser. This code is normally omitted because it is under the control of the preprocessor symbol YYDEBUG. This option is equivalent to either setting YYDEBUG on the compiler command line or defining YYDEBUG in the first section of the grammar.

-v 

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

-v stats 

is identical to -v except that the verbose description is written to the stats file.

-w 

produces a Microsoft Windows compatible resource output file (with the default name lex_yy.rc) in addition to the default output file.

-W filename 

writes a Microsoft Windows compatible resource output file to the specified filename.


DIAGNOSTICS

The exit status of yacc is 0 if the parser is generated; otherwise, the status is 1. The following diagnostics may be generated by yacc:

No input file 

No grammar file gram.y was specified on the command line.

No parser produced 

Analysis of the input grammar shows that it contains inaccessible or ungrounded non-terminal 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.

Missing [option] after -[option

A missing specification after one or more of the options -b, -D, -o, -p, -P, -S, -V, and -W.


FILES

y.out 

default statistics file when you specify -v

ytab.c 

default code file for the generated C parser

ytab.h 

default definitions file when you specify the -d option

ytab.cpp 

default code file for the generated C++ parser.

ytab.hpp 

default definitions file for the generated C++ parser.

ytab.rc 

default resource file when the -w option is specified.

ROOTDIR/etc/yyparse.c 

default C prototype parser.

ROOTDIR/etc/yyparse.cpp 

default C++ prototype parser.


LIMITS

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


PORTABILITY

Windows 8.1. Windows Server 2012 R2. Windows 10. Windows Server 2016. Windows Server 2019. Windows 11. Windows Server 2022. All UNIX systems. POSIX.2.

The -D, -h, -m, -p, -PC, -q, -V, -w, and -W options are specific to MKS YACC.

The ability to generate Microsoft Windows compatible resource files is specific to MKS YACC.


SEE ALSO

Commands:
lex

Miscellaneous:
mks_yaccplus, yacc

YACC Programming Guide


PTC MKS Toolkit 10.4 Documentation Build 39.