Using bison Command In Linux (Examples)

bison command in Linux is basically a parser generator alike yacc. So, it’s also known as the replacement of yacc. The input files should follow the yacc convention of ending with .y extension. Alike yacc, the generated files by this command don’t have a fixed name, but use the prefix of the input file. In case you require to feed C++ code inside the input file, you can name the file ending with C++ like extension, for an instance, .C++, so the bison command will follow the extension and name the output file will also receive .C++ extension at the end.

Syntax of bison command in Linux

bison [OPTION] FILE_NAME

Options available to use with bison command

  • -h | –help: Displays the help information and exits.
  • -V | –version: Displaces version information and exits.
  • -print-localedir: Displays the directory containing locale-dependent data.
  • -print-datadir: Displays the directory containing skeletons and XSLT.
  • -y | -yacc: Emulates POSIX yacc.
  • -W | -warnings[=CATEGORY]: Reprots the warnings falling in specified CATEGORY.
  • -f | -feature[=FEATURE]: Activates miscellaneous features.

Parser to use with bison command

  • -L | -language=LANGUAGE: Specifies the output programming language.
  • -S | -skeletor=FILE: Specifies the skeleton to use.
  • -t | -debug: Used for instrument the parser to trace same as “-Dparse.trace”.
  • -locations: Enables the location support to use with command.
  • -D | -define=NAME[VALUE]: Works similarly to %define NAME “VALUE”.
  • -F | -force-define=NAME[=VALUE]: Used for overriding %define NAME ”VALUE”.
  • -p | -name-prefix=PREFIX: Used for prepending PREFIX to external symbols deprecated by “Dapi.prefix=PREFIX”.
  • -l | -no-lines: Used for denying to generate ‘#line’ directives.
  • -k | -token-table: Used for including a table of token names.

Output options for bison command

  • -defines[=FILE]: Used for producing a header file.
  • -d: It’s also similar to previous one, but users can’t specify a FILE.
  • -r | -report=THINGS: Used for producing details on the automaton.
  • -report-file=FILE: Used for writing report to FILE.
  • -v | -verbose: It works same as ‘-report=state’.
  • -b | -file-prefix=PREFIX: Used for specifying a prefix for output files.
  • -o | -output=FILE: It leaves the output to a specified FILE.
  • -g | -graph[=FILE]: Used for preparing a graph of the automaton.
  • -x | -xml[=FILE]: Used for creating an XML report of the automaton.

Some examples of bison command in Linux

1: Displaying the bison version details on screen

bison -V

2: Displaying help information

bison -h

3: displaying directory that includes locale-dependent data

bison –print-localedir

4: Displaying an XML report of the automaton

bison -x file_name.y