Identifiers
An identifier is the name, which can identify in the code:
- A variable
- A class
- An attribute
- A method
- A type
- A package
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:
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 |
| List 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.
Note:
There is no support for character literal in OTScript.
| Type |
Examples |
| Empty list |
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" |
Table 1. Correspondence 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.
AccessThe syntax access is as
follows: <expr>.<member>Evaluates the expression before
the period, and then applies the results to the member.
Assignments
The following assignments are available for member accesses of attribute type:
| Keyword |
Description |
:= |
obj1 := obj2 defines obj1. |
+= |
obj1 += obj2 is equivalent to obj1 := obj1 $+
obj2. |
-= |
obj1 += obj2 is equivalent to obj1 := obj1 $-
obj2. |
Recommendation:
Compare PLM objects based on the properties that you can see,
because comparing the same PLM references may return different results.
Predefined Variables
Some variables are predefined to help coding.
Most pieces of OTScript are 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 names 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. To
declare variables, use the TMP keyword and an identifier followed by a type
or an expression to initialize the value.
Simple Assignment
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.
Assignment by Sum or Difference
The following assignments are also available:
| Keyword |
Description |
+= |
var1 += var2 is equivalent to var1 := var1 $+
var2. |
-= |
var1 += var2 is equivalent to var1 := var1 $-
var2. |
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 you
can use it 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
}
|