BISON(1)

πŸ’– NAME πŸ’–

okay so bestie, meet bison β€” the GNU Project parser generator, aka the glow-up replacement for yacc. πŸ‘‘βœ¨


✨ SYNOPSIS ✨

bison [ -b file-prefix ] [ --file-prefix=file-prefix ] [ -d ] [
--defines ] [ -l ] [ --no-lines ] [ -o outfile ] [ --output-file=outfile
] [ -p prefix ] [ --name-prefix=prefix ] [ -t ] [ --debug ] [ -v ] [
--verbose ] [ -V ] [ --version ] [ -y ] [ --yacc ] [ --fixed-output-
files ] file

πŸ¦‹ DESCRIPTION πŸ¦‹

So like, bison is a parser generator in the same lane as yacc(1). The whole vibe is that it should be upwardly compatible with input files that were written for yacc. no cap. πŸ’…

Your input files should follow the yacc convention of ending in .y. But here's the twist that makes it ✨different✨ from yacc: the generated files do not have fixed names. Instead they use the prefix of the input file. So for instance, a grammar description file named parse.y would produce the generated parser in a file named parse.tab.c, instead of yacc's y.tab.c. it's giving main character energy, fr fr. πŸŽ€

This description of the options you can hand to bison is adapted from the node Invocation in the bison.texinfo manual β€” and that one should be taken as authoritative, okay? like, if there's ever a disagreement, that's the queen. πŸ‘‘

bison supports both traditional single-letter options and mnemonic long option names. Long option names are indicated with -- instead of -. Abbreviations for option names are allowed as long as they are unique. And when a long option takes an argument, like --file-prefix, you connect the option name and the argument with =. periodt. 🫢

πŸŽ€ OPTIONS πŸŽ€

  • -b file-prefix, --file-prefix=file-prefix β€” give bison a prefix to use for all of its output file names. The names get chosen as if the input file were named file-prefix.c. πŸ’–
  • -d, --defines β€” write an extra output file stuffed with macro definitions for the token type names defined in the grammar and the semantic value type YYSTYPE, plus a few extern variable declarations. ✨

If the parser output file is named name.c then this file is named name.h.

this output file is essential if you wanna put the definition of yylex in a separate source file, because yylex needs to be able to refer to token type codes and the variable yylval. no notes, that's just how it is. πŸ’…
  • -l, --no-lines β€” don't put any #line preprocessor commands in the parser file. Normally bison puts them in the parser file so that the C compiler and debuggers will associate errors with your source file β€” the grammar file. This option makes them associate errors with the parser file instead, treating it as an independent source file in its own right. 🌸
  • -o outfile, --output-file=outfile β€” specify the name outfile for the parser file. πŸ“

The other output files' names are constructed from outfile as described under the -v and -d switches. iykyk. πŸ¦‹

  • -p prefix, --name-prefix=prefix β€” rename the external symbols used in the parser so they start with prefix instead of yy. The precise list of symbols renamed is yyparse, yylex, yyerror, yylval, yychar, and yydebug. πŸ”₯

For example, if you use -p c, the names become cparse, clex, and so on. slay. πŸ’–

  • -t, --debug β€” output a definition of the macro YYDEBUG into the parser file, so that the debugging facilities are compiled. πŸ›βœ¨
  • -v, --verbose β€” write an extra output file containing verbose descriptions of the parser states and what is done for each type of look-ahead token in that state. πŸ‘€

This file also describes all the conflicts β€” both the ones resolved by operator precedence and the unresolved ones. πŸ’€

The file's name is made by removing .tab.c or .c from the parser output file name, and adding .output instead.

Therefore, if the input file is foo.y, then the parser file is called foo.tab.c by default. As a consequence, the verbose output file is called foo.output. math is mathing. 🌈

  • -V, --version β€” print the version number of bison. ⭐
  • -y, --yacc, --fixed-output-files β€” equivalent to -o y.tab.c; the parser output file is called y.tab.c, and the other outputs are called y.output and y.tab.h. The purpose of this switch is to imitate yacc's output file name conventions. 🧚 So the following shell script can substitute for yacc:
bison -y $*

okay so one more thing: the long-named options can be introduced with + as well as --, for compatibility with previous releases. But eventually support for + will be removed, because it is incompatible with the POSIX.2 standard. so maybe don't get too attached bestie 😭


🌸 FILES 🌸

  • /usr/local/lib/bison.simple β€” simple parser
  • /usr/local/lib/bison.hairy β€” complicated parser

(one of them is simple, one of them is hairy, and honestly? both iconic in their own way. πŸ’œ)


πŸ’œ SEE ALSO πŸ’œ

  • yacc(1)
  • The Bison Reference Manual, included as the file bison.texinfo in the bison source distribution.

πŸ‘‘ DIAGNOSTICS πŸ‘‘

Self explanatory. πŸ’… (yes that's the whole section, she said what she said)


and that's the page bestie!! πŸŽ€ this one comes from the local source in the BISON(1) manual, and there's like no date on it so we're calling it timeless. πŸ¦‹ go forth and generate some parsers, you absolute legend πŸ’–βœ¨πŸ«Ά