ModSlaveSim help v3.06 - 5.1. Lexical Structure

Download manual: HTML

5.1. Lexical Structure

ModSlaveSim contains 4 classes of tokens: identifiers, constants, operators and keywords.

token:
        identifier
        keyword
        constant
        operator
      

Whitespace (space, newlines, tabs) is ignored except in its role as a separator of tokens.

  1. Identifiers

     identifier :
          $$
          $ integer_constant
          

    An identifier is a $ followed by a sequence of digits.

    In ModSlaveSim an identifier is used to refer to a register. An expression may contain a reference to any register, including itself. An alternative way to refer to itself is by using the form $$.

    To identify a specific register, the register address is used as the sequence of digits after the $. The minimum value for an address is 0 and the maximum value 'model address' is 2147483647 (see Map Addresses). Identifiers can therefore occur in the range $0 to $2147483647.

    A warning message appears when an expression contains a reference to a register that has not yet been entered (declared). It is possible to continue and enter the register later.

  2. Keywords

    keyword : if | then | else | CycleTime | TimeNow
          

    Keywords are all case-sensitive. TimeNow and CycleTime are ModSlaveSim variables (see section Pre-defined Variables).

  3. Constants

    constant :
            integer_constant
            floating_constant
          

    integer_constant : integer
    integer : digit digit*
    digit : 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
          

    An integer_constant is a digit followed by zero or more digits.


          

    floating_constant : 
            integer period
            integer period? exponent
            integer? period integer exponent?
    period : .
    exponent :
             E sign? integer
             e sign? integer
    sign :
             +
             -
          

    A floating_constant must have either a period [.] or an exponent e.g. [e-3], but may have both. It must also have an integer component either for the whole number part, or the fraction part, or both. The following are all valid examples::

            67.    67.0     67.89     0.89    .89 
            6e-3   67.e+4   67.89e-2  0.89e1  .89e-4

    For all constants, a sequence of digits is taken to be in decimal radix.

  4. Operators

    operator : 
            ()     
            ~     
            unary_sign     
            * | / | %
            binary_sign 
            << | >>    
            &    
            bitwise_or 
            < | > | <= | >= | == | !=
            !    
            &&
            ||
          

    An operator specifies an operation to be performed that returns a value. The object that the operator acts upon is the operand.

    The ( ) operator shall always occur in a pair.