Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Lexical Rules

Specifications occur within Rust source code. Function contracts and type invariants use attributes; statement annotations and quantifiers use macro invocations. Comments do not introduce specifications.

Tokens and identifiers

Identifiers, literals, whitespace, and comments follow Rust’s lexical rules. Whitespace and ordinary comments may separate tokens wherever Rust permits them. The specification language introduces no separate literal notation or mathematical Unicode operators.

The following names in the grammar refer to Rust syntax:

NameMeaningExamples
IDENTIFIERIdentifierx, result, limit
TypeTypeu8, &T, Vec<i32>
LiteralLiteral expressiontrue, 16, 0u8
PathExpression pathx, u8::MAX
TUPLE_INDEXTuple-field index0 in pair.0

Names introduced by bindings follow Rust scope rules. In a postcondition, result is an ordinary parameter name; another identifier may be used instead. In a type invariant, self refers to the value whose invariant is being described.

Grammar notation

Syntax blocks use a compact extended BNF (EBNF). Boxed monospace text denotes literal source tokens; linked names denote nonterminals.

NotationMeaning
A := BDefines A in terms of B
A BA followed by B
A | BEither A or B
A?Zero or one occurrence of A
A*Zero or more occurrences of A
(A B)Groups grammar elements

A boxed (, ) or | is a source token, not a grammar operator. Arguments? permits an omitted argument list; ","? permits a trailing comma. The Show syntax diagrams button displays the same production as a diagram.

The grammar uses unqualified names, parenthesized macro invocations, and simple parameter bindings. The Expr production describes expression structure; Rust operator precedence determines grouping. It is not an unambiguous parser grammar for all Rust expressions.

Example

#[precondition(x /* input */ < 16)]
#[postcondition(|result: u8| result >= x)]

The comment separates tokens without changing the precondition. The bars in the second attribute delimit the return-value binding.

Implementation boundaries

  • Frontend rust-llbc: uses Rust lexical rules, expression parsing, and typing and borrowing checks.
  • Backend llbc-why3: handles extracted representations rather than these lexical forms directly.

Remaining work

Distinguishing markers from ordinary names (frontend). Name-based replacement of implies and postcondition old also changes ordinary Rust names. For example, .old() in #[postcondition(|r| r == value.old())] is replaced even when it denotes a user-defined method, causing expansion to fail. Name handling needs to preserve ordinary method calls while recognizing specification markers. See Name rewriting.