Programming http://www.inf.ethz.ch/personal/gonnet/ContDict/Programming 31/Dec/1997 experimental Basic A programming CD which allows to exchange scientific
programs and algorithms between some common languages.
Formal, Constructor Declaration This statement associates names of variables
with types and values. Each argument of the Declaration
is an equation. The left-hand side of the equation is
a variable or a list of variables which are being
declared. The right-hand side of the equation is a
TypeTokens. Each variable on the lhs is declared
to be of the type and values contained in the rhs.
Declarations can appear in Blocks or at the top level.
When they appear at the top level they are valid for
the entire program. When they appear in a Block they
are valid for the entire Block. If a variable is
declared in more than one nested Block, the closest
enclosing Declaration is used.
With minor restrictions, the arguments of Declaration
follow the same syntax as the arguments for TypeDeclaration,
Parameters and Record.
Nary Sequence( Equation( Union( symbol, List(symbol)),
TypeTokens() )) -> constructor n Integer a b Float Long Local TypeDeclaration This statement associates names with types.
These names can be used instead of the explicit types.
Non-trivial types are best defined by a TypeDeclaration
once and then used (maybe several times) for variable
declarations. Each argument of the TypeDeclaration is
an equation. The left-hand side of the equation is
a name or a list of names which are being declared.
The right-hand side of the equation is a TypeTokens.
Each name on the lhs is associated with the TypeTokens
on the right-hand-side. TypeDeclarations should appear
at the top level. They are global and valid for all
the programs and functions defined. With minor
restrictions, the arguments of TypeDeclaration follow
the same syntax as the arguments for Declaration,
Parameters and Record.
Nary Sequence( Equation( Union( symbol, List(symbol)),
TypeTokens() )) -> constructor
complex
real imag Float Long Function This construction defines a function.
A function receives some arguments and computes a value
which is being returned. A function definition has four
arguments. The first argument is its name. The second
argument describes the parameters passed to the function
(see Parameters). The third argument is the TypeTokens
of the value returned by the function. The fourth argument
is typically a Block, but could be any Statement, and it
is the body of the function, that is all the statements
that will be executed when the function is invoked.
A function can only return a scalar value. That is a
simple type. Simple types are all types defined in this
CD excluding Arrays and Records.
4ary ( symbol, Parameters(), TypeTokens(), Block() ) ->
constructor Procedure This construction defines a procedure.
A procedure receives some arguments and computes but does
not return any explicit value. A procedure definition has
three arguments. The first argument is its name. The
second argument describes the parameters passed to the
procedure (see Parameters). The third argument is typically
a Block, but could be any Statement, and it is the body of
the procedure, that is all the statements that will be
executed when the procedure is invoked.
Ternary ( symbol, Parameters(), Block() ) -> constructor
Program This construction defines a complete program.
A program does not receive any arguments and does not
return any explicit value. A program definition has
two arguments. The first argument is its name. The
second argument is typically a Block, but could be any
Statement, and it is the body of the program, that is
all the statements that will be executed when the program
is executed.
Binary ( symbol, Block() ) -> constructor Local In a declaration this is an indication that
the name(s) defined are only valid within the declaration.
Names, coinciding with the name(s) declared, defined in
an outer scope become unreachable. Unless a Constant(...)
declaration is also used, the name(s) declared should not
be used before assigning them a value.
The name Local cannot be used inside a TypeDeclaration,
Parameters or Record DeclSequence.
Constant () -> constructor Declaration Global In a declaration this is an indication that
the name(s) defined are global names, that is a single
instance of the variable is accessible to all the code.
Unless a Constant(...) declaration is also used, the
name(s) declared should not be used before assigning
them a value. The name Global cannot be used inside a
TypeDeclaration, Parameters or Record DeclSequence.
Constant () -> constructor Declaration Integer In a declaration, type declaration, parameter
or record, this is an indication that the name(s) defined
will hold integer values. The range of valid integers
depends on other qualifiers (Short, Long). Integers are
assumed to be signed integers.
Constant () -> constructor Declaration TypeDeclaration Parameters Record Float In a declaration, type declaration, parameter
or record, this is an indication that the name(s) defined
will hold floating point values. The precision and range
of valid floating point numbers depends on other qualifiers
(Short, Long). It is assumed that the definition of a
Float (and its precision qualifier) comply with the IEEE
standard for floating point representation.
Constant () -> constructor Declaration TypeDeclaration Parameters Record Char In a declaration, type declaration, parameter
or record, this is an indication that the name(s)
defined will hold character values (ascii or unicode).
Strings are defined as arrays of characters.
Constant () -> constructor Declaration TypeDeclaration Parameters Record Type This construct takes one argument. In a
declaration, type declaration, parameter or record,
this is an indication that the name(s) defined will
hold values of the same type as the argument of Type.
Constant () -> constructor Declaration TypeDeclaration Parameters Record Short In a declaration, type declaration, parameter
or record, this is an indication that the name(s) defined
will be as short as possible. For integers, this is at
least 16-bits signed integers; for floating point numbers
this is at least 32-bit floating point numbers according
to the IEEE standard.
Constant () -> constructor Declaration TypeDeclaration Parameters Record Long In a declaration, type declaration, parameter
or record, this is an indication that the name(s)
defined will be longer than normal. For integers,
this is at least 64-bits signed integers; for floating
point numbers this is at least 64-bit floating point
numbers according to the IEEE standard. For characters,
this is at least a 16-bit encoding.
Constant () -> constructor Declaration TypeDeclaration Parameters Record Constant In a declaration, type declaration, parameter
or record, this construction assigns an initial value
to the variable(s) declared. Constant takes a single
operand. The type of the operand should match the type
of the variable(s) being declared.
Unary anything -> constructor Declaration TypeDeclaration Parameters Record Array In a declaration, type declaration, parameter
or record this is an indication that the variable(s)
defined are arrays. Array takes k+1 arguments, where
the first k define the dimensions of the array. The
last argument of Array defines the type of the elements
of the array. The first k arguments are segments, as
defined in Basic.
Nary Sequence( anything ) -> constructor Declaration TypeDeclaration Parameters Record Record In a declaration, type declaration, parameter
or record this is an indication that the variable(s)
defined are records. The format of the arguments to
Record is the same as for Declaration, TypeDeclaration
or Parameters.
Nary Sequence( Equation( Union( symbol, List(symbol)),
TypeTokens() )) -> constructor Declaration TypeDeclaration Parameters Record Parameters In a function or procedure declaration this
is a description of the name and type of the variables
which are passed as parameters. The format of the
arguments to Parameters is the same as for Declaration,
TypeDeclaration or Parameters. Inside a Parameters
declaration, the names Local, Global, and Constant cannot
be used.
Scalar parameters (integers, floats or characters) are
passed by value. Structured parameters (Arrays or
Records) are passed by reference. This has the following
consequences:
(a) Inside a Function or Procedure, the names of
the Parameters can never be assigned, that is they cannot
be on the lhs of an Assign statement.
(b) Components of the Structured parameters can be
assigned inside a Function or Procedure, and these
assignments will change the structures which have been
used in the calling statement.
(c) The behaviour of parameters defined with other
types (not defined in this CD) is not defined, and there
are no guarantees on how they will behave in a particular
system.
Nary Sequence( Equation( Union( symbol, List(symbol)),
TypeTokens() )) -> constructor Function Procedure Assign This statement has two parameters. The first
one is a variable name or selector (or an array or record).
The second parameter is an arbitrary expression (written
using the OpenMath Basic CD and/or others). The result
of the execution of the Assign is that the value computed
for the second parameter is assigned to the variable name
or to the selected array entry or record field.
If the first argument of Assign is an indexed name (using
the select construct in OpenMath), then the corresponding
entry in the Array or the corresponding field in the Record
are assigned. (See comments on selectors at the end).
Binary (symbol anything) -> constructor Block Function Procedure Program ForLoop ForWhile If v v 1 x Block A Block defines a sequence of statements which
are executed as a single unit. A Block is used every time
that more than one statement has to be executed in a
Function, Procedure, Program, ForLoop, ForWhile or If
statement.
A Block may have Declaration statements. In this case,
the Local variables declared will be accessible to the
statements in the Block alone. Their scope is the Block.
A Block is equivalent to "{ ... }" in C or begin ... end
in Pascal.
Nary Sequence(anything) -> constructor Block Function Procedure Program ForLoop ForWhile If t x t x x y y t Comment Definition of a comment. The arguments of this
statement are strings. These will be inserted as comments
in the generated code. They serve no other purpuse than
documentation.
Nary Sequence(string) -> constructor Block Function Procedure Program ForLoop ForWhile If Error An Error is an executable statement that will
terminate the execution of the entire program. The arguments
to Error are used to indicate the cause of the error to the
user. They will normally be strings.
Nary Sequence(anything) -> constructor Block Function Procedure Program ForLoop ForWhile If m 1000 "too many data points, tables overflowed" ForLoop An integer repetition statement.
This statement repeats the execution of its last argument,
a statement or a Block of statements, for consecutive values
of the "LoopVariable". The argumets to ForLoop are:
ForLoop( LoopVariable, InitialValue, Increment, LastValue, Block )
Formally, the ForLoop executes as follows:
LoopVariable := InitialValue;
while Increment > 0 and LoopVariable ≤ LastValue or
Increment < 0 and LoopVariable ≥ LastValue do
Block;
LoopVariable := LoopVariable+Increment
od;
(A Break statement inside Block should be read as a Goto
to the statement immediately following the loop, a Next
statement inside Block should be read as a Goto to the
LoopVariable := LoopVariable+Increment statement).
This is equivalent to
for LoopVariable from InitialValue by Increment to LastValue do
Block od;
in Maple, and to
for( LoopVariable=InitialValue;
Increment > 0 && LoopVariable ≤ LastValue ||
Increment < 0 && LoopVariable ≥ LastValue;
LoopVariable += Increment ) Block;
in C.
5ary (symbol integer integer integer Block()) -> constructor
Block Function Procedure Program ForLoop ForWhile If ForWhile A conditional repetition statement.
This statement repeats the execution of its last argument,
a statement or a Block of statements, while a boolean
expression evaluates to true. The ForWhile could be viewed
as modelled after the "for" statement in C. The arguments
to ForWhile are:
ForWhile( Initial, Condition, Repeat, Block )
Formally, the ForWhile executes as follows:
Initial;
Label: TopOfLoop;
if Condition = true then
Block;
Repeat;
Goto TopOfLoop
fi;
(A Break statement inside Block should be read as a Goto
to the statement immediately following the loop, a Next
statement inside Block should be read as a Goto to the
Repeat statement).
This is equivalent to
Initial; while Condition do Block; Repeat od;
in Maple and to
for( Initial; Condition; Repeat ) Block;
in C.
4ary (Statement() boolean Statement() Block()) -> constructor
Block Function Procedure Program ForLoop ForWhile If Break Break out of the nearest enclosing ForLoop
or ForWhile. Identical to break in Maple or C.
Constant () -> constructor Block ForLoop ForWhile If Next Continue with the next iteration of then
nearest enclosing ForLoop or ForWhile. Identical to
next in Maple or continue in C.
Constant () -> constructor Block ForLoop ForWhile If If One-branch conditional statement (no else).
The format of this statement is: If( Condition, Block ).
The Condition is evaluated first. If it evaluates to
true, then the statements in Block are executed.
Binary (boolean Block()) -> constructor Block Function Procedure Program ForLoop ForWhile If If Two-branch conditional statement (if else).
The format of this statement is: If( Condition, TBlock, FBlock ).
The Condition is evaluated first. If it evaluates to
true, then the statements in TBlock are executed, otherwise
the statements in FBlock are executed.
Ternary (boolean Block() Block()) -> constructor Block Function Procedure Program ForLoop ForWhile If Return Return from a Procedure or exit/terminate a Program.
This statement terminates the execution of a Procedure or a
Program. No result is returned (neither procedures nor
programs are expected to return values). There is no need
to use a Return statement at the end of the Block in the
body of the Procedure or Program, a Return statement is
implicitly assumed to exist there.
Constant () -> constructor Block Procedure Program ForLoop ForWhile If Return Exit from a Function and return a given value.
This statement terminates the execution of a procedure or a
program. The argument of Return is returned as a value of
the Function called. The type of this argument should
coincide with the type declared for the function return.
A Return statement is needed at the end of the Block in
the body of the Function, if the execution would ever
fall through.
Unary anything -> constructor Block Function Program ForLoop ForWhile If