![]() |
![]() |
![]() |
![]() |
(..Acc. Single Reg.) | Contents | Index | (..Expressions..) |
|
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
Besides that, we have the possibility to come to more complex expressions using binary operators with operands from IntOp (*, /, %, +, -, <<, >>, &, |):
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:
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:
(15+2)-(3*2)*(6/2*(27-25))5 ( ...
(15+2)-6*(6/2*(27-25))
(15+2)-6*(3*(27-25))
(15+2)-6*(3*2)
...
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.
-10 * +23-230 (1 + abs(int_var) / 13) << 2
4 stoi("1001 nightmerries") + (8+4+2) & (4+2+1)
1007
![]() |
![]() |
![]() |
![]() |
(..Acc. Single Reg.) | Contents | Index | (..Expressions..) |