diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2015-07-22 01:40:53 +0200 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2015-07-22 01:40:53 +0200 |
commit | efa862d4f89401c5148746a5aba4d88ed6b6cbaa (patch) | |
tree | 22afe953b54b4b0fc6f80f0aef80c4ae45b8f3be /doc/sciteco.7.template | |
parent | 91f29f5b146453e67e15f8e91571b0f806526d1f (diff) | |
download | sciteco-efa862d4f89401c5148746a5aba4d88ed6b6cbaa.tar.gz |
fixed operator precedence list
* necessary since in SciTECO every operator has a different
precedence. E.g. successive additions/subtractions cannot
be evaluated from left to right (by their associativity).
Perhaps this should be changed.
* subtraction must have a higher precedence than addition,
since (a+b)-c == a+(b-c)
* division must have a higher precedence than multiplication
since (a*b)/c == a*(b/c).
This is not quite true for integer arithmetics.
* this fixes expressions like 5-1+1 which were counterintuitively
evaluated like 5-(1+1)
Diffstat (limited to 'doc/sciteco.7.template')
-rw-r--r-- | doc/sciteco.7.template | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/doc/sciteco.7.template b/doc/sciteco.7.template index c64fb4a..9c6180c 100644 --- a/doc/sciteco.7.template +++ b/doc/sciteco.7.template @@ -731,24 +731,24 @@ precedence: .IB base " ^* " power Raise \fIbase\fP to \fIpower\fP. .TP -.IB a " * " b -Multiply \fIa\fP by \fIb\fP. -.TP -.IB a " / " b -Divide \fIa\fP by \fIb\fP. -Naturally it is a division without remainder. -.TP .IB a " ^/ " b Remainder of \fIa\fP divided by \fIb\fP. It is actually a modulo operation conforming to the host C compiler's modulo semantics. .TP -.IB a " + " b -Add \fIb\fP to \fIa\fP. +.IB a " / " b +Divide \fIa\fP by \fIb\fP. +Naturally it is a division without remainder. +.TP +.IB a " * " b +Multiply \fIa\fP by \fIb\fP. .TP .IB a " - " b Subtract \fIb\fP from \fIa\fP. .TP +.IB a " + " b +Add \fIb\fP to \fIa\fP. +.TP .IB a " & " b Binary AND. .TP @@ -774,6 +774,20 @@ mandatory in classic TECO, like in \(lq.ZD\(rq. I recommend to use it as much as possible in code where clarity matters. .LP +Note that \*(ST assigns an unique precedence to each operator +instead of having several operators (like addition and subtraction) +share the same precedence and evaluate them according to their +associativity. +Still the precedence rules should ensure that expressions are +evaluated similarily to other programming languages. +When the same operator is used repeatedly, expressions are always +evaluated with left-to-right associativity. +For instance, \(lq2^*3^*4\(rq is evaluated like \(lq(2^*3)^*4\(rq. +The arithmetic evaluation order established by the operator precedence +or braces must not be confused with the execution order of \*(ST commands +which is always strictly from left to right (unless flow control +commands are used). +.LP The only unary operator currently supported is .RB \(lq - \(rq. The minus-operator is special and has unique semantics. @@ -781,7 +795,7 @@ It sets the so called \fBprefix sign\fP which is 1 by default to -1. This prefix sign may be evaluated by commands \(em most often it is the default value if the argument stack is empty so that expressions like -\(lq-C\(rq are rougly equivalent to \(lq-1C\(rq. +\(lq-C\(rq are roughly equivalent to \(lq-1C\(rq. However in front of opening brackets, like in \(lq-(1+2)\(rq, it is roughly equivalent to \(lq-1*(1+2)\(rq so that values calculated in brackets can be easily negated. |