CADiZ

Reference manual / Concrete syntax


Contents of this page

Introduction

The concrete syntax defines which sequences of tokens (or lexemes) are acceptable as sentences of the Z language.

The concrete syntax is formalized below using syntactic metalanguage. MixedCase is used for the names of syntactic rules. CAPITALISED names are tokens of the lexis, as are mathematical symbols and symbols ending in -tok.

ISO Standard concrete syntax

Formal definition of concrete syntax

This formal definition is public domain material, and appears as it appears in ISO/IEC 13568:2002 (the Z standard).

Specification = { Section } (* sectioned specification *)
| { Paragraph } (* anonymous specification *)
;

Section = ZED , section , NAME , parents , [ NAME , { ,-tok , NAME } ] , END , { Paragraph } (* inheriting section *)
| ZED , section , NAME , END , { Paragraph } (* base section *)
;

Paragraph = ZED , [-tok , NAME , { ,-tok , NAME } , ]-tok , END (* given types *)
| AX , SchemaText , END (* axiomatic description *)
| SCH , NAME , SchemaText , END (* schema definition *)
| GENAX , [-tok , Formals , ]-tok , SchemaText , END (* generic axiomatic description *)
| GENSCH , NAME , [-tok , Formals , ]-tok , SchemaText , END (* generic schema definition *)
| ZED , DeclName , == , Expression , END (* horizontal definition *)
| ZED , NAME , [-tok , Formals , ]-tok , == , Expression , END (* generic horizontal definition *)
| ZED , GenName , == , Expression , END (* generic operator definition *)
| ZED , FreeType , { ampersand , FreeType } (* free types *)
| ZED , \vdash? , Predicate , END (* conjecture *)
| ZED , [-tok , Formals , ]-tok , \vdash? , Predicate , END (* generic conjecture *)
| ZED , OperatorTemplate , END (* operator template *)
;

Freetype = NAME , ::= , Branch , { |-tok , Branch } ; (* free type *)

Branch = DeclName , [ \ldata , Expression , \rdata ] ; (* element or injection *)

Formals = NAME , { ,-tok , NAME } ; (* generic parameters *)

Predicate = Predicate , NL , Predicate (* newline conjunction *)
| Predicate , ;-tok , Predicate (* semicolon conjunction *)
| \forall , SchemaText , @ , Predicate (* universal quantification *)
| \exists , SchemaText , @ , Predicate (* existential quantification *)
| \exists1 , SchemaText , @ , Predicate (* unique existential quantification *)
| Predicate , \iff , Predicate (* equivalence *)
| Predicate , \implies , Predicate (* implication *)
| Predicate , \lor , Predicate (* disjunction *)
| Predicate , \land , Predicate (* conjunction *)
| \lnot , Predicate (* negation *)
| Relation (* relation operator application *)
| Expression (* schema predicate *)
| true (* truth *)
| false (* falsity *)
| (-tok , Predicate , )-tok (* parenthesized predicate *)
;

Expression = \forall , SchemaText , @ , Expression (* schema universal quantification *)
| \exists , SchemaText , @ , Expression (* schema existential quantification *)
| \exists1 , SchemaText , @ , Expression (* schema unique existential quantification *)
| \lambda , SchemaText , @ , Expression (* function construction *)
| \mu , SchemaText , @ , Expression (* definite description *)
| let , DeclName , == , Expression , { ;-tok , DeclName , == , Expression } , @ , Expression (* substitution expression *)
| Expression , \iff , Expression (* schema equivalence *)
| Expression , \implies , Expression (* schema implication *)
| Expression , \lor , Expression (* schema disjunction *)
| Expression , \land , Expression (* schema conjunction *)
| \lnot , Expression (* schema negation *)
| if , Predicate , then , Expression , else , Expression (* conditional *)
| Expression , \semi , Expression (* schema composition *)
| Expression , >> , Expression (* schema piping *)
| Expression , \ , (-tok , DeclName , { ,-tok , DeclName } , )-tok (* schema hiding *)
| Expression , \project , Expression (* schema projection *)
| pre , Expression (* schema precondition *)
| Expression , \cross , Expression , { \cross , Expression } (* Cartesian product *)
| \power , Expression (* powerset *)
| Application (* function or generic operator application *)
| Expression , Expression (* application *)
| Expression , STROKE (* schema decoration *)
| Expression , [-tok , DeclName , / , DeclName , { ,-tok , DeclName , / , DeclName } , ]-tok (* schema renaming *)
| Expression , . , RefName (* binding selection *)
| Expression , . , NUMERAL (* tuple selection *)
| \theta , Expression , { STROKE } (* binding construction *)
| RefName (* reference *)
| RefName , [-tok , Expression , { ,-tok , Expression } , ]-tok (* generic instantiation *)
| NUMERAL (* number literal *)
| {-tok , [ Expression , { ,-tok , Expression } ] , }-tok (* set extension *)
| {-tok , SchemaText , @ , Expression , }-tok (* set comprehension *)
| ( ( {-tok , SchemaText , }-tok ) - ( {-tok , }-tok ) ) - ( {-tok , Expression , }-tok ) (* characteristic set comprehension *)
| ( [-tok , SchemaText , ]-tok ) - ( [-tok , Expression , ]-tok ) (* schema construction *)
| \lblot , [ DeclName , == , Expression , { ,-tok , DeclName , == , Expression } ] , \rblot (* binding extension *)
| (-tok , Expression , ,-tok , Expression , { ,-tok , Expression } , )-tok (* tuple extension *)
| (-tok , \mu , SchemaText , )-tok (* characteristic definite description *)
| (-tok , Expression , )-tok (* parenthesized expression *)
;

)

SchemaText = [ DeclPart ] , [ |-tok , Predicate ] ;

DeclPart = Declaration , { ( ;-tok | NL ) , Declaration } ;

Declaration = DeclName , { ,-tok , DeclName } , : , Expression
| DeclName , == , Expression
| Expression
;

OperatorTemplate = relation , Template
| function , CategoryTemplate
| generic , CategoryTemplate
;

CategoryTemplate = PrefixTemplate
| PostfixTemplate
| Prec , Assoc , InfixTemplate
| NofixTemplate
;

Prec = NUMERAL;

Assoc = leftassoc
| rightassoc
;

Template = PrefixTemplate
| PostfixTemplate
| InfixTemplate
| NofixTemplate
;

PrefixTemplate = (-tok , PrefixName , )-tok
| (-tok , \power , _ , )-tok
;

PostfixTemplate = (-tok , PostfixName , )-tok ;

InfixTemplate = (-tok , InfixName , )-tok ;

NofixTemplate = (-tok , NofixName , )-tok ;

DeclName = NAME
| OpName
;

RefName = NAME
| (-tok , OpName , )-tok
;

OpName = PrefixName
| PostfixName
| InfixName
| NofixName
;

PrefixName = PRE , _
| PREP , _
| L , { _ , ES | ,, , SS } , ( _ , ERE | ,, , SRE ) , _
| LP , { _ , ES | ,, , SS } , ( _ , EREP | ,, , SREP ) , _
;

PostfixName = _ , POST
| _ , POSTP
| _ , EL , { _ , ES | ,, , SS } , ( _ , ER | ,, , SR )
| _ , ELP , { _ , ES | ,, , SS } , ( _ , ERP | ,, , SRP )
;

InfixName = _ , I , _
| _ , IP , _
| _ , EL , { _ , ES | ,, , SS } , ( _ , ERE | ,, , SRE ) , _
| _ , ELP , { _ , ES | ,, , SS } , ( _ , EREP | ,, , SREP ) , _
;

NofixName = L , { _ , ES | ,, , SS } , ( _ , ER | ,, , SR )
| LP , { _ , ES | ,, , SS } , ( _ , ERP | ,, , SRP )
;

GenName = PrefixGenName
| PostfixGenName
| InfixGenName
| NofixGenName
;

PrefixGenName = PRE , NAME
| L , { NAME , ( ES | SS ) } , NAME , ( ERE | SRE ) , NAME
;

PostfixGenName = NAME , POST
| NAME , EL , { NAME , ( ES | SS ) } , NAME , ( ER | SR )
;

InfixGenName = NAME , I , NAME
| NAME , EL , { NAME , ( ES | SS ) } , NAME , ( ERE | SRE ) , NAME
;

NofixGenName = L , { NAME , ( ES | SS ) } , NAME , ( ER | SR ) ;

Relation = PrefixRel
| PostfixRel
| InfixRel
| NofixRel
;

PrefixRel = PREP , Expression
| LP , ExpSep , ( Expression , EREP | ExpressionList , SREP ) , Expression
;

PostfixRel = Expression , POSTP
| Expression , ELP , ExpSep , ( Expression , ERP | ExpressionList , SRP )
;

InfixRel = Expression , ( \in | =-tok | IP ) , Expression , { ( \in | =-tok | IP ) , Expression }
| Expression , ELP , ExpSep , ( Expression , EREP | ExpressionList , SREP ) , Expression
;

NofixRel = LP , ExpSep , ( Expression , ERP | ExpressionList , SRP ) ;

Application = PrefixApp
| PostfixApp
| InfixApp
| NofixApp
;

PrefixApp = PRE , Expression
| L , ExpSep , ( Expression , ERE | ExpressionList , SRE ) , Expression
;

PostfixApp = Expression , POST
| Expression , EL , ExpSep , ( Expression , ER | ExpressionList , SR )
;

InfixApp = Expression , I , Expression
| Expression , EL , ExpSep , ( Expression , ERE | ExpressionList , SRE ) , Expression
;

NofixApp = L , ExpSep , ( Expression , ER | ExpressionList , SR ) ;

ExpSep = { Expression , ES | ExpressionList , SS } ;

ExpressionList = [ Expression , { ,-tok , Expression } ] ;

User-defined operators

In a Template, each operator token shall be a name with no STROKEs. That name can take part in the templates of several operators that are in scope together, so long as it has the same operator token in all of them and all of them have the same precedence. Every template shall differ in some way from all other templates that are in scope together.

All prefix operators are right associative. All postfix operators are left associative. Different associativities shall not be used at the same precedence level by operator template paragraphs in the same scope.

The following table defines the relative precedences of the productions of Expression and Predicate. The rows in the table are ordered so that the entries with higher precedence (and so that bind more strongly) appear nearer the top of the table than those with lower precedence (that bind more weakly). Associativity has significance only in determining the nesting of applications involving non-associative operators of the same precedence. Explicitly-defined function and generic operator applications have a range of precedences specified numerically in the corresponding operator template paragraph. Cartesian product expressions have precedence value 8 within that numeric range.

Productions Associativity
 
binding construction
binding selection, tuple selection
schema renaming
schema decoration
application left
postfix function and generic operator application
powerset, prefix function and generic operator application
Cartesian product, infix function and generic operator application
schema precondition
schema projection left
schema hiding
schema piping
schema composition
conditional
substitution expression
definite description
function construction
relation operator application
negation
conjunction
disjunction
implication right
equivalence
universal, existential and unique existential quantifications
newline conjunction, semicolon conjunction

Additional syntactic restrictions

STROKE is used in three contexts: within NAMEs, in binding construction expressions, and in schema decoration expressions. The condition for a STROKE to be considered as part of a NAME was given in the lexis. Other STROKEs are considered to be parts of binding construction expressions if they can be when interpreted from left to right. The schema decoration expression interpretation is considered last.

A predicate can be just an expression, yet the same logical operators (\land, \lor, \lnot, \implies, \iff, \forall, \exists, \exists1) can be used in both expressions and predicates. Where a predicate is expected, and one of these logical operators is used on expressions, there is an ambiguity: either the whole logical operation is an expression and that expression is used as a predicate, or the whole logical operation is a predicate involving expressions each used as a predicate. This ambiguity is benign, as both interpretations have the same precedence, associativity and meaning.

CADiZ-specific concrete syntax

Cadiz permits the declaration part of a substitution expression to be an arbitrary SchemaText, just like a definite description (\mu) expression, rather than only constant (==) declarations.

Expression = let , SchemaText , @ , Expression
| (-tok , let , SchemaText , )-tok
;

Cadiz offers exclusive or (\xor) as an additional logical operator in Predicate and Expression. It has the same precedence and associativity as inclusive or.

Predicate = Predicate , \xor , Predicate ;
Expression = Expression , \xor , Expression ;

A string literal may appear as an Expression.

Expression = STRING ;

A comment to be typeset as part of the specification can be included as a predicate.

Predicate = comment , STRING ;

A constant declaration can declare more than one name for the constant.

Declaration = DeclName , { ,-tok , DeclName } , == , Expression ;

The syntax of conjectures is replaced by a syntax of sequents, which includes conjectures as a special case.

Paragraph = [ [-tok , Formals, ]-tok ] , [ DeclPart , { \dagger , DeclPart } ] , [ |-tok , Predicate , { ,-tok , Predicate } ] , \vdash? , [ Predicate, { ,-tok , Predicate } ] ;

Cadiz adds the following schema operators: overriding, postcondition and undecoration.

Expression = Expression , \zovr , Expression
| post , Expression
| undecor , STROKE , Expression
;

A generic parameter list may distinguish parameters that may be instantiated only with schemas. These are used in the definition of type-constrained generics.

Formals = [NAME , { ,-tok , NAME } ] , [ \dagger , NAME , { ,-tok , NAME } ] ;

Branch is redefined to permit mixfix syntax for injections in free types.

Branch = DeclName , \ldata , Expression , \rdata
| Expression
;

Multiple unboxed paragraphs may be merged into a single unboxed paragraph.

Paragraph = ZED , UnboxedDef , { UnboxedDef } , END
| ZED , OperatorTemplate , { OperatorTemplate } , END
| axiomatic description
| schema definition
| generic axiomatic description
| generic schema definition
| conjecture
| generic conjecture
;
UnboxedDef = given set
| free types
| horizontal definition
| generic horizontal definition
| generic operator definition
;

IT 22-Jan-2002