Expressions are:
function call
equality
type equality
in-expression (sets)
create
this
BNF:
expression ::= function-call
| operator-expression
| reference-equality
| type-equality
| in
| create
| old
| this
A function call is a call to a routine which returns one or more values.
BNF:
function-call ::= call-chain
call-chain ::= unqualified-call { "." unqualified-call }
unqualified-call ::= identifier [ "(" expression-list ")" ]
Examples:
x := func
a,b := func (1)
if obj.func (a,b+c) then ...
found, element := list.search (22);
if found then
print (element)
end if
A function call is syntactically similar to a procedure call. Since a function returns values, it is used in an expression rather than as a statement. A function can return one or more values, which can then be assigned to variables in a (multi-)assignment.
If a function returns exactly one value, it can also be used in expressions such as the condition of an if statement or in an actual parameter list. Functions returning multiple values can only be used in a multi-assignment statement.
If a function has no parameters, a call to that function consists of its name only (no parentheses are written to indicate an empty parameter list).
BNF:
reference-equality ::= expression comparison expression comparison ::= "=" | "<>"
Examples:
a = b
found = true
a <> 42
See section 3.2.2 (Comparison).
BNF:
type-equal ::= expression is type
Examples:
var
f: Figure
r: Rect - - inherits from figure
... if f is Rect then
r := f
end if
The keyword is checks whether a variable is of a given type. The result is a boolean value. The expression
ident is Mytype
is true, if the dynamic type of ident is Mytype or a subclass of Mytype. In other words: The expression is true, if the dynamic type of ident conforms to Mytype.
BNF:
in ::= expression in set_expr
set_expr ::= "{" [ set_elem { "," set_elem } ] "}"
set_elem ::= expression | subrange
subrange ::= expression ".." expression
if num in {1, 3, 5, 7} then ...
if n in {1..10} then ...
valid := x in {" ", "\t", "0".."9" }
In expressions are aliases and are defined by combinations of comparisons:
n in {a, b} is defined as n = a or n = b
n in {a..b} is defined as n>=a and n<=b
n in {a, b..c} is defined as n = a or (n>=b and n<=c)
BNF:
create ::= general-create | array-create
general-create ::= create class-ident [ "(" expression-list ")" ]
array-create ::= "[" expression { "," expression } "]"
Example:
var
r : Rectangle
b : Buffer
... r := create Rectangle (p1, p2, c)
b := create Buffer
The create keyword creates an object of the specified class and executes its creation routine. Parameters to the creation routine are passed in a parameter list after the class name. If the creation routine has no parameters, the create call has no parameter list. (If the class does not specify a creation routine, a default routine without parameters is generated).
BNF:
expression ::= this
Example:
list.add (this)
The expression this is a reference to the currently active object. It can be used to pass the current object reference to other objects.