smllex(1)

smllex1

The lexical analyzer generator for sml#

Usage

smllex [-o file] filename ...

Overview

SMLLex is a lexical analyzer generator in the style of ML-Lex. It accepts input files designed for ML-Lex. Generated programs can be compiled by the SML# compiler. They are compatible to those of ML-Lex with a few exceptions.

When multiple input files are given, each input file is separately read and yields a separate program. By default, the output file name is obtained by appending .sml suffix to the input file name.

To compile the generated program with SML#, an interface file (.smi file) is needed. See EXAMPLES for details.

Options

-o filename

Set the output file name of the first input.

Examples

The following is a minimal example of an input file ex.lex:

type lexresult = bool option
fun eof () = NONE
%%
%structure ExampleLex
%%
"T" => (SOME true);
"F" => (SOME false);

By applying this file to smllex,

smllex ex.lex

you obtains a program named ex.lex.sml. To compile it, you need to create the following ex.lex.smi file by yourself:

_require "basis.smi"
structure ExampleLex =
struct
  exception LexError
  val makeLexer : (int -> string) -> unit -> bool option
end

When your .lex file has an %arg, directive, 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));

the generated makeLexer function takes an additional argument:

_require "basis.smi"
structure Example2Lex =
struct
  exception LexError
  val makeLexer : (int -> string) -> {inverse : bool}
                  -> unit -> bool option
end

History

SMLLex is a derivative of ML-Lex, which is originally developed by Andrew W. Appel, James S. Mattson, and David R. Tarditi.

Major changes from the orginal ML-Lex includes the following:

•

The command line option -o is added.

•

The character position starts with 0, not 2.

•

The generated program does not use Unsafe features of SML/NJ.

From smlsharp 4.1.0-1+b1 in Debian 13 (Trixie). Parsed by carta from the page's man source.