LSPS documentation logo
LSPS Documentation
Expressions

An expression is a combination of keywords, operators, and literals, and names of data types, variables, model elements, functions and methods. It always returns its resulting value. For example, "Hello " + getWorld() concatenates the strings, "Hello " and the string returned by the getWorld() function call, and returns the concatenation.

//while names with whitespaces are strongly discouraged,
//such names must be wrapped in single quotes:
def Integer 'my number' := 1;
def String var := "hello";
//expression returns the right side "hello":

Chaining Expressions

To chain multiple expression into a single expression, connect them with a semi-colon or a new line. Such a chained expression returns the return value of the last expression in the chain. Intermediary return values of the other chained expressions are ignored.

def String varString; varString := "Hello" //two expressions chained by a semi-colon (;)
varString:=varString + "World" //an expression chained by a new line

Block

An expression block is an expression with its own contexts.

Expression blocks follow the visibility rules of contexts: the data in an expression block, such as, an expression variable, cannot be access from outside of the block.

The if, then, else, switch, foreach, while, for content represent an expression block. You can create an expression block explicitly as well: start the block with the begin keyword and finish it with the end keyword.

begin
//declaration of an expression variable:
def Boolean visibility := true
   //beginning a codeblock
   begin
     //declaration of an expression variable in the block (not available out of the block):
     def Boolean visibility := false;
     visibility == false;
   end;
visibility == true;
end;

Literals

Literals represent fixed values. The notation of literals depends on the data type they represent. The notation is documented in Data Types.