Usage

Command Line Options

In the Nix development shell (and project root directory), run python -m lamb -h to see help information. Some frequently used command-line toggles are listed below:

  • -c <length>: stop searching for ambiguous sentences after reaching the given length. This is useful if you want to check the bounded unambiguity of a given grammar.
  • -l <length>: start the checking process at the specified length. This assumes that one has already checked that any shorter sentence under this grammar is unambiguous.
  • -s: output metrics like running time as well as REPL outputs as machine-readable JSON strings.

EBNF Syntax

Lamb accepts .bnf files as inputs. A formal definition in Antlr can be found here.

Informally, a .bnf file consists of many production rules, each has the form

<nonterminal> ::= <expr> ;

The expression is one of the following:

  • An identifier representing a nonterminal (e.g., block)
  • A quoted string representing a terminal (e.g., "do")
  • A parenthesized expression (to promote priority)
  • A sequence of expressions as concatenation
  • A postfix expression
  • An infix expression

We include all standard EBNF constructs:

  • Postfix + for Kleene plus (occur at least once)
  • Postfix * for Kleene star (occur an arbitrary number of times, including zero)
  • Postfix ? for optional (occur once or none)
  • Infix | for alternative (choose either part)

We support the following layout constraints:

  • Infix <> or || for alignment (the first tokens of the two parts have the same column number)
  • Infix -> for indentation (the second part has its first token to the right of the first part and a newline in between)
  • Postfix |> for offside (any subsequent lines must start from a column that is further to the right of the start token of the first line)
  • Postfix |>> for offside align (a variant of the above: subsequent lines can start from the same column as that of the first line)
  • Postfix |+| for aligned Kleene plus (a variant of Kleene plus, but each element must be aligned to each other)
  • Postfix |*| for aligned Kleene star (a variant of Kleene plus, but each element must be aligned to each other)
  • Postfix ~ for single-line (one-line)

If needed, check the examples in the tests/ folder for a better understanding.