previous contents index next
(..Acc. Single Reg.) Contents Index (..Expressions..)

2.10 Expressions

 

2.10.1 Integer Expressions (IntExpression)

IntExpression - Syntax:

Syntax: IntExpression

In principle, every object of type INT or better every arithmetical expression in parentheses is called an integer expression. Now you will surely have a rather good idea of what could be meant, and, of course, this is totally legitimate! But we should not forget that we try to communicate with a compiler, which does really not need to understand all the subtile human thoughts and intentions... That is why we - in spite of our intuition - are going to precise the definition:

First we already know some elementary integer expressions, which are described above in the same chapter, and which all the other integer expressions are assembled out of. These modules are

Take specially care about restrictions and differences between IntReg objects in RDL and SDL.
 

Besides that, we have the possibility to come to more complex expressions using binary operators with operands from IntOp (*, /, %, +, -, <<, >>, &, |):

IntExpression1 IntOp IntExpression2

Like this, it is no problem to design expressions with more than one operator. In this case, the order of their evaluation is given by a fixed hierarchy (hierarchy table). Operators with higher priority are evaluated first. (E.g., *, / and % have an higher evaluation priority than + and - according to the well-known arithmetical rule.) Whenever there are two operators which have the same priority within the same expression, the left one is evaluated first. (The only exception to the rule are the signs, which have not been mentioned yet.)


 

Furthermore an expression put in parentheses is again an expression:

( IntExpression )

As usual the parentheses give the evaluation of the surrounded expression priority treatment; - of course, only in relation to the normal order, or in other words, the expression which is surrounded by the greatest number of parentheses is not automatically evaluated first. The example beneath should make it a bit clearer:


Example 27:

(15+2)-(3*2)*(6/2*(27-25))  leadsto  5

( ...     leadsto  (15+2)-6*(6/2*(27-25))     
          leadsto  (15+2)-6*(3*(27-25))     
          leadsto  (15+2)-6*(3*2) 
          leadsto     ...
          leadsto  17-12 )

In particular the existing hierarchy may be canceled, that means, operators with a lower priority can be evaluated before others with an higher priority.


In principle it is not forbidden by SCARLET'S grammar to transform every expression by placing a sign + or - directly in front of it into a new one with the same or negative value respectively; but we will not allow such expressions where more than one + or - are following each other. It could be avoided using parentheses.


Example 28:

Finally there are some examples of integer expressions.
Let us suppose that int_var is an integer variable with contents -15.

-10 * +23  leadsto  -230

(1 + abs(int_var) / 13) << 2  leadsto  4

stoi("1001 nightmerries") + (8+4+2) & (4+2+1)  leadsto  1007  

previous contents index next
(..Acc. Single Reg.) Contents Index (..Expressions..)