nonterminal ::= alternative ∣ alternative ∣ ... ∣ alternativeThe following extensions are used:
| a , ... | a list of one or more as separated by commas: "" or "a" or "a, a" or "a, a, a", etc. |
| { a } | a sequence of zero or more as: "" or "a" or "a a" or "a a a", etc. |
| [ a ] | an optional a: "" or "a". |
Nonterminal symbols appear in lightface. Reserved words appear in boldface.
All other terminal symbols are nonalphabetic and appear in lightface:
| module | ::= | { equate } procedure |
| ∣ | { equate } iterator | |
| ∣ | { equate } cluster | |
| procedure | ::= | idn = proc [ parms ] args [ returns ] [ signals ] [ where ] |
| routine_body | ||
| end idn | ||
| iterator | ::= | idn = iter [ parms ] args [ yields ] [ signals ] [ where ] |
| routine_body | ||
| end idn | ||
| cluster | ::= | idn = cluster [ parms ] is idn , ... [ where ] |
| cluster_body | ||
| end idn | ||
| parms | ::= | [ parm , ... ] |
| parm | ::= | idn , ... : type ∣ idn , ... : type_spec |
| args | ::= | ( [ decl , ... ] ) |
| decl | ::= | idn , ... : type_spec |
| returns | ::= | returns ( type_spec , ... ) |
| yields | ::= | yields ( type_spec , ... ) |
| signals | ::= | signals ( exception , ... ) |
| exception | ::= | name [ ( type_spec , ... ) ] |
| where | ::= | where restriction , ... |
| restriction | ::= | idn has oper decl , ... |
| ∣ | idn in type_set | |
| type_set | ::= | { idn ∣ idn has oper decl , ... { equate } } ∣ idn |
| oper_decl | ::= | op name , ... : type_spec |
| op_name | ::= | name [ [ constant , ... ] ] |
| constant | ::= | expression ∣ type_spec |
| routine_body | ::= | { equate } |
| { own_var } | ||
| { statement } | ||
| cluster_body | ::= | { equate } rep = type_spec { equate } |
| { own_var } | ||
| routine { routine } | ||
| routine | ::= | procedure ∣ iterator |
| equate | ::= | idn = constant ∣ idn = type_set |
| own_var | ::= | own decl |
| ∣ | own idn : type_spec := expression | |
| ∣ | own decl , ... := invocation | |
| type_spec | ::= | null ∣ bool ∣ int ∣ real ∣ char ∣ string ∣ any ∣ rep ∣ cvt |
| ∣ | array [ type_spec ] ∣ sequence [ type_spec ] | |
| ∣ | record [ field_spec , ... ] ∣ struct [ field_spec , ... ] | |
| ∣ | oneof [ field_spec , ... ] ∣ variant [ field_spec , ... ] | |
| ∣ | proctype ( [ type_spec , ... ] ) [ returns ] [ signals ] | |
| ∣ | itertype ( [ type_spec , ... ] ) [ yields ] [ signals ] | |
| ∣ | idn [ constant , ... ] ∣ idn | |
| field_spec | ::= | name , ... : type_spec |
| statement | ::= | decl |
| ∣ | idn : type_spec := expression | |
| ∣ | decl , ... := invocation | |
| ∣ | idn , ... := invocation | |
| ∣ | idn , ... := expression , ... | |
| ∣ | primary . name := expression | |
| ∣ | primary [ expression ] := expression | |
| ∣ | invocation | |
| ∣ | while expression do body end | |
| ∣ | for [ decl , ... ] in invocation do body end | |
| ∣ | for [ idn , ... ] in invocation do body end | |
| ∣ | if expression then body | |
| { elseif expression then body } | ||
| [ else body ] | ||
| end | ||
| ∣ | tagcase expression | |
| tag_arm { tag_arm } | ||
| [ others : body ] | ||
| end | ||
| ∣ | return [ ( expression , ... ) ] | |
| ∣ | yield [ ( expression , ... ) ] | |
| ∣ | signal name [ ( expression , ... ) ] | |
| ∣ | exit name [ ( expression , ... ) ] | |
| ∣ | break | |
| ∣ | continue | |
| ∣ | begin body end | |
| ∣ | statement resignal name , ... | |
| ∣ | statement except { when_handler } | |
| [ others_handler ] | ||
| end | ||
| tag_arm | ::= | tag name , ... [ ( idn : type_spec ) ] : body |
| when_handler | ::= | when name , ... [ ( decl , ... ) ] : body |
| ∣ | when name , ... ( * ) : body | |
| others_handler | ::= | others [ ( idn : type_spec ) ] : body |
| body | ::= | { equate } |
| { statement } | ||
| expression | ::= | primary | |
| ∣ | ( expression ) | ||
| ∣ | ~ expression | % 6 (precedence) | |
| ∣ | expression | % 6 | |
| ∣ | expression ** expression | % 5 | |
| ∣ | expression // expression | % 4 | |
| ∣ | expression / expression | % 4 | |
| ∣ | expression * expression | % 4 | |
| ∣ | expression || expression | % 3 | |
| ∣ | expression + expression | % 3 | |
| ∣ | expression - expression | % 3 | |
| ∣ | expression < expression | % 2 | |
| ∣ | expression <= expression | % 2 | |
| ∣ | expression = expression | % 2 | |
| ∣ | expression >= expression | % 2 | |
| ∣ | expression > expression | % 2 | |
| ∣ | expression ~< expression | % 2 | |
| ∣ | expression ~<= expression | % 2 | |
| ∣ | expression ~= expression | % 2 | |
| ∣ | expression ~>= expression | % 2 | |
| ∣ | expression ~> expression | % 2 | |
| ∣ | expression & expression | % 1 | |
| ∣ | expression cand expression | % 1 | |
| ∣ | expression | expression | % 0 | |
| ∣ | expression cor expression | % 0 |
| primary | ::= | nil ∣ true ∣ false |
| ∣ | int_literal ∣ real_literal ∣ char_literal ∣ string_literal | |
| ∣ | idn | |
| ∣ | idn [ constant , ... ] | |
| ∣ | primary . name | |
| ∣ | primary [ expression ] | |
| ∣ | invocation | |
| ∣ | type_spec${ field , ... } | |
| ∣ | type_spec$[ [ expression : ] [ expression , ... ] ] | |
| ∣ | type_spec$name [ [ constant , ... ] ] | |
| ∣ | force [ type_spec ] | |
| ∣ | up ( expression ) | |
| ∣ | down ( expression ) | |
| invocation | ::= | primary ( [ expression , ... ] ) |
| field | ::= | name , ... : expression |
| any | down | int | record | tagcase |
| array | else | is | rep | then |
| begin | elseif | iter | resignal | true |
| bool | end | itertype | return | type |
| break | except | nil | returns | up |
| cand | exit | null | sequence | variant |
| char | false | oneof | signal | when |
| cluster | for | others | signals | where |
| continue | force | own | string | while |
| cor | has | proc | struct | yield |
| cvt | if | proctype | tag | yields |
| do | in | real |
| ( | : | " | < | ~< | + | || |
| ) | := | ' | <= | ~<= | - | ** |
| { | , | \ | = | ~= | * | // |
| } | . | >= | ~>= | / | & | |
| [ | $ | > | ~> | ∣ | ||
| ] | ~ |
idn [ [ constant , ... ] ]
where idn names the user defined type, each constant must be computable| Shorthand Form | Expansion |
| expr1 ** expr2 | T $power(expr1 ; expr2 ) |
| expr1 // expr2 | T $mod(expr1 ; expr2 ) |
| expr1 / expr2 | T $div(expr1 ; expr2 ) |
| expr1 * expr2 | T $mul(expr1 ; expr2 ) |
| expr1 || expr2 | T $concat(expr1 ; expr2 ) |
| expr1 + expr2 | T $add(expr1 ; expr2 ) |
| expr1 - expr2 | T $sub(expr1 ; expr2 |
| expr1 < expr2 | T $lt(expr1 ; expr2 ) |
| expr1 <= expr2 | T $le(expr1 ; expr2 ) |
| expr1 = expr2 | T $equal(expr1 ; expr2 ) |
| expr1 >= expr2 | T $ge(expr1 ; expr2 ) |
| expr1 > expr2 | T $gt(expr1 ; expr2 ) |
| expr1 ~< expr2 | ~ (expr1 < expr2 ) |
| expr1 ~<= expr2 | ~ (expr1 <= expr2 ) |
| expr1 ~= expr2 | ~ (expr1 = expr2 ) |
| expr1 ~>= expr2 | ~ (expr1 >= expr2 ) |
| expr1 ~> expr2 | ~ (expr1 > expr2 ) |
| expr1 &expr2 | T $and(expr1 ; expr2 ) |
| expr1 s∣ jexpr2 | T $or(expr1 ; expr2 ) |
| -expr | T $minus(expr) |
| ~expr | T $not(expr) |
expression1 cand expression2
is the boolean and of expression1 and expression2. However, if expression1expression1 cor expression2
is the boolean or of expression1 and expression2, but expression2 is not| Precedence | Operators |
| 5 | ** |
| 4 | * / // |
| 3 | + - || |
| 2 | < <= = >= > ~< ~<= ~= ~>= ~> |
| 1 | & cand |
| 0 | ∣ cor |
| Expression | Equivalent Form |
| a + b // c | a + (b // c) |
| a + b - c | (a + b) - c |
| a + b ** c ** d | a + (b ** (c ** d)) |
| a = b | c = d | (a = b) | (c = d) |
| -a * b | (-a) * b |
x: any := 3
y: int := force[int](x)
x: any := 3
y: int := x
body ::= { equate }
{ statement } % statements include declarations
tagcase expression
tag_arm { tag_arm }
[ others : body ]
end
tag_arm ::= tag name , ... [ ( idn: type_spec ) ] : body
The expression must evaluate to a oneof or variant object. The tag of this
statement except { when_handler }
[ others_handler ]
end
when_handler ::= when name , ... [ ( decl , ... ) ] : body
∣ when name , ... ( * ) : body
others_handler ::= others [ ( idn : type_spec ) ] : body
| idn = | proc [ parms ] args [ returns ] [ signals ] [ where ] |
| routine_body | |
| end idn |
| args | ::= ( [ decl , ... ] ) |
| returns | ::= returns ( type_spec , ... ) |
| signals | ::= signals ( exception , ... ) |
| exception | ::= name [ ( type_spec , ... ) ] |
| routine_body | ::= { equate } { own var } { statement } |
| idn = | iter [ parms ] args [ yields ] [ signals ] [ where ] |
| routine_body | |
| end idn |
yields ::= yields ( type_spec , ... )
| idn = | cluster [ parms ] is idn , ... [ where ] |
| cluster_body | |
| end idn |
| cluster_body ::= | { equate } rep = type_spec { equate } |
| { own var } | |
| routine { routine } | |
| routine ::= | procedure ∣ iterator |
where ::= where restriction , ...
where
| restriction | ::= | idn has oper_decl , ... |
| ∣ | idn in type set | |
| oper_decl | ::= | op_name , ... : type_spec |
| op_name | ::= | name [ [ constant , ... ] ] |
| type_set | ::= | { idn | idn has oper_decl , ... { equate } } |
| ∣ | idn |
3.14 3.14E0 314e-2 .0314E+2 3. .14Each implementation represents numbers in
| ∀r ∈ D | Approx(r) ∈ Real |
| ∀r ∈ Real | Approx(r) = r |
| ∀r ∈ D {0} | ∣(Approx(r) - r)/r∣ < 101-p |
| ∀r,s ∈ D | r ≤ s ⇒ Approx(r) ≤ Approx(s) |
| ∀r ∈ D | Approx(–r) = –Approx(r) |
| escape sequence | character |
| \' | ' (single quote) |
| \" | " (double quote) |
| \\ | \ (backslash) |
| \n | NL (newline) |
| \t | HT (horizontal tab) |
| \p | FF (form feed, newpage) |
| \b | BS (backspace) |
| \r | CR (carriage return) |
| \v | VT (vertical tab) |
| \*** | specified by octal value (exactly three octal digits) |
The escape sequences may also be written using upper case
letters. Examples of character literals are
`7'
`a'
\
"
`\"'
`\''
`\B'
`\177'
Operations
proctype ( [ type_spec , . . . ] ) [ returns ] [ signals ]
and an iterator type specification has the formitertype ( [ type_spec , . . . ] ) [ yields ] bn brack signals ]
where
| returns | ::= | returns (type_spec , . . .) |
| yields | ::= | yields (type_spec , . . .) |
| signals | ::= | signals (exception , . . .) |
| exception | ::= | name [ (type_spec , . . .) ] |