O'Reilly logo

lex & yacc, 2nd Edition by Tony Mason, John Levine, Doug Brown

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix B. AT&T Yacc

Options

AT&T yacc is distributed with most versions of UNIX, except for the most recent verions of Berkeley UNIX, which have Berkeley yacc. If you’re not sure which version of yacc you have, try running it with no arguments. If it says:

    fatal error: cannot open input file, line 1

it’s AT&T yacc. If it gives you a summary of the command syntax, it’s Berkeley yacc.

Yacc processes a file containing a grammar and generates source code for a parser. By convention, the grammar file has a .y extension. The file that yacc generates is named y.tab.c.

The syntax of the yacc command is:

yacc [options]file

where options are as follows:

-d

Generates the header file y.tab.h that contains definitions of token names.

-l

Omits #line constructs in the generated code.

-t

Includes runtime debugging code when y.tab.c is compiled.

-v

Produces the file y.output, which contains a listing of all of the states in the generated parser and other useful information.

In order to compile the parser generated by yacc, you must supply a main routine and a supporting routine, yyerror. The UNIX library liby.a contains default versions of these routines.

See Chapter 7, A Reference for Yacc Grammars , for information on yacc specifications.

Error Messages

This section discusses correcting problems and errors reported by yacc, aside from the shift/reduce and reduce/reduce errors discussed in Chapter 8, Yacc Ambiguities and Conflicts . The error messages are organized alphabetically.

%d rules never reduced ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required