Variables, Constants and Types

Previous  Top  Next


 
In the SimuPLC 4.1.0, the verification of types is very weak, till more than in the C language, for example, that is, the Simulator doesn't do consistency of type of variable for purposes of errors compilation detection (the only consistency made is if is obligatory that determined identifier or parameter is variable or can be constant). The implicit variety of types of the variable remembers the Variant type of the Pascal language, that, typefying some variable, does this one can contain values of almost all the other types allowed by language, which are utilized of way context sensitive. For example, if the following assignment instruction is executed in the SimuPLC:  
 
            V0 R:= 100000.125;  
 
and, after, these ones are executed:  
 
            V1 R:= V0;      V1 will receive 100000.125  
            V1 := V0;      V1 will receive 100000 (the default is D)
            V1
D:= V0;      V1 will receive 100000
            
V1 W:= V0;      V1 will receive 34464
             
V1 B:= V0;      V1 will receive 160

that is, a same variable keeps values of the types R - real float - 32 bits, D - integer doubleword - 32 bits, W - integer word - 16 bits e B - integer byte - 8 bits. And also bit - on/off or false/true - 1 bit, because, after of all, we still can have, referencing this variable, some bit logic instruction:

         
operate V0; or
         
turn_on
V0; or
         
turn_off
V0;
         
if
(V0) { ... }

and now
V0 is representing the respective bit variable (on/off - false/true).

Obs.
: in the formation of expressions, the following arithmetical and logical operators (+, -, *, /, & (and), | (or) e ^ (or exclusive)) can be used. Before of the operators that build the expression also can be placed type qualifiers of the operation: B, W, D e R, that define the size and type of values of the operators and of result of the operation. D is the standard, assumed by default if it isn't placed any. The type R cannot be utilized with logical operators. For example:

V0 R:= AIW0 R+ (AIW1 R/ 8); // Always keep space between operator and operand and never between type of the operation and operator


Numerical Constants in the SimuPLC 4.1.0:

·The numerical constant values can be represented in the traditional decimal system, as shown in the given examples above.  

·Or can, still, be represented in the binary (2-base) or hexadecimal format (16-base), as long as preceded of 2# (for example, 2#1000 = 8), or 16# (for example, 16#1C = 28), respectively. Note that negative numbers aren't allowed when such formats are utilized.  

Obs.
: the variables and instructions in the SimuPLC are case sensitive, that is, it's considered different the lower and upper case of the same letter. Generally, the
instructions into IL
are written in upper, and, into LCE, in lower case.