Titan



var

1. Declaring a variable of built-in type

2. Declaring a variable of referenced type

3. Multiple declaration of variables of the same type

4. Declaring a variable array


1. Declaring a variable of built-in type


var ( bitstring | boolean | charstring | universal charstring | integer | octetstring | objid | hexstring | verdicttype | float | address | default | anytype ) var_identifier  [:= single_variable_expression ] ;

   TITAN specific restriction compared to the standard: anytype is not implemented yet.
  • anytype defines as a shorthand for the union of all defined types, imported ASN.1 and other imported external types.

Example


2. Declaring a variable of referenced type


var [ module_id [.obj_id ].] type_reference [.field_reference ] var_identifier  [:=  
single_variable_expression | value_list | value_assginment_list ];

   TITAN specific restriction compared to the standard: objid  is not implemented yet; it is discarded when encountered.
  • obj_id is an optional object identifier which may follow the TTCN-3 module identifier.

   TITAN specific restriction compared to the standard: field reference can only be used with structured variables defined in the module definition part.
   TITAN specific restriction compared to the standard: value assignment can only be used with structured variables defined in the module definition part.
  • The optional value_assignment_list is a comma-separated list of the field name - variable value pairs between curly brackets. Used with structured types to define an initial value.

Example


3. Multiple declaration of variables of the same type


var type  identifier1 [ := variable_expression1], identifier2  [:= variable_expression2 ]… ;

Example


4. Declaring a variable array


var type var_identifier [ array_index ] [:= value_list];

Example



Example 1a:

var integer v_myVariable := 127;

A variable called v_MyVariable is defined. The variable will have the initial value one hundred twenty seven.


Example 1b:

var bitstring v_myGarland := '00101101'B; 
var bitstring v_myBiggerGarland := v_myGarland & '11000010'B;

Two variables are defined. The one called v_myBiggerGarland initially will have the binary value 11101111.


Example 2a:

type record E_Rec {integer field1, boolean field2}; //defined in Elsewhere

var Elsewhere.E_Rec v_CurrVar := {17, true};

A record called E_Rec have been defined in the TTCN-3 module Elsewhere. In the current module we define a variable named v_CurrVar and assign values to all of its fields. In TITAN, the value notation as shown above may only be used in the module definition part.


Example 2b:

type record G_Rec {float first_field, hexstring last_field}; 
var G_Rec.last_field v_FuzerVar;

First we define a record called G_Rec. Then we define a variable named v_FuzerVar derived from the second field of the referred type and assign no initial value to it. 


Example 2c:

type record G_Rec {float first_field, hexstring last_field}; 
var G_Rec v_UeppigVar := {
    first_field := 5.77,
    last_field := '55'H;
}

First we define a record called G_Rec. Then we define a variable named v_UeppigVar and assign initial values to both of its fields using assignment notation.


Example 3:

var boolean v_MyVar2 := true, v_MyVar3;

Two variables (v_MyVar2 and v_MyVar3) are declared within one operation. The latter variable has no initial value assigned.


Example 4a:

var boolean v_MinVar[3] := { true, false, false };

The array defined v_MinVar consists of three elements indexed from 0 to 2.


Example 4b:

var boolean v_DinVar[7..9] := { true, false, false };

The array defined v_DinVar consists also of three elements as in the example 4a, but here the indices run from 7 to 9.



BNF definition of var