OCAMLLEX(1)
π OCAMLLEX(1) π
okay so bestie, welcome to the ocamllex page β it lives in the General Commands Manual and it is literally the OCaml lexer generator. yes, THE one. β¨
π¦ NAME π¦
ocamllex β the OCaml lexer generator, no cap. π
πΈ SYNOPSIS πΈ
ocamllex [ -o output-file ] [ -ml ] filename.mll
β¨ DESCRIPTION β¨
so like. the ocamllex(1) command generates OCaml lexers out of a set of regular expressions that have semantic actions attached to them, in the style of lex(1). it's giving classic, it's giving vintage, we love her. π
when you run ocamllex(1) on the input file lexer.mll, you get OCaml code for a lexical analyzer in the file lexer.ml. boom. that's the whole glow-up. π₯
that file defines one lexing function per entry point in the lexer definition, and those functions have the exact same names as the entry points, fr fr. a lexing function takes a lexer buffer as its argument, and it returns the semantic attribute of the corresponding entry point. that's it, that's the job. π«Ά
lexer buffers are an abstract data type implemented in the standard library module Lexing. and the functions Lexing.from_channel, Lexing.from_string and Lexing.from_function create lexer buffers that read from an input channel, a character string, or any reading function, respectively. three lil besties, three lil sources of input. π
and when you use this in conjunction with a parser generated by ocamlyacc(1), the semantic actions compute a value belonging to the type token defined by the generated parsing module. iconic collaboration honestly. π
π OPTIONS π
the ocamllex(1) command recognizes the following options, bestie, and we are going through every single one:
-mlβ outputs code that does not use OCaml's built-in automata interpreter. instead, the automaton gets encoded by OCaml functions. this one is mainly useful for debuggingocamllex(1)β and using it for production lexers is not recommended. so like, cute for snooping, not for shipping. π-ooutput-file β specify the name of the output file thatocamllex(1)produces. the default is the input file name, with its extension replaced by.ml. so you get a say in where it goes π-qβ quiet mode.ocamllex(1)normally outputs informational messages to standard output, and they get suppressed if you use option-q. shy girl era. π€«-vor-versionβ print version string and exit. π¦-vnumβ print short version number and exit. short and sweet. β-helpor--helpβ display a short usage summary and exit. the tutorial, but tiny. πΈ
π SEE ALSO π
ocamlyacc(1).- The OCaml user's manual, chapter "Lexer and parser generators".
ok that's the whole page, you ate it up, go generate some lexers π
and that's a wrap, bestie β this was OCAMLLEX(1) from the General Commands Manual, and we are obsessed. mwah, bye ππ
π¦ 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