Skip to content

CMLGrammar

Joey Coleman edited this page Jul 16, 2014 · 9 revisions

CML Grammar

model
value declarations
values, { value definition }
;
value definition
qualifier
private | protected | public | logical
;
channel declarations
;
channel name declarations
identifier, { ,, identifier }, [ :, type ]
;
chanset declarations
chansets, { chanset definition }
;
chanset definition
nameset declarations
namesets, { nameset definition }
;
nameset definition
state declarations
instance variable definition
assignment definition
identifier, :, type, [ :=, expression ]
;
invariant definition
inv, expression
;
process declaration
process, identifier, =, [ parametrisation, { ,, parametrisation }, @ ], process
;

Note: the only parametrisation qualifier allowed in a process declaration is val. (Omitting a parametrisation qualifier defaults to val, and is permitted as well.)

parametrisation
parametrisation qualifier
val | res | vres
;
action declarations
actions, { action definition }
;
action definition
chanset expression
nameset expression
class declaration
class, identifier, [ extends, identifier ], =, begin, { class paragraph }, end
;
action process
begin, { action paragraph }, @, action, end
;
renaming expression
[[``, |renaming pair|_, { ``,``, |renaming pair|_ }, ``]]
| [[``, |renaming pair|_, ``|`` |bind list|_, [ ``@``, |expression|_ ], ``]]
;

Note that the current parser only supports a single expression after an identifier in a renaming pair; this will be corrected in a future release.

renaming pair
;
replication declarations
replication declaration
identifier, { ,, identifier }, :, type
| identifier, { ,, identifier }, in set, expression
;
action
communication
communication parameter
?, bindable pattern, [ :, (, expression, ) ]
| !, parameter
| ., parameter
;
parametrised action
instantiated action
local definition
non-deterministic alt
if statement
if, expression, then, action, { elseif statement }, [ else, action ]
;
elseif statement
elseif, expression, then, action
;
cases statement
cases statement alt
others statement
others, ->, action
;
assign statement
multiple assign statement
;
call statement
name, (, [ expression, { ,, expression } ], )
| assignable expression, :=, name, (, [ expression, { ,, expression } ], )
;
new statement
assignable expression, :=, new, name, (, [ expression, { ,, expression } ], )
;
type declarations
types, [ type definition, { ;, type definition } ]
;
type definition
type
(, type, )
| compose, identifier, of, { field }, end
| type, |, type, { |, type }
| type, *, type, { *, type }
| [, type, ]
| set of, type
| seq of, type
| seq1 of, type
| map, type, to, type
| inmap, type, to, type
| name
;
basic type
bool | nat | nat1 | int | rat | real | char | token
;
field
function type
discretionary type
type | ()
;
type invariant
inv, pattern, ==, expression
;

Operations do not include reactive constructs; while the parser will accept any action in an operation body, the typechecker will only allow statements, the ; sequential composition operator, and the constant action Skip. In essence, operation bodies in CML allow only what is allowed in VDM operation bodies.

operation declarations
operations, { operation definition }
;
explicit operation definition
operation type
operation body
| is subclass responsibility
| is not yet specified
;
implicit operation definition
frame
var information
rd, name, { ,, name }, [ :, type ]
| wr, name, { ,, name }, [ :, type ]
;
function declarations
functions, { function definition }
;
explicit function definition
;
parameters list
parameters
(, [ pattern list ], )
;
implicit function definition
parameter types
(, [ pattern list, :, type, { ,, pattern list, :, type } ], ) }
;
identifier type pair list
identifier, :, type, { ,, identifier, :, type }
;
function body
| is not yet specified
| is subclass responsibility
;
name
old name
;
unary operator
+ | - | abs | floor | not | card | power | dunion | dinter | hd | tl | len | elems | inds | reverse | conc | dom | rng | merge | inverse
;
binary operator
+ | - | * | / | div | rem | mod | < | <= | > | >= | = | <> | or | and | => | <=> | in set | not in set | subset | psubset | union | \ | inter | ^ | ++ | munion | <: | <-: | :> | :-> | comp | **
;
tuple expression
mk_, (, expression, ,, expression, { ,, expression }, )
;
record expression
mk_, token, (, expression, )
| mk_, name, (, [ expression, { ,, expression } ], )
;
set expression
{, [ expression, { ,, expression } ], }
| {, expression, |, bind list, [ @, expression ], }
| {, expression, ,, ..., ,, expression, }
;
sequence expression
[, [ expression, { ,, expression } ], ]
| [, expression, |, set bind, [ @, expression ], ]
;
subsequence
expression, (, expression, ,, ..., ,, expression, )
;
map expression
{, |->, }
| {, maplet, { ,, maplet }, }
| {, maplet, |, bind list, [ @, expression ], }
;
maplet
apply
expression, (, [ expression, { ,, expression } ], )
;
field select
tuple select
if expression
elseif expression
elseif, expression, then, expression
;
cases expression
cases, expression, :, cases expression alternatives, [ ,, others -> expression ], end
;
cases expression alternatives
assignable expression
self { selector }
;
selector
(, [ expression, { ,, expression } ], )
| (, expression, ..., expression, )
| .#, numeral
;
pattern
bindable pattern
-
| mk_, (, pattern, ,, pattern list, )
| mk_, name, (, [ pattern list ], )
;
match value
pattern list
pattern, { ,, pattern }
;
bind
set bind
pattern, in set, expression
;
type bind
;
bind list
multiple bind
type bind list
;

[ Please note: the parser's implementation of this is still incomplete. For now it's probably best to stick within the ASCII character set. ]

Unlike the rest of this specification, the rules in this section are sensitive to whitespace; as such, whitespace may not implicity separate any pair of components in a rule here.

Note that the unicode character categories can be found online at http://www.fileformat.info/info/unicode/category/index.htm. The present release of the tool only supports characters below U+0100; support for characters outside of the extended ASCII subset of unicode is planned for a future release.

initial letter
if codepoint < U+0100 then Any character in categories Ll, Lm, Lo, Lt, Lu, or the character U+0024 (\$) else Any character, excluding categories Cc, Zl, Zp, Zs, Cs, Cn, Nd, Pc. ;
following letter
if codepoint < U+0100 then Any character in categories Ll, Lm, Lo, Lt, Lu, Nd, or the characters U+0024 (\$), U+0027 ('), and U+005F (_) else Any character, excluding categories Cc, Zl, Zp, Zs, Cs, Cn. ;
ascii letter
Any character in the ranges [U+0041,U+005A] and [U+0061, U+007A] --- A-Z and a-z, respectively. ;
character
Is left underdefined, except to note that it may be any unicode character except those that conflict with the lexical rule that uses the character class. For example, character does not include \ in the character literal rule. ;
identifier
digit
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
;
hex digit
digit | a | b | c | d | e | f | A | B | C | D | E | F
;
numeral
digit, { digit }
;
numeric literal
exponent
(E | e), [ + | -], numeral
;
decimal literal
numeral, [ ., digit, { digit } ], [ exponent ]
;
hex literal
(0x | 0X), hex digit, { hex digit }
;
boolean literal
true | false
;
nil literal
nil
;
character literal
', character, '
;
escape sequence
\\ | \r | \n | \t | \f | \e | \a| \"| \' | \x, hex digit, hex digit
;
text literal
;
quote literal
<, identifier, >
;