the REXX manuals seems clear about operator precedence
* / % // HAVE the same priority
and <contiguous> operators with the same priority are processed left to right
same thing with OBJECT REXX and TSO REXX
Running under win xp home sp3 the problem occurs in v3.5 and 3.6
the following code illustrates the issue ...
The last two example works as expected - i included them for contrast
say
say;say 'Precedence of "*" before "%" and "//" ?'
say
say;say '10 % 2 * 3 =' 10 % 2 * 3
say;say '10 % (2 * 3) =' 10 % (2 * 3)
say
say;say '10 // 2 * 3 =' 10 // 2 * 3
say;say '10 // (2 * 3) =' 10 // (2 * 3)
say
say;say '10 + 2 * 3 =' 10 + 2 * 3
say;say '10 + (2 * 3) =' 10 + (2 * 3)
say
say;say '10 - 2 * 3 =' 10 - 2 * 3
say;say '10 - (2 * 3) =' 10 - (2 * 3)
the REXX manuals seems clear about operator precedence
* / % // HAVE the same priority
and <contiguous> operators with the same priority are processed left to right
same thing with OBJECT REXX and TSO REXX
This may well be a doc issue?
I have copied the following from the v3.6 regina.pdf p.59
I found similar language in the TRL
2.5.1 Arithmetic Operators
Arithmetic operators can be applied to numeric constants and Rexx variables that evaluate to valid Rexx numbers. The following operators are listed in decreasing order of precedence:
-Unary prefix. Same as 0 - number.
+Unary prefix. Same as 0 + number.
**Power
*Multiply
/Divide
%Integer divide. Divide and return the integer part of the division.
//Remainder divide. Divide and return the remainder of the division.
+Add
-Subtract.
v3.5 regina.pdf p.61 says the same thing about "decreasing order of precedence:" under the same heading of 'Arithmetic Operators'
Yes a documentation bug. It has been changed to:
The following operators are grouped in decreasing order of precedence:
- Unary prefix. Same as 0 – number.
+ Unary prefix. Same as 0 + number.
….....................................................................................................................................
** Power.
….....................................................................................................................................
* Multiply.
/ Divide.
% Integer divide. Divide and return the integer part of the division.
// Remainder divide. Divide and return the remainder of the division.
….....................................................................................................................................
+ Add.
- Subtract.
Does this clarify the precedence rules?
Hi Mark,
perhaps while we are at it we can include all the operators in a precedence table
similar to the one i found in the IBM REXX 400 Programmers guide v4 p145
i'll try to upload a screen dump of the page via a file attach
thanks for the quick resolution
screen shot from REXX 400 Prog Guide
It's not clear by the above lists that multiple and division (et al) have the same priority. Looking at the list, it looks (appears) that multiply (*) has greater precedence than division (/) because of the vertical listing and not grouping them together. That whole list should be re-done, re-grouped, re-listed, re-edited.
Also, no mention is made of grouping symbols (er, that means parenthesis) have or that they even exist. Sometimes, even the most obvious needs to be stated. Try finding the definition of how ( ) are treated in REXX expression(s) in the REXX doc. Good luck.
Also, don't forget about || (concatenation) and abutment(s), implied or explicity used (including those abutments that are implied by interspersed blanks and/or whitespace). Again, obvious to an old hand, but not obvious to newbies, or people/programmers who don't have abutments in their "native" programming languages. I.E.: y = 5 6 7
g=funkyTown(67)'piggy-back'
And also: p=(53)'yuppers'
and q='yuppers'(53)
which are quite two different animals.
________________________________________________ Gerard Schildberger
Log in to post a comment.