[ Previous | Next | Table of Contents | Index | Library Home |
Legal |
Search ]
Commands Reference, Volume 6
Generates an LALR(1) parsing
program from input consisting of a context-free grammar specification.
yacc [ -b
Prefix ] [ -C ]
[ -d ] [ -l ] [ -NnNumber ] [ -NmNumber ] [ -NrNumber ] [ -p Prefix ] [ -s ] [ -t ] [ -v ] [ -y
Path ] Grammar
The yacc command
converts a context-free grammar specification into a set of tables for a
simple automaton that executes an LALR(1) parsing algorithm. The
grammar can be ambiguous; specified precedence rules are used to break
ambiguities.
You must compile the output file,
y.tab.c, with a C language compiler to produce a
yyparse function. This function must be loaded with the
yylex lexical analyzer, as well as with the main
subroutine and the yyerror error-handling subroutine (you must
provide these subroutines). The lex command is useful for
creating lexical analyzers usable by the yyparse subroutine.
Simple versions of main and yyerror subroutines are
available through the yacc library,
liby.a. Also, yacc can be used to generate
C++ output.
You can compile the
yacc-generated C file (y.tab.c) with the
-DYACC_MSG option to include code necessary to use the Message
Facility. When you use this option during compilation, error messages
generated by the yyparse subroutine and the YYBACKUP
macro are extracted from the yacc_user.cat catalog.
This allows you to receive error
messages in languages other than English in non-English locales. If the
catalog cannot be found or opened, the yyparse and
YYBACKUP subroutines display the default English messages.
The yacc command is
affected by the LANG, LC_ALL, LC_CTYPE, and
LC_MESSAGES environment variables.
-b Prefix
| Use Prefix instead of y as the prefix for all
output file names. The code file y.tab.c, the
header file y.tab.h (created when -d is
specified), and the description file y.output (created when
-v is specified) are changed to
Prefix.tab.c,
Prefix.tab.h, and
Prefix.output, respectively.
|
-C
| Produces the y.tab.C file instead of the
y.tab.c file for use with a C++ compiler. To
use the I/O Stream Library for input and output, define the macro,
_CPP_IOSTREAMS.
|
-d
| Produces the file y.tab.h. This contains
the #define statements that associate the yacc-assigned
token codes with your token names. This allows source files other than
y.tab.c to access the token codes by including this
header file.
|
-l
| Does not include any #line constructs in
y.tab.c. Use this only after the grammar and
associated actions are fully debugged.
|
-NnNumber
| Changes the size of the token and nonterminal names array to
Number. The default value is 8000. Valid values are
only those greater than 8000.
|
-NmNumber
| Changes the size of the memory states array to Number.
Default value is 40000. Valid values are only those greater than
40000.
|
-NrNumber
| Changes the internal buffer sizes to handle large grammars. The
default value is 2000. Valid values are only those greater than
2000.
|
-p Prefix
| Use Prefix instead of yy as the prefix for all
external names created by the yacc command. External names
affected include: yychar, yylval,
yydebug, yyparse( ), yylex( ), and
yyerror( ). (Previously, -p was used to specify
an alternate parser; now, -yPath can be used to
specify an alternate parser.)
|
-s
| Breaks the yyparse function into several smaller
functions. Since its size is somewhat proportional to that of the
grammar, it is possible for the yyparse function to become too
large to compile, optimize, or execute efficiently.
|
-t
| Compiles run-time debugging code. By default, this code is not
included when y.tab.c is compiled. However,
the run-time debugging code is under the control of the preprocessor macro,
YYDEBUG. If YYDEBUG has a nonzero value, the C
compiler (cc) includes the debugging code, regardless of whether
the -t flag is used. YYDEBUG should have a value
of 0 if you don't want the debugging code included by the
compiler. Without compiling this code, the yyparse
subroutine will have a faster operating speed.
The -t flag causes
compilation of the debugging code, but it does not actually turn on the debug
mode. To get debug output, the yydebug variable must be set
either by adding the C language declaration, int yydebug=1 to
the declaration section of the yacc grammar file or by setting
yydebug through dbx.
|
-v
| Prepares the file y.output. It contains a
readable description of the parsing tables and a report on conflicts generated
by grammar ambiguities.
|
-y Path
| Uses the parser prototype specified by Path instead of the
default /usr/lib/yaccpar file. (Previously, -p
was used to specify an alternate parser.)
|
This command returns the following
exit values:
0
| Successful completion.
|
>0
| An error occurred.
|
- The following command:
yacc grammar.y
draws yacc rules from the grammar.y file,
and places the output in y.tab.c.
- The following command:
yacc -d grammar.y
functions the same as example 1, but it also produces the
y.tab.h file which would contain C-style
#define statements for each of the tokens defined in the
grammar.y file.
y.output
| Contains a readable description of the parsing tables and a report on
conflicts generated by grammar ambiguities.
|
y.tab.c
| Contains an output file.
|
y.tab.h
| Contains definitions for token names.
|
yacc.tmp
| Temporary file.
|
yacc.debug
| Temporary file.
|
yacc.acts
| Temporary file.
|
/usr/ccs/lib/yaccpar
| Contains parser prototype for C programs.
|
/usr/ccs/lib/liby.a
| Contains a run-time library.
|
The lex command.
Creating an
Input Language with the lex and yacc Commands in AIX 5L Version
5.1 General Programming Concepts: Writing and Debugging
Programs.
The Example
program for the lex and yacc programs in AIX 5L Version 5.1
General Programming Concepts: Writing and Debugging
Programs.
[ Previous | Next | Table of Contents | Index |
Library Home |
Legal |
Search ]