Subsections
Identifier Expressions
We call an identifier expression an unary or binary expression whose operands
must be identifiers. There are height identifier operators: ::,
isset, unset, & (identical to refof),
* (identical to valof), scopeof, push
and pop.
As all these operators take identifiers as their operands,
we skip the second table (operand combinations) while introducing these
operators.
The :: unary/binary operator (called scope operator) is used to
define a global or particular scope for a variable.
The unary version of this operator denotes a global scope.
For instance, ::alpha denotes the global variable alpha.
In the body of a function, identifiers denote local variables; outside
the body of a function identifiers denote global variables, that means
that, in this context, the global scope operator is not mandatory.
If one wants to use a global variable in the body of a function, the
global scope operator is mandatory.
Refer to the Function Definition Statement Section for more information
about local function variables.
The binary version of this operator denotes a particular scope.
For instance, Person::checkName denotes the class attribute
or method of the class Person.
note: class (or static) attributes are not currently well supported
by the OQL interpreter. Class attributes are only supported in some
specific query expressions (refer to the Query Expression Section).
General Information |
Operator |
:: |
Syntax |
:: identifier |
|
identifier::identifier |
Type |
unary and binary |
Operand Types |
identifier |
Result Type |
value of the identifier if used as a right value;
identifier reference if used as a left value |
Function |
defines a global or particular scope for the identifier. |
Expression Examples |
expression |
result |
::a |
the value of the global variable a |
::alpha := 1 |
sets the value of the global variable
alpha to 1, returns 1 |
Person::checkName("wayne") |
calls the class method
checkName in the class Person |
2::alpha |
raises an error |
The isset operator is used to check whether a variable
is already set or not. It returns true is the variable is
set, false otherwise.
General Information |
Operator |
isset |
Syntax |
isset identifier |
Type |
unary |
Operand Type |
identifier |
Result Type |
boolean |
Function |
evaluated to true if the identifier is set, false otherwise |
Expression Examples |
expression |
result |
isset oql$variables |
true |
isset a |
returns true if a is set, false otherwise |
isset 1 |
raises an error |
The unset operator is used to unset an variable. It returns the
nil atom.
General Information |
Operator |
unset |
Syntax |
unset identifier |
Type |
unary |
Operand Type |
identifier |
Result Type |
nil |
Function |
unset the identifier |
Expression Examples |
expression |
result |
unset a |
nil |
unset ::a |
nil |
unset 2 |
raises an error |
The & (identical to refof) operator is used to get the
reference of an identifier. This operator is essentially used when
one calls a function or method which updates one or more given parameters.
For instance, let the function swap(x, y) which swaps the value
of its two parameters. One needs to give the references of the
variables that one wants to swap. For instance:
i := "ii";
j := "jj";
swap(&i, &j);
After the call to swap, the variable i equals
jj while the variable j equals ii.
The reverse operator * (described following section) is used in
the swap function.
General Information |
Operator |
refof |
|
& |
Syntax |
refof identifier |
|
& identifier |
Type |
unary |
Operand Type |
identifier |
Result Type |
identifier |
Function |
evaluates the expression to the identifier reference; returned an
identifier atom |
Expression Examples |
expression |
result |
&alpha |
alpha |
refof alpha |
alpha |
The * (identical to valof) operator is used to get
the value of the identifier pointed by a reference.
For instance, after the two following expressions:
alpha := 1;
ralpha := α
*ralpha equals 1.
This operator may be used in the composition of a left value, for instance:
alpha := 1;
ralpha := α
*ralpha := 2; // now, alpha equals 2
*ralpha += 8; // now, alpha equals 10
But this operator is essentially used in the body of functions or methods which
update one or more given parameters, for instance, the function swap
described in the previous section is as follows:
function swap(x, y) {
v := *x;
*x := *y;
*y := v;
}
General Information |
Operator |
valof |
|
* |
Syntax |
valof identifier |
|
* identifier |
Type |
unary |
Operand Type |
identifier |
Result Type |
value of the identifier |
Function |
returns the value of the identifier denotes by the operand |
Expression Examples |
expression |
result |
*alpha |
if alpha value is an atom identifier x,
returns the value of x, otherwise an error is thrown |
x := 12; alpha := &x; *x |
*x returns 12 |
The scopeof operator returns the string "global" or
"local" depending whether the identifier is global or local.
General Information |
Operator |
scopeof |
Syntax |
scopeof identifier |
Type |
unary |
Operand Type |
identifier |
Result Type |
string |
Function |
returns the scope of the identifier. |
Expression Examples |
expression |
result |
scopeof ::alpha |
returns "global" for any alpha if
it set; otherwise an error is thrown |
scopeof alpha |
returns "global" or "local"
depending on the context. |
The push operator is used to push an identifier on a new local
table. This operator is rarely used.
General Information |
Operator |
push |
Syntax |
push identifier |
|
push identifier := expr |
Type |
unary and binary |
Operand Types |
first operand identifier, optionnal second operand:
any type |
Result Type |
identifier or any type in case of an assignment |
Function |
push the identifier on to the symbol table stack. An assignment
can be performed at the same time. Returns the identifier or the
value of the expression assignment. |
Expression Examples |
expression |
result |
push a |
pushes a on a new local symbol table. |
push a := 10 |
pushes a on a new local symbol table
and assigns its value to 10 |
The pop operator is used to pop an identifier from a local table.
It is used after a push. For instance:
a := "hello";
a; // a equals "hello"
push a := 10;
a; // a equals 10
pop a;
a; // a equals "hello"
General Information |
Operator |
pop |
Syntax |
pop identifier |
Type |
unary |
Operand Type |
identifier |
Result Type |
the type of the value of the identifier |
Function |
pop the identifier from the symbol table stack |
Expression Examples |
expression |
result |
pop a |
returns the value of a if it is set; otherwise
an error is returned |
EyeDB manual