| Module structure, Signatures | Paragraphs, Declarations | Formulas, Expressions | Operators, Miscellaneous |
|---|---|---|---|
Module structure
// module declaration
module qualified/name
// imports
open other_module
open qual/name[Param] as Alias
// paragraphs (any order)
sig name ...
fact name { formulas }
pred name { formulas }
assert name { formulas }
fun name [Param] : bounding-expr {
body-expression
}
run pred-name for scope
check assertion for scope
SignaturesGeneralsig qualified-name ... {
field declarations
}
// or ...
sig qualified-name ... {
field declarations
}{
signature facts
}
Given Top-level type signaturessig qname { ... }
Subtype signaturessig qname extends superclass { ... }
N.B. If A and B each extend C, then A and B are disjoint. Subset signaturessig qname in sup { ... }
sig qname in sup1 + sup2 + ... { ... }
N.B. Subset signatures are not necessarily pairwise disjoint, and may have multiple parents. Multiple signaturessig qname1, qname2, ... { ... }
≡ Signature multiplicitiesone sig qname1 { ... }
lone sig qname1 { ... }
some sig qname1 { ... }
The keywords Alloy 4 quick reference summary by C. M. Sperberg-McQueen, Black Mesa Technologies LLC (v1.1 2013-07-23) ©2013 CC BY-SA 3.0. |
ParagraphsFactsfact name { formulas }
fact { formulas } // name optional
Predicates, RunPredicates are either true or false; they can take arguments. pred name { formulas }
pred name [decl, decl2 ...]{ formulas }
Use run name Optionally specify scope (defaults to 3): run name for 2 run name for 2 but 1 sig1, 5 sig2 Assertions, Checkassert name { formulas }
Unlike predicates, assertions don't bind arguments. Use check name for 2 but 1 sig1, 5 sig2 Functionsfun name [decl, ...] : e1 { e2 }
The body expression e2 is evaluated to produce the function value; the bounding expression e1 describes the set from which the result is drawn. DeclarationsFields of signatures, function arguments, predicate arguments, comprehension variables, quantified variables all use same declaration syntax: Simple declarationname
Constrains values to be a subset of the value of the bounding expression. Multiple declarationname1, name2 : bounding-expression // or disj name1, name2 : bounding-expression In field declarations, sig S {f : disj e}
Requires distinct S atoms to have distinct f values;
≡ MultiplicitiesDefault multiplicity is one: name1 : bounding-expression // equivalent to: name1 : one bounding-expression Other multiplicities: name2 : lone expr // at most one name3 : some expr // one or more name4 : set expr // zero or more RelationsBounding expression may denote a relation: r : e1 -> e2 Multiplicities in declaring relations: r : e1 -> one e2 // total function r : e1 -> lone e2 // partial function r : e1 one -> one e2 // 1:1 (bijection) |
FormulasFormulas (aka constraints) are boolean expressions. Primitive boolean operators include the comparison operators: set1 in set2 set1 = set2 scalar = value Expression quantifiers make booleans out of relational expressions. some relation-name no r1 & r2 // etc. Quantified expressions are formulas: some var : bounding-expr | expr all var : bounding-expr | expr one var : bounding-expr | expr lone var : bounding-expr | expr no var : bounding-expr | exprTrue iff expr is true for some, all, exactly one, at most one, or no elements of the set denoted by bounding-expr The logical
operators ( boolean and boolean2 not boolean or boolean2 boolean implies boolean2 // etc. Conditional expressionsboolean implies expression boolean implies expr1 else expr2 Let expressionslet decl, decl2 ... | expression
let decl, decl2 ... { formulas }
Relational expressionsSimple expressions: qualified name, Constants: Unary compound expressions: op r
where op is a unary relational operator ( Binary compound expressions: a op b
where op is a binary relational operator ( Arrow expressions: r1 [mult| Integer expressionsNumeric constant: [1-9][0-9]* Arithmetic operators ( Constants, predefined identifiersPredefined functions
Relations
|
Operators in precedence ordera, b, c are n-ary relations (n ≠ 0), f a functional relation, r, r1, r2 are binary relations, s is a set (unary relation). N.B. ≡ is standard mathematical syntax, not Alloy syntax. Unary operators:
Dot join:
Box join:
Restriction:
Arrow product:
Intersection:
Override:
Cardinality:
Union, difference:
Expression quantifiers, multiplicities:
Comparison negation:
Comparison operators:
Logical negation:
Conjunction:
Implication:
Bi-implication:
Disjunction:
Let, quantification operators:
† ‡ Arithmetic overflow may occur. Associativity:Implication associates right:
All other binary operators
associate left: Lexical structureCharacters: any ASCII character except Alloy is case-sensitive Tokenization: any whitespace or punctuation separates tokens, except
that Comments: from Identifiers (names): letters, numerals, underscore, quote marks (no hyphens) Qualified names (qnames): sequence of slash-separated names, optionally beginning
with Reserved words:
Namespaces: 1 module names and aliases; 2 signatures, fields, paragraphs (facts, predicates, assertions, functions), bound variables; 3 command names. Names in different namespaces do not conflict; variables are lexically scoped (inner bindings shadow outer). Otherwise, no two things can share a name. |