06.01.2015 Views

Manual

Manual

Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9: Invoking Bison 97<br />

9 Invoking Bison<br />

The usual way to invoke Bison is as follows:<br />

bison infile<br />

Here infile is the grammar file name, which usually ends in ‘.y’. The parser file’s name<br />

is made by replacing the ‘.y’ with ‘.tab.c’ and removing any leading directory. Thus, the<br />

‘bison foo.y’ file name yields ‘foo.tab.c’, and the ‘bison hack/foo.y’ file name yields<br />

‘foo.tab.c’. It’s also possible, in case you are writing C++ code instead of C in your grammar<br />

file, to name it ‘foo.ypp’ or ‘foo.y++’. Then, the output files will take an extension<br />

like the given one as input (respectively ‘foo.tab.cpp’ and ‘foo.tab.c++’). This feature<br />

takes effect with all options that manipulate file names like ‘-o’ or ‘-d’.<br />

For example :<br />

bison -d infile.yxx<br />

will produce ‘infile.tab.cxx’ and ‘infile.tab.hxx’, and<br />

bison -d -o output.c++ infile.y<br />

will produce ‘output.c++’ and ‘outfile.h++’.<br />

For compatibility with POSIX, the standard Bison distribution also contains a shell script<br />

called yacc that invokes Bison with the ‘-y’ option.<br />

9.1 Bison Options<br />

Bison supports both traditional single-letter options and mnemonic long option names.<br />

Long option names are indicated with ‘--’ instead of ‘-’. Abbreviations for option names<br />

are allowed as long as they are unique. When a long option takes an argument, like<br />

‘--file-prefix’, connect the option name and the argument with ‘=’.<br />

Here is a list of options that can be used with Bison, alphabetized by short option. It is<br />

followed by a cross key alphabetized by long option.<br />

Operations modes:<br />

‘-h’<br />

‘--help’<br />

Print a summary of the command-line options to Bison and exit.<br />

‘-V’<br />

‘--version’<br />

Print the version number of Bison and exit.<br />

‘--print-localedir’<br />

Print the name of the directory containing locale-dependent data.<br />

‘-y’<br />

‘--yacc’<br />

Act more like the traditional Yacc command. This can cause different diagnostics<br />

to be generated, and may change behavior in other minor ways. Most<br />

importantly, imitate Yacc’s output file name conventions, so that the parser<br />

output file is called ‘y.tab.c’, and the other outputs are called ‘y.output’ and<br />

‘y.tab.h’. Thus, the following shell script can substitute for Yacc, and the<br />

Bison distribution contains such a script for compatibility with POSIX:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!