
HANDBOOK
/ LANGUAGE REFERENCE MANUAL
/
Expressions
Expression = Expr2
|
Expression ( "+" | "-" ) Expr2 .
Expr2 = Expr3
|
Expr2 ( "*" | "/" ) Expr3 .
Expr3 =
IdentUC
| Number
| String
|
Functor
["("[Expression{ "," Expression}]")"]
|
( "+" | "-" ) Expr3
| "(" Expression ")"
Functor =
[Ident "'"] IdentLC .
An expression describes the computation of a value.
The value of an expression E on a position with type T
is computed as follows.
Variables
If E has the form
where V is a variable, the value of the expression is the value of the
variable. The type of the variable must be T.
Numbers
If E has the form
where N is a number,
T must be INT.
The value of E is the value of the number.
Strings
If E has the form
where S is a string,
T must be STRING.
The value of E is the value of the string.
Terms
If E has the form
the declaration of T must contain a functor specification
f ( T1 , ... , Tn ).
E1, ..., En
appear on positions with types
T1, ..., Tn.
E1, ..., En
are evaluated yielding values
Sigma1, ..., Sigman.
The value of E is given as
f ( Sigma1 , ... , Sigman ).
If the type T of the position is unknown (in the case of generic
predicates) and if f is defined for more than one type,
f must be prefixed by the type:
T ' f .
|
|
|
Example
list(X1, list(yellow, X2))
If the value of X1 is red
and the value of X2 is nil,
the value of the expression is
list(red(list(yellow,nil)).
|
|
|
Arithmetic Expressions
If E has the form
where op is one of +, -, *, /,
T must be INT and
E1 and E2 must be expressions of type INT.
The value of P is computed by applying the operator to the values
of E1 and E2.
If E has the form
where op is one of +, -,
T must be INT and
E1 must be an expression of type INT.
The value of P is computed by applying the operator to the value
of E1.
If E has the form
the value of E is the value of E1.
E1 must be an expression of type T.
