DOORS DXL Tutorial Part 2
In this series of articles, I am going to explain to you IBM DOORS DXL scripting from scratch. So, if you are a beginner in DXL scripting, hopefully, this article will help you. This is part-2 of the DOORS DXL tutorial.
So, if you are looking for a starting point to learn DXL scripting, you are on the right page! I know, we have the DXL reference manual and it’s a bit concise and difficult to grasp for beginners, especially if you do not have any previous experience in other programming languages.
In the previous article (Part-1), I explained how to write a simple Hello World program. In this article series, we will mainly discuss the data types in DXL scripting.
What is an Identifier in DXL?
Identifier is nothing but a variable, data types, functions, and values.
Basic Data Types in DXL
Here are the fundamental data types that are available in DXL scripting:
Basic Data Type in DXL | Description |
---|---|
int | Integer type. It is a 32-bit integer type. |
real | Similar to float or double type in C/C++. It is 64-bit precision. |
char | Similar to character type in C/C++. |
string | string data type. |
bool | Boolean data type to represent true or false. |
void | Empty data type. It is mainly used for function return types. |
Variable declaration and initialization
Now, we know all the available data types in DXL. Let’s now look into a couple of examples to show how to declare and initialize different types of variables. Here is an example DXL program:
// www.TheCloudStrap.Com /************************************************************************ * $FILENAME: d2.1.dxl * $DESCRIPTION: This is a sample DXL program. * * NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved. * Software comes without any warranties and guarantees, is provided * as is and is not supported. Use this software at your own risk. * Authors resume no liabilities. * * Contact: admin {at} TheCloudStrap.com ************************************************************************/ int i = 100 real r = 200.58; bool b = true; char c = 'W' string s = "Welcome to DXL!" print "i = " i "\n" print("r = " r "\n") print("c = " c "\n") print("b = " b "\n") print("s = " s "\n")
In the above program, I have declared and initialized several variables such as i, r, b, c, s of type int, real, bool, char, and string respectively. I have then simply printed them one by one. I have not included “void” type in this example to make the example simple. I will cover the void type when I discuss the function. In DXL, the void data type is mainly used for the function return type to indicate what kind of data the function is going to return.
Let us now run the above program and see the output. I have discussed in the previous article how to run the DXL script in DOORS.
We can do various operations on these basic data types. For example, we can apply addition, subtraction, multiplication, division, increment, decrement, bitwise AND etc operators. Similarly, you can apply the arithmetic operator, assignment operator, and math functions for real types. But, you can not apply the bitwise operator on real data types for obvious reasons. For boolean types, you can apply comparison operators ( i.e. >,<,>=,<=,==,!=), and logical operators (&&, ||, !).
Here is an example program to showcase how to apply those operators on int, real type variables. If you are familiar with other programming languages such as C/C++, you may already know the concept.
In this program, you can see addition, and subtraction for int and real and comparison operations for bool type. First, I have declared an integer type variable i.e. day, and initialized it to 0. Notice that I have intentionally added a semicolon at the end of the statement and in the next line, I have avoided it. This is to show you that the DXL interpreter does not expect you to end a statement with a semicolon. It is optional. From my next article, onward I will consistently follow by adding a semicolon at the end of each statement.
The variable “day” is then incremented by 1 and again added to 2 with the current value. After that, it is decremented(–) by 1.
Similarly, I have declared temp, and temp_offset of real type and performed subtraction operation. Later, the comparison operation is performed in the if condition. The syntax of the if condition is very similar to C/C++. If you have just one statement under the if condition, you can also avoid adding “{}”.
// www.TheCloudStrap.Com /************************************************************************ * $FILENAME: d2.2.dxl * $DESCRIPTION: This is a sample DXL program. * * NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved. * Software comes without any warranties and guarantees, is provided * as is and is not supported. Use this software at your own risk. * Authors resume no liabilities. * * Contact: admin {at} TheCloudStrap.com ************************************************************************/ int day = 0; day++ // day = day + 1 day = day + 2 day-- // day = day - 1 real temp = 5.78; real temp_offset = 0.02; temp = temp - temp_offset; if(day==2){ print "Happy Tuesday!\n" } if(temp>5.0){ print "It's Cold!" }
Now, let’s run the program. Here is the output:
Arithmetic Operations on Integer Type in DXL
Here is the operation you can perform on integer data type:
// www.TheCloudStrap.Com /************************************************************************ * $FILENAME: d2.3.dxl * $DESCRIPTION: This is a sample DXL program. * * NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved. * Software comes without any warranties and guarantees, is provided * as is and is not supported. Use this software at your own risk. * Authors resume no liabilities. * * Contact: admin {at} TheCloudStrap.com ************************************************************************/ int i = 15, j = 2, result = 0; // 1. Addition result = i + j; print("result = " result "\n"); // 2. Subtraction result = i - j; print("result = " result "\n"); // 3. Multiplication result = i * j; print("result = " result "\n"); // 4. Division result = i / j; print("result = " result "\n"); // 5. Modulo Division (remainder after division) result = i % j; print("result = " result "\n"); // 6. Bitwise OR result = i | j; print("result = " result "\n"); // 7. Bitwise AND result = i & j; print("result = " result "\n"); // 8. Bitwise NOT result = ~i; print("result = " result "\n"); // 9. Negation result = -i; print("result = " result "\n");
Assignment Operations on Integer type in DXL
Here is another example DXL script to demonstrate the various assignment operation you can do on integer type.
// www.TheCloudStrap.Com /************************************************************************ * $FILENAME: d2.4.dxl * $DESCRIPTION: This is a sample DXL program. * * NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved. * Software comes without any warranties and guarantees, is provided * as is and is not supported. Use this software at your own risk. * Authors resume no liabilities. * * Contact: admin {at} TheCloudStrap.com ************************************************************************/ int i = 15, j = 2, result = 0; // assignment operation result = i; print("result = " result "\n"); // += result += j; print("result = " result "\n"); // -= result -= j; print("result = " result "\n"); // *= result *= j; print("result = " result "\n"); // /= result /= j; print("result = " result "\n"); // %= result %= j; print("result = " result "\n"); // |= result |= j; print("result = " result "\n"); // &= result &= j; print("result = " result "\n");
Conclusion
This was part-2 of the DOORS DXL tutorial. The intention of this article was just to familiarize you with DOORS DXL and show you different data types that are supported by DXL scripting. Please comment below if you have any questions/suggestions.
This post was published by Admin.
Email: admin@TheCloudStrap.Com