SMLLEX(1)
β¨ NAME β¨
smllex β the lexical analyzer generator for SML# π
π¦ SYNOPSIS π¦
smllex [-o file] filename ...
πΈ DESCRIPTION πΈ
Okay bestie, so SMLLex is a lexical analyzer generator, and it's literally living in the style of ML-Lex. It takes input files that were designed for ML-Lex, no notes. β¨
The programs it generates? Compilable by the SML# compiler, periodt. They're compatible with the ones ML-Lex spits out, with a few exceptions β so like, mostly the same energy but not 100% identical, iykyk.
When you hand it multiple input files, each one gets read separately and each one yields its own separate program. Not me bundling them together, no ma'am. By default, the output file name is the input file name with a .sml suffix appended to it. Easy.
Heads up bestie π«Ά β to compile the generated program with SML#, you need an interface file (a .smi file). The EXAMPLES section below has the deets.
π OPTIONS π
-ofilename β sets the output file name of the first input. That's it, that's the whole option, she's simple and she serves. π
π EXAMPLES π
Here's a minimal little input file, ex.lex, and honestly? She's cute:
type lexresult = bool option
fun eof () = NONE
%%
%structure ExampleLex
%%
"T" => (SOME true);
"F" => (SOME false);
So you apply this file to smllex like:
smllex ex.lex
and boom π₯ you obtain a program named ex.lex.sml. To compile it, you need to create this ex.lex.smi file yourself β yes, by hand, bestie, no cap:
_require "basis.smi"
structure ExampleLex =
struct
exception LexError
val makeLexer : (int -> string) -> unit -> bool option
end
Now π¦ plot twist π¦ β when your .lex file has an %arg directive, like for example:
type lexresult = bool option
fun eof {inverse} = NONE
%%
%structure Example2Lex
%arg ({inverse});
%%
"T" => (SOME (if inverse then false else true));
"F" => (SOME (if inverse then true else false));
then the generated makeLexer function takes an additional argument. The way that it just... does that:
_require "basis.smi"
structure Example2Lex =
struct
exception LexError
val makeLexer : (int -> string) -> {inverse : bool}
-> unit -> bool option
end
Slay. π
π HISTORY π
SMLLex is a derivative of ML-Lex, which was originally developed by Andrew W. Appel, James S. Mattson, and David R. Tarditi. Legends, fr fr. π«Ά
The major changes from the original ML-Lex include the following:
- The command line option
-ois added. β¨ - The character position starts with
0, not2. (not me being zero-indexed, iconic behavior) - The generated program does not use Unsafe features of SML/NJ. π«
π SEE ALSO π
smlyacc(1)- A lexical analyzer generator for Standard ML, available at
https://www.smlnj.org/doc/ML-Lex/manual.html - SML# Document, available at
https://www.pllab.riec.tohoku.ac.jp/smlsharp/docs/
okay that's the whole page bestie, ily, go generate some lexers π this was the General Commands Manual situation, SMLLEX(1), section 1 of the manual β mwah, take care of her ππ¦β¨
π¦ where this page comes from
- debian trixie: smlsharp 4.1.0-1+b1 Β· MIT
- ubuntu jammy: smlsharp 4.0.0+git20211227.5af5945b-1 Β· MIT
- ubuntu noble: smlsharp 4.0.0+git20211227.5af5945b-2 Β· MIT
- ubuntu questing: smlsharp 4.1.0-1
- ubuntu resolute: smlsharp 4.1.0-1.1 Β· MIT
- ubuntu stonking: smlsharp 4.1.0-1.1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms