Identifiers
An identifier is the name, which identifies a variable, a class, an attribute, a
method, a type, or a package in the code.
Description
Identifiers are case-sensitive like in most programming languages.
An identifier can contain letters, digits, and underscores.
An identifier cannot start with a digit and cannot be equal to a reserved keyword.
Backticks
Enclose the identifier in backticks (``), if the identifier:
- Contains specific characters, such as, spaces.
Example: To quote the
Requirement Specification class in a condition, enter the
following code: `Requirement Specification` .
- Corresponds to a name, which is supposed to be a reserved word.
Example: To quote
the METHOD identifier in a condition, enter the following
code: `METHOD` .
Note:
You can use backticks (``) in conditions and in OTScript code elements.
Reserved Keywords
OTScript language contains reserved keywords.
Keywords are case-sensitive like in most programming languages.
Types |
Keywords |
Predefined variables
|
THIS , EACH ,
EACHINDEX |
Constant keywords |
TRUE , FALSE , VOID ,
I18N |
Control flow keywords |
TMP , IF , IFRE ,
IFNOT , ELSE , CATCH ,
DEFAULT |
Logical keywords |
ISA , AND , OR ,
NOT |
Collection keywords |
SORTBY , SELECTUNIQUE |
Class-object related keywords |
NEW , GETOBJECT |
Top-level keywords |
PACKAGE , CLASS , ATTRIBUTE ,
METHOD , LABEL , CATEGORY ,
HELPTEXT |
Literals
OTScript supports the following notations for representing values in the
code.
Type |
Examples |
Empty collection |
VOID(Boolean), VOID(Integer), VOID(String),
VOID(Requirement) |
Boolean value |
TRUE, FALSE |
Integer number value |
0, 1, -20 |
Real number value |
0.0, 1.1, -20.2 |
String syntax Note:
The table below lists the escape
characters.
|
"surrounded by double-quotes" |
Note:
There is no support for character literal in OTScript.
Table 1. Correspondance of String Escape-Sequences
Character |
Description |
"" |
Double-quote character |
"t |
Tabulation character |
"n |
Line separator (system dependent) |
"r |
Carriage return (CR) |
"l |
Line return (LF) |
"f |
Line feed |
"b |
Bell |
"u0AF9 |
16-bit character code point specified in hexadecimal |
Member Access
The member access lets you access attributes and methods.
The syntax access is as
follows: <expr>.<member> Evaluates the expression before
the period, and then applies the results to the member.
Predefined Variables
Some variables are predefined to help coding.
Most pieces of OTScript is bound to a predefined variable context.
Keyword |
Description |
THIS |
Refers to the receiver object of the current method in which
the code is executed. Usage: THIS.name |
EACH |
Refers to the value of the current iteration or
THIS when there is no iterator. |
EACHINDEX |
Refers to the index of the current iteration. |
Notes:
EACH and EACHINDEX can have as many
^ (caret) as there are parent iterators, making it possible to
reach the iteration value or index from an upper iterator.
EACH can be optional in the case of a member access.
ExamplesPrerequisite:
reqSpec is an element of a Requirement
Specification class.
-
To get requirement Req1 among all
requirements. reqSpec.getAllRequirements[EACH.name = "Req1"]
-
To get the third requirement from the list. (First index of the list is
1) reqSpec.getAllRequirements[EACHINDEX = 3]
To get a list composed of attribute name and their value of an XML
node. xmlNode.attributeNames.{ xmlNode.getAttribute(EACH).(^EACH $+ EACH)
}
Variables
Temporary variable definition can appear anywhere like any other
instruction. Variables are declared using the TMP keyword and an
identifier followed by a type or an expression to initialize the value.
The syntax to define a temporary variable is as follows:
TMP var { : <type> |:= <expr> }
From a syntax point of view, a variable declaration is considered as an instruction that
can only appear in an instruction block.
Examples
TMP i : Integer; // only the Integer type is specified, so it has no integer value.
TMP str := "A string"; // a value is specified so the type is inferred, it is a string variable.
Instruction Blocks
An instruction block defines a group of instructions separated by
; (semicolon) and surrounded by { } (curly brackets). It
returns the last expression result.
The syntax to define an instruction block is as follows:
{ <expr1> ; <expr2> ; … ; <exprN> }
A semicolon is not required to end the last instruction of a block.
From a syntax point of view, an instruction block is a considered as an expression so it
can be used at various places in the OTScript code.
Examples
{
TMP i := 0;
i := i + 1 // semicolon is not required for the last instruction of a block
}
|