Open In App

bison command in Linux with Examples

Improve
Improve
Like Article
Like
Save
Share
Report

bison command is an replacement for the yacc. It is basically a parser generator similar to yacc. Input files should follow the yacc convention of ending in .y format. Similar to yacc, the generated files do not have fixed names, but instead use the prefix of the input file. Moreover, if you need to put C++ code in the input file, you can end his name by a C++-like extension as .ypp or .y++, then bison will follow your extension to name the output file as .cpp or .c++.

Syntax:

bison [OPTION]... FILE

Operation modes:

  • -h, –help : It display this help and exit.
  • -V, –version : It display version information and exit.
  • –print-localedir : It display directory containing locale-dependent data.
  • –print-datadir : It display directory containing skeletons and XSLT.
  • -y, –yacc : It emulate POSIX Yacc.
  • -W, –warnings[=CATEGORY] : It report the warnings falling in CATEGORY.
  • -f, –feature[=FEATURE] : It activate miscellaneous features.

Parser:

  • -L, –language=LANGUAGE : It specify the output programming language.
  • -S, –skeleton=FILE : It specify the skeleton to use.
  • -t, –debug : It instrument the parser for tracing same as ‘-Dparse.trace’.
  • –locations : It enable location support.
  • -D, –define=NAME[=VALUE] : It similar to ‘%define NAME “VALUE”‘.
  • -F, –force-define=NAME[=VALUE] : It override ‘%define NAME “VALUE”‘.
  • -p, –name-prefix=PREFIX : It prepend PREFIX to the external symbols deprecated by ‘-Dapi.prefix=PREFIX’.
  • -l, –no-lines : It don’t generate ‘#line’ directives.
  • -k, –token-table : It include a table of token names.

Output:

  • –defines[=FILE] : It also produce a header file.
  • -d : It’s likewise but cannot specify FILE (for POSIX Yacc).
  • -r, –report=THINGS : It also produce details on the automaton.
  • –report-file=FILE : It write report to FILE.
  • -v, –verbose : It same as ‘–report=state’.
  • -b, –file-prefix=PREFIX : It specify a PREFIX for output files.
  • -o, –output=FILE : It leave output to FILE.
  • -g, –graph[=FILE] : It also output a graph of the automaton.
  • -x, –xml[=FILE] : It also output an XML report of the automaton (the XML schema is experimental).

Example:

  • bison: For example, the bison grammar file called file.y. By default, bison will create the output file with the same name as the input file, with .tab appended to the name.
    bison file.y 

  • -y: It emulate POSIX Yacc i.e. it created the output file name using the typical yacc convention (y.tab.c), instead of y.tab.cpp by bison.
    bison -y file1.ypp

  • –defines: It is used to generate a header file along with the .c (or .cpp) file.
    bison --defines file.y

  • -p: It is used to add own custom prefix to the external symbols.
    bison -p FILE file.y

  • -r: It is used to generate a report file. The default report file name is file.output
    bison -r all file.y

  • -V: It display the bison version information.
    bison -V

  • –print-localedir: It display directory containing locale-dependent data.
    bison --print-localedir

  • –print-datadir: It display directory containing skeletons and XSLT.
    bison --print-datadir

  • -x: It display an XML report of the automaton (the XML schema is experimental).
    bison -x file.y

  • -g: It display a graph of the automation.
    bison -g file.y

Note:

  • To check for the manual page of bison command, use the following command:
    man bison
  • To check the help page of bison command, use the following command:
    bison --help 


Last Updated : 15 Apr, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads