RPGLE 中的布尔操作顺序

Boolean order of operation in RPGLE

如果 type = 7 且 seq = 224,为什么下面的代码结果为 true?

RPGLE 自由形式:

if (type = 6 or                 
    type = 7 or                 
    type = 9) and               
    not (seq = 224 or seq=249);

我不得不将其重写为:

if (type = 6 or                 
    type = 7 or                 
    type = 9) and               
    seq <> 224 and 
    seq <> 249;

但是为什么呢?我猜这与 NOT 运算符有关。

嗯,NOT 的优先级高于 ANDOR RPG IV Reference manual operator precedence

  1. ()
  2. 内置函数、用户自定义函数
  3. 一元 +, 一元 -, NOT
  4. **
  5. *, /
  6. 二进制+,二进制-
  7. =、<>、>、>=、<、<=

但是,您显示的表达式的计算结果应该为 false...

**free

 dcl-s flag ind;
 dcl-s seq int(5) inz(224);
 dcl-s type int(5) inz(7);

   flag = (type = 6 or
           type = 7 or
           type = 9) and
            not (seq = 224 or seq=249);

   dsply ('Flag=' + flag);
   *INLR = *ON;
   return; 

工作日志显示:

DSPLY Flag=0