ModMultiSim help v3.07 - 5.1. Lexical Structure

Download manual: HTML

5.1. Lexical Structure

ModMultiSim 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
            $ integer_constant $ integer_constant
            $ letter_sequence
          

    letter_sequence : letter letter*
    letter : a-zA-Z
      

    A $ integer_constant (a $ followed by a sequence of digits as in $15) is the form of identifier 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. This form of identifier may only be used in the statement of a register.

    A $ integer_constant $ integer_constant (a $ followed by a sequence of digits followed by $ and another sequence of digits as in $3$15) is the form of identifier used to refer to a register in a specific slave. The digits after the first $ represent the slave, and those after the second $ represent the address of the register, as above. This form of identifier is used in the statement of an environment property. For example, if a slave with an id of 3 controls a heater in the environment by setting a counter in register 15, then the statement for an environment property for temperature may access the slave register value using:

            $3$15

    in order to compute its own value (temperature). (Though a slave may refer to another slave's registers, this would not be possible in the real world, so there would be no reason to do so here.)

    A $ letter_sequence ( a $ followed by a sequence of letters as in $volume or $temp) is the form of identifier used to refer to an environment property. This form may be used in the statement of a register or an environment property. When used in the statement of an environment property it may refer to itself or to another environment property. For example, the statement to calculate pressure changes may refer to itself "presschange" and properties representing the temperature "temp", last recorded pressure "press" and volume "vol" in its statement:

            $presschange - $press - ($temp / $vol)

    In all the above cases, a warning message appears when an expression contains a reference to a register or environment property that has not yet been entered (declared). It is possible to continue and enter the register or property later.

  2. Keywords

    keyword : if | then | else | CycleTime | TimeNow
          

    Keywords are all case-sensitive. TimeNow and CycleTime are ModMultiSim 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.