blob: cbd1eb73ad3c880bca697e547be296500814e178 [file] [log] [blame]
yacc \- yet another compiler-compiler
.B yacc
.I option ...
.I grammar
.I Yacc
converts a context-free grammar and translation code
into a set of
tables for an LR(1) parser and translator.
The grammar may be ambiguous;
specified precedence rules are used to break ambiguities.
The output file,
.BR ,
must be compiled by the C compiler
to produce a program
.LR yyparse .
This program must be loaded with a lexical analyzer function,
.B yylex(void)
(often generated by
.IR lex (1)),
with a
.B main(int argc, char *argv[])
program, and with an error handling routine,
.BR yyerror(char*) .
The options are
.TP "\w'\fL-o \fIoutput\fLXX'u"
.BI -o " output
Direct output to the specified file instead of
.BR .
.BI -D n
Create file
.BR y.debug ,
containing diagnostic messages.
To incorporate them in the parser, compile it with preprocessor symbol
.B yydebug
The amount of
diagnostic output from the parser is regulated by
.IR n .
The value 0 reports errors; 1 reports reductions;
higher values (up to 4) include more information about
state transitions.
.B -v
Create file
.BR y.output ,
containing a description of the parsing tables and of
conflicts arising from ambiguities in the grammar.
.B -d
Create file
.BR ,
.B #define
statements that associate
.IR yacc -assigned
`token codes' with user-declared `token names'.
Include it in source files other than
to give access to the token codes.
.BI -s " stem
Change the prefix
.L y
of the file names
.BR ,
.BR ,
.BR y.debug ,
.B y.output
.IR stem .
.B -S
Write a parser that uses
instead of the
.B print
routines in libc.
.BI -l
Disable #line directives in the generated parser.
.BI -a
Generate a parser that takes an argument of type Yyarg
and passes this argument to each invocation of the lexer
function, yylex. Yyarg contains per-instance state
and a single user-visible member, arg, of type void*.
The specification of
.I yacc
itself is essentially the same as the UNIX version
described in the references mentioned below.
Besides the
.B -D
option, the main relevant differences are:
The interface to the C environment is by default through
.B <libc.h>
rather than
.BR <stdio.h> ;
.B -S
option reverses this.
The parser accepts
input text (see
.IR utf (7)),
which has a couple of effects.
First, the return value of
.B yylex()
no longer fits in a
.BR short ;
second, the starting value for non-terminals is now 0xE000 rather than 257.
The generated parser can be recursive: actions can call
.IR yyparse ,
for example to implement a sort of
.B #include
statement in an interpreter.
Finally, some undocumented inner workings of the parser have been
changed, which may affect programs that know too much about its structure.
.TF y.debug.xxxxx
.B y.output
.B y.debug
.B y.tmp.*
temporary file
.B y.acts.*
temporary file
.B \*9/lib/yaccpar
parser prototype
.B \*9/lib/yaccpars
parser prototype using stdio
.B \*9/src/cmd/yacc.c
.IR lex (1)
S. C. Johnson and R. Sethi,
``Yacc: A parser generator'',
Unix Research System Programmer's Manual,
Tenth Edition, Volume 2
B. W. Kernighan and Rob Pike,
The UNIX Programming Environment,
Prentice Hall, 1984
The parser may not have full information when it writes to
.B y.debug
so that the names of the tokens returned by
.L yylex
may be missing.