languagemachine2

module
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2026 License: GPL-3.0

README

Language Machine 2

A Go port of Peri Hankey's Language Machine, a toolkit for language and grammar. In a Language Machine grammar, a rule applies when what is expected and what is in the input fail to match. Recognition and substitution interleave on the input stream, so one notation (lmn) covers lexing, parsing, translation and evaluation.

The port keeps the original execution semantics and the lm-diagram trace. The grammars and reference outputs from the original release (in examples/) produce the same output, and the regression tests check this.

Build

Requires Go 1.27 or later. There are no third-party dependencies.

make build        # -> bin/lm
make test         # regression tests
make check        # vet + tests
make race         # tests under the race detector
make bench        # engine benchmarks at 1, 4 and 16 CPUs

Quick start

Grammars are written in lmn and compiled to .lm bytecode by the lmn compiler, which is itself a grammar. First build the compiler from its sources. lmnbs.lm is the original bootstrap, and the second stage is a fixpoint:

bin/lm -rules internal/lmnsrc/lmnbs.lm internal/lmnsrc/lmn2xfe.lmn internal/lmnsrc/lmn2mbe.lmn > stage1.lm
bin/lm -rules stage1.lm -output lmn.lm internal/lmnsrc/lmn2xfe.lmn internal/lmnsrc/lmn2mbe.lmn

Then compile a grammar and run it:

bin/lm -rules lmn.lm -output calc.lm examples/basics/calc.lmn
bin/lm -rules calc.lm -input '3*(4+5)='          # the answer is 27
bin/lm -rules calc.lm examples/basics/calc.input  # input files as arguments
bin/lm -rules calc.lm -trace D -input '1+2='      # draw the lm-diagram

Run bin/lm -h for all options. Flags take effect in the order given (for example, -dwidth must come before -trace D).

Documentation

License

Language Machine 2 is distributed under the GNU GPL v3 (see COPYING). It is based on the Language Machine © 2005 Peri Hankey, GNU GPL v2 (see COPYING.languagemachine).

Directories

Path Synopsis
cmd
lm command
Command lm runs Language Machine rules (.lm bytecode) on its input.
Command lm runs Language Machine rules (.lm bytecode) on its input.
lmn command
Command lmn is the lmn compiler (lmn2xfe + lmn2mbe) built into a Go program by lmn2go, as the original built lmn2m with lmn2d and gdc.
Command lmn is the lmn compiler (lmn2xfe + lmn2mbe) built into a Go program by lmn2go, as the original built lmn2m with lmn2d and gdc.
lmn2go command
Command lmn2go compiles Language Machine rules to a Go program or package, as lmn2d compiled them to D (docs/lmn2go.md).
Command lmn2go compiles Language Machine rules to a Go program or package, as lmn2d compiled them to D (docs/lmn2go.md).
examples
highlight
Package highlight does syntax highlighting with Language Machine rules.
Package highlight does syntax highlighting with Language Machine rules.
highlight/lmhl command
Command lmhl highlights source text with Language Machine rules (../README.md).
Command lmhl highlights source text with Language Machine rules (../README.md).
internal
conv
Package conv holds the text conversions that must behave as the original machine's did: URI encoding like JavaScript's encodeURI, C-style escapes, and C library number parsing (strtod, sscanf "%o").
Package conv holds the text conversions that must behave as the original machine's did: URI encoding like JavaScript's encodeURI, C-style escapes, and C library number parsing (strtod, sscanf "%o").
lmgo
Package lmgo turns compiled Language Machine rules into Go source, as the original lmn2d back end turned them into D: the rules in .lm bytecode are embedded in a Go file that runs them with package lm, together with a table that binds the functions the rules call to Go functions.
Package lmgo turns compiled Language Machine rules into Go source, as the original lmn2d back end turned them into D: the rules in .lm bytecode are embedded in a Go file that runs them with package lm, together with a table that binds the functions the rules call to Go functions.
lmnsrc
Package lmnsrc embeds the lmn compiler: the bootstrap compiler lmnbs.lm and the sources of the bytecode compiler, front end lmn2xfe.lmn and back end lmn2mbe.lmn.
Package lmnsrc embeds the lmn compiler: the bootstrap compiler lmnbs.lm and the sources of the bytecode compiler, front end lmn2xfe.lmn and back end lmn2mbe.lmn.
version
Package version holds the version, date and licence strings.
Package version holds the version, date and licence strings.
lm
Package lm runs Language Machine rulesets built into a Go program.
Package lm runs Language Machine rulesets built into a Go program.
lmn
Package lmn compiles lmn, the notation of Language Machine rules, to the .lm bytecode that lm.Program runs.
Package lmn compiles lmn, the notation of Language Machine rules, to the .lm bytecode that lm.Program runs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL