ref: c3ba64f6935322f09b6de5c2285544fd471c605d
dir: /sys/man/1/yacc/
.TH YACC 1 .SH NAME yacc \- yet another compiler-compiler .SH SYNOPSIS .B yacc [ .I option ... ] .I grammar .SH DESCRIPTION .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. .PP The output file, .BR y.tab.c , 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*) . .PP The options are .TP "\w'\fL-o \fIoutput\fLXX'u" .BI -o " output Direct output to the specified file instead of .BR y.tab.c . .TP .BI -D n Create file .BR y.debug , containing diagnostic messages. To incorporate them in the parser, compile it with preprocessor symbol .B yydebug defined. The amount of diagnostic output from the parser is regulated by value .IR n . The value 0 reports errors; 1 reports reductions; higher values (up to 4) include more information about state transitions. .TP .B -v Create file .BR y.output , containing a description of the parsing tables and of conflicts arising from ambiguities in the grammar. .TP .B -d Create file .BR y.tab.h , containing .B #define statements that associate .IR yacc -assigned `token codes' with user-declared `token names'. Include it in source files other than .B y.tab.c to give access to the token codes. .TP .BI -s " stem Change the prefix .L y of the file names .BR y.tab.c , .BR y.tab.h , .BR y.debug , and .B y.output to .IR stem . .TP .B -S Write a parser that uses Stdio instead of the .B print routines in libc. .PP 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: .IP The interface to the C environment is by default through .B <libc.h> rather than .BR <stdio.h> ; the .B -S option reverses this. .IP The parser accepts .SM UTF input text (see .IR utf (6)), 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. .IP The generated parser can be recursive: actions can call .IR yyparse , for example to implement a sort of .B #include statement in an interpreter. .IP Finally, some undocumented inner workings of the parser have been changed, which may affect programs that know too much about its structure. .SH FILES .TF /sys/lib/yaccpars .TP .B y.output .TP .B y.tab.c .TP .B y.tab.h .TP .B y.debug .TP .B y.tmp.* temporary file .TP .B y.acts.* temporary file .TP .B /sys/lib/yaccpar parser prototype .TP .B /sys/lib/yaccpars parser prototype using stdio .SH SOURCE .B /sys/src/cmd/yacc.c .SH "SEE ALSO" .IR lex (1) .br S. C. Johnson and R. Sethi, ``Yacc: A parser generator'', .I Unix Research System Programmer's Manual, Tenth Edition, Volume 2 .br B. W. Kernighan and Rob Pike, .I The UNIX Programming Environment, Prentice Hall, 1984 .SH BUGS 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.