GoFiler Legato Script Reference
Legato v 1.5b Application v 5.24b
|
Table of Contents | < < Previous | Next >> |
Chapter Three — Data Types and Operators (continued)
Operators are the “bread and butter” of any computer language. They perform mathematical operations, set variables to values, perform logical tests, and manipulate data on a logical basis. When one or more operators are combined in a statement, it is said to be an “expression”. For example:
float x;
x = 17.5;
if (y < x) {
...do something...
}
In the above example, the statement x = 17.5; defines an expression that will set the value of x to 17.5. This is considered an assignment expression because the variable x is assigned the literal value of 17.5. In the next line, y is compared to x, the result of which is a logical FALSE or TRUE (a boolean value) after which execution will either continue into the conditional block or skip the block if the result is FALSE. For more information on flow control, see Chapter Four — Flow Control.
As expressions become more complex, the script processor must make decisions with respect to “which comes first”, or order of precedence. For example:
a = b + c / 2;
Clearly, there is an assignment of a result of a sequence of mathematical operations to the variable a. But is the expression evaluated as b + c and then divide the result by 2 or is it c divided by 2 and then add b? To make this determination, the interpreter must have a set of rules to provide predictable results. This is called operator precedence. Legato will process the latter case, performing the division prior to the addition.
To force an operation to occur in a certain order, the expression can contain grouping. For example:
a = (b + c) / 2;
would provide the expected result. Parentheses force certain operations to be grouped and performed prior to other operations. Parentheses can be nested, and the expression that is most nested is evaluated first. For more information on operators and order of precedence, see Section 3.12 Operator Precedence. In general, Legato follows the basic scope of expressions used by C/C++, JavaScript, PHP, and many other languages.
Boolean values or boolean expressions operate differently than mathematical expressions. Boolean values are either TRUE or FALSE. In Legato, zero is always FALSE and non-zero TRUE. If an expression evaluates to TRUE, its value will always be one. Certain expressions and operations only operate in a boolean manner and give a boolean result.
Operators are grouped into the following categories (note that precedence is actually in a different order and is discussed in the next section):
Mathematical — Performs addition, division, multiplication, subtraction and modulus.
Bitwise Logical — Performs operations including and, or, exclusive or (xor), where the binary values are acted upon. For example, 4 OR’ed with 6 would equal 6 since 0100 binary OR’ed with 0110 binary yields 0110 when performed on a bitwise basis. Bitwise logical operators also include shifting.
Boolean Logical — Performs operations including and, or, exclusive or where the boolean values are taken into account. For example, 4 OR’ed with 6 would equal 1. 0100 binary (TRUE) OR’ed with 0110 binary (TRUE) yields 0001 (TRUE) when performed on a bitwise basis.
Comparison — Compares two values (is equal, not equal, less than, greater than, etc).
Assignment — Sets the variable on the left to the value on the right.
Unary — Adjusts a single value such as increment, decrement, make negative.
When an expression is evaluated, the base data type must also be taken into account. Certain operations cannot be performed on certain data types. For example:
"cat" / "fish"
Division on strings does not make sense. Therefore, strings can only be compared or added, but nothing else. So,
"cat" + "fish"
is “catfish”. Likewise, certain data types, such as handles, can be assigned and tested for equality but other operators cannot be used.
Table of Contents | < < Previous | Next >> |
© 2012-2024 Novaworks, LLC. All rights reserved worldwide. Unauthorized use, duplication or transmission prohibited by law. Portions of the software are protected by US Patents 10,095,672, 10,706,221 and 11,210,456. GoFiler™ and Legato™ are trademarks of Novaworks, LLC. EDGAR® is a federally registered trademark of the U.S. Securities and Exchange Commission. Novaworks is not affiliated with or approved by the U.S. Securities and Exchange Commission. All other trademarks are property of their respective owners. Use of the features specified in this language are subject to terms, conditions and limitations of the Software License Agreement.