OCAMLYACC(1)
π OCAMLYACC β the OCaml parser generator, bestie π
okay so picture this: it's ocamlyacc(1), from the General Commands Manual, and she is literally the parser generator for OCaml. she takes your grammar and turns it into an actual parser. no cap. β¨
π¦ SYNOPSIS π¦
ocamlyacc [ -b prefix ] [ -q ] [ -v ] [ -version ] [ -vnum ]
filename.mly
πΈ DESCRIPTION πΈ
so the ocamlyacc(1) command produces a parser from a LALR(1) context-free grammar specification with attached semantic actions β yes, in the style of yacc(1), she's giving classic but make it OCaml π
say your input file is grammar.mly. run ocamlyacc on it and boom: you get OCaml code for a parser in the file grammar.ml, plus its interface in the file grammar.mli. iconic behaviour tbh.
the generated module defines one parsing function per entry point in the grammar. these functions have the same names as the entry points. main character energy, matching names and everything π
and what do those parsing functions take? listen:
- a lexical analyzer β a function from lexer buffers to tokens
- a lexer buffer
and they return the semantic attribute of the corresponding entry point. that's the whole vibe.
quick lore drop: lexical analyzer functions are usually generated from a lexer specification by the ocamllex(1) program. lexer buffers are an abstract data type implemented in the standard library module Lexing. and tokens are values from the concrete type token, defined in the interface file grammar.mli produced by ocamlyacc(1). it's all connected, iykyk π§
β¨ OPTIONS β¨
the ocamlyacc(1) command recognizes the following options, and we're going through every single one because we don't skip π
-bprefix β name the output filesprefix.ml,prefix.mli,prefix.output, instead of doing the default naming convention thing. custom names, your rules π-qβ ngl bestie this option has no effect. that's it. that's the whole option. she's just there π«Ά--strictβ reject grammars with conflicts. no conflict-having in this house, periodt π«-vβ generate a description of the parsing tables AND a report on conflicts resulting from ambiguities in the grammar. the description gets put in the filegrammar.output. receipts!! π₯-versionβ print version string and exit. bye π-vnumβ print short version number and exit. shorter bye π¨-β read the grammar specification from standard input. the default output file names in that case arestdin.mlandstdin.mli. fed straight from stdin, we love a flexible queen π--file β process file as the grammar specification, even if its name starts with a dash (-) character.
β οΈ heads up: this option must be the last one on the command line. not negotiable, it goes last, that's the rule π
π SEE ALSO π
ocamllex(1)β her bestie fr fr- The OCaml user's manual, chapter "Lexer and parser generators" π
and that's the page!! π generated straight from the General Commands Manual, OCAMLYACC(1), and dated OCAMLYACC(1) β wait no, that's the footer, which is also OCAMLYACC(1). anyway, go build a parser bestie, you're gonna ate πβ¨π¦
π¦ where this page comes from
- alpine 3.22: ocaml5-doc 5.3.0-r0 Β· LGPL-2.1-or-later WITH OCaml-LGPL-linking-exception
- alpine 3.23: ocaml5-doc 5.4.0-r0 Β· LGPL-2.1-or-later WITH OCaml-LGPL-linking-exception
- alpine 3.24: ocaml5-doc 5.4.1-r0 Β· LGPL-2.1-or-later WITH OCaml-LGPL-linking-exception
- arch rolling: ocaml 5.5.0-1 Β· LGPL2.1 AND custom: QPL-1.0
- centos-stream 10: ocaml-docs 5.2.0-5.el10 Β· LGPL-2.1-or-later WITH OCaml-LGPL-linking-exception
- debian trixie: ocaml 5.3.0-3 Β· LGPL-2.1-OCaml
- fedora 43: ocaml-docs 5.3.0-4.fc43 Β· LGPL-2.1-or-later WITH OCaml-LGPL-linking-exception
- fedora 44: ocaml-docs 5.4.0-2.fc44 Β· LGPL-2.1-or-later WITH OCaml-LGPL-linking-exception
- nixos 26.05: ber-metaocaml 153
- nixos 26.05: ocaml 5.4.1
- nixpkgs unstable: ber-metaocaml 153
- nixpkgs unstable: ocaml 5.5.1
- nixpkgs unstable: ocaml-solo5 1.3.5
- ubuntu questing: ocaml 5.3.0-3
- ubuntu resolute: ocaml 5.4.0-3ubuntu1 Β· LGPL-2.1-OCaml
- ubuntu stonking: ocaml 5.4.1-1ubuntu1 Β· LGPL-2.1-OCaml
- Copyright 1996 Institut National de Recherche en Informatique et
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms