yacc Command yacc Parser generator yacc [option ...] file cc y.tab.c [-ly] Many programs process highly structured input according to given rules. Compilers are a familiar example. Two of the most com- plicated parts of such programs are lexical analysis and parsing (sometimes called syntax analysis). The COHERENT system includes two powerful tools called lex and yacc to assist you in perfor- ming these tasks. lex takes a set of lexical rules and writes a lexical analyzer, whereas yacc takes a set of parsing rules and writes a parser; both output C source code that can be compiled into a full program. The term yacc is an acronym for ``yet another compiler-com- piler''. In brief, the yacc input file describes a context free grammar using a BNF-like syntax. The output is a file y.tab.c; it contains the definition of a C function yyparse(), which par- ses the language described in file. The output is ready for processing by the C compiler cc. Ambiguities in the grammar are reported to the user, but resolved automatically by precedence rules. The user must provide a lexical scanner yylex(), which you may generate with lex. The yacc library includes default definitions of main, yylex, and yyerror, and may be included with the option -ly on the cc command line. yacc recognizes the following options: -d Enable debugging output; implies -v. -hdr headerfile Put the header output in headerfile instead of y.tab.h. -l listfile Place a description of the state machine, tokens, parsing actions, and statistics in file listfile. -st Print statistics on the standard output. -v Verbose option. Like -l, but places the listing in file y.output by default. The following options are useful if table overflow messages ap- pear: -nterms N Allow for N nonterminals; default, 100. -prods N Allow for N productions (rules); default, 175. -states N Allow for N states; default, 300. COHERENT Lexicon Page 1
yacc Command yacc -terms N Allow for N terminal symbols; default 100. -types N Allow for N types; default, ten. ***** Files ***** y.tab.c -- C source output y.tab.h -- Default C header output y.output -- Default listing output /lib/yyparse.c -- Protoparser /tmp/y[ao]* -- Temporaries /usr/include/action.h -- Header referenced by protoparser /usr/lib/liby.a -- Library ***** See Also ***** cc, commands, lex Introduction to yacc, Yet Another Compiler-Compiler DeRemer F, Pennello TJ: Efficient computation of LALR(1) lookahead sets. SIGPLAN conference, 1979. ***** Diagnostics ***** yacc reports the number of R/R (reduce/reduce) and S/R (shift/reduce) conflicts (ambiguities) on the standard error stream. COHERENT Lexicon Page 2