April 2002 Draft
Tuesday, December 18, 2001
The above keywords are not reserved and may be used in identifiers.
2.0 references can be qualified by a qualifier, which, in the general syntax, is a ParenExpression
that must be a compile-time constant expression that evaluates to a namespace. For convenience,
if the ParenExpression consists of a single identifier, the parentheses
may be omitted:
(a)::m may be written as
The reserved words
private may also be used as qualifiers.
internal (which is not a reserved
word) evaluates to the containing package’s anonymous namespace.
can only be used inside a class and evaluates to the containing class’s anonymous namespace.
See the name lookup section for more information on the
A Number literal, ParenListExpression, or UnitExpression followed by a String literal is a unit expression, which is evaluated as follows:
Evaluate the String literal to obtain a string S. Parse that string according to
the unit grammar and semantics to obtain
a list of identifiers and exponents [id1e1,
id2e2, ..., idnen].
If the parse fails, signal a syntax error. If the list is empty, let U be the function
accepts one required and one optional argument and returns its first argument, ignoring the optional argument.
If the list is not empty, for each i between 1 and n, let Vi be the value of
looking up the class property idi of the
Unit class. If ei is 1,
let Fi = Vi; otherwise, let Fi = Vi
Then let U = F1
For example, if S is
"Kg*m^2/s^2*q", then U is the value of
The result U should be callable as a function that accepts one required and one optional argument. The unit
expression calls U, providing the numeric value of the Number literal, ParenListExpression,
or UnitExpression as the first argument. The second argument is present
only for the UnitExpression Number [no line break] String
production, in which case it is the original Number literal expressed as a string. Continuing
the example above, the unit expression
32.50 "Kg*m^2/s^2*q", evaluates to the result of
U’s second argument allows user-defined unit classes to define extended syntaxes for numbers. For instance,
a long-integer package might define a unit called
"L" that treats the Number literal
as a full 64-bit number without rounding it to a float64 first. Such a unit can be combined with other units by listing the
units one after another; note that the lexer allows the first unit to be unquoted if it directly
follows the number:
3L "cm" is the same as
3 "L" "cm" and evaluates to the result
Unit class is predefined by the system. A program can define additional units by using a class
unit attribute is conveniently provided to make
a definition into a class extension. For example:
unit const µm = Unit.m/1e6; unit const Å = Unit.m/1e10; unit const dm = Unit.m/10; unit const \_in = Unit.m*0.0254; unit const liter = Unit.dm.pow(3);
\_ must be used to define the unit
in is a reserved word. However, the
in may be used without quoting it, as in the expression
3in + 5cm.
public evaluates to the
this may only be used in methods, constructors,
or functions with the
prototype attribute set.
A FunctionExpression creates and returns an anonymous function.
A ParenExpression must evaluate to a string.
super, which may only be used inside a class C, can be applied to a subexpression that evaluates
to an instance v of C. That subexpression can be either a ParenExpression
or omitted, in which case it defaults to
As specified in the grammar below, the SuperExpression must be embedded as an operand to one of the following operators:
inoperator (for the
new()operators the SuperExpression must be a FullSuperExpression)
super changes the behavior of the operator in which it is embedded by limiting its property search to definitions
inherited from class C’s superclass. See property lookup and
A SimpleQualifiedIdentifier or ExpressionQualifiedIdentifier expression id resolves to the binding of id in the innermost enclosing scope that has a visible binding of id. If a qualifier q is present before the id, then the QualifiedIdentifier expression resolves to the binding of id in the innermost enclosing scope that has a visible binding of id in the namespace q.
. operator accepts a QualifiedIdentifier as the
second operand and performs a property lookup.
 operator can take multiple (or even named) arguments. This allows programmers
to define data structures such as multidimensional arrays via operator overriding.
 operator is overridden for an object o, the expression o
explicitly coerces m to a
and returns the result of o
.s, limiting the name lookup to the
properties of o. See property lookup.
A list of arguments can contain both positional and named arguments. The positional arguments are the subexpressions separated by commas within the ListExpressionallowIn. Named arguments use the same syntax as object literals. All strings except those consisting entirely of digits are legal for argument names. No two arguments may have the same name. The order of named arguments is immaterial.
type of an object x, use x
The expression a
is b takes an expression that must evaluate
to a type as its second operand b. When a is not
null, the expression a
true if a is a member of type b and
otherwise; this is equivalent to testing whether a can be stored in a variable of type b without coercion.
When a is
is b behaves analogously to method
dispatch and returns
true if b is either
otherwise. As a special case, when a is –0.0 and b is
is b returns
The expression a
as b returns a if a
is a member of type b. Otherwise, if a can be implicitly
coerced to type b, then the result is the result of that implicit coercion. Otherwise, a
null is a member of type b or throws an exception otherwise. In any case
b must evaluate to a type.
1.5 — a
instanceof b follows a’s prototype chain.
^^ operator is a logical exclusive-or operator. It evaluates both operands. If they both convert to true
or both convert to false, then
^^ returns false; otherwise
^^ returns the unconverted value of whichever
argument converted to true.
A compile-time constant expression is an expression that either produces an error or evaluates to a value that can be determined at compile time.
The reason that a compile-time constant expression is not guaranteed to always evaluate successfully at run
time is that global name lookup cannot be guaranteed to succeed. It is possible for a program to import a package P
that defines a global constant P
::A that can be accessed as A and then dynamically
define another top-level variable Q
::A that collides with A. It does not appear
to be practical to restrict compile-time constant expressions to only qualified names to eliminate the possibility of such
A compile-time expression can consist of the following:
null, numeric, boolean, and string constants.
+(unary and binary),
-(unary and binary),
,as long as they are used only on numbers, booleans, strings,
A reference R to a definition D of a compile-time constant is allowed inside a compile-time constant
expression as long as the conditions below are met. If D was imported from another package, then the location of
D is considered to be the location of the
import directive. If D is visible to R
by virtue of an intervening
use directive U, then the conditions below have to be satisfied both with
respect to D and R and with respect to U and R.
usedirective between D and R.
Some compile-time constant expressions only allow references to definitions that are textually prior to the point of the reference. Other compile-time constant expressions allow forward references to later compile-time constant definitions.
constdefinitions with the
compileattribute must have initializers that are compile-time constant expressions. These expressions cannot contain forward references.
namespacedirective must dominate the end of the program or package. This restriction limits these statements to the top level of the program, a top-level block, or a top-level conditional whose condition is known at compile time.
A statement A dominates statement B if any of the following conditions are met:
defaultlabels between them.
false, and C dominates B.
Note that the above definition is conservative. If statement A dominates statement B, then it is guaranteed that, if B is executed then A must have been executed earlier; however, there may be some other statements A' that also are guaranteed to have been executed before B but which do not dominate B by the above definition.
A statement A is dead if any of the following conditions are met:
throwstatement B such that statements A and B are in the same block with B before A and no
defaultlabels between them.
Note that the above definition is conservative. If a statement is dead, then it is guaranteed that it cannot be executed; however, there may be statements that cannot be executed that are not dead by the above definition.
A statement is live if it is not dead.
Last modified Tuesday, December 18, 2001