Variable and Type Declarations

SPLASH variable declarations resemble those in C: the type precedes the variable names, and the declaration ends in a semicolon. The variable can be assigned an initial value as well.

Here are some examples of SPLASH declarations:

integer a, r;
float b := 9.9;
string c, d := 'dd';
[ integer key1; string key2; | string data; ] record;

The first three declarations are for scalar variables of types integer, float, and string. The first has two variables. In the second, the variable "b" is initialized to 9.9. In the third, the variable "c" is not initialized but "d" is. The fourth declaration is for a record with three columns. The key columns "key1" and "key2" are listed first before the | character; the remaining column "data" is a non-key column. The syntax for constructing new records is parallel to this syntax type.

The typeof operator provides a convenient way to declare variables. For instance, if rec1 is an expression with type [ integer key1; string key2; | string data; ].
typeof(rec1) rec2;
The above declaration is the same as the following declaration:
[ integer key1; string key2; | string data; ] rec2;
SPLASH type declarations also resemble those in C. The typedef operator provides a way to define a synonym for a type expression.
typedef float newFloatType;
typedef [ integer key1; string key2; | string dataField; ] rec_t;
These declarations create new synonyms newFloatType and rec_t for the float type and the given record type, respectively. Those names can then be used in subsequent variable declarations which improves the readability and the size of the declarations:
newFloatType var1;
rec_t var2;