关于FP(free pascal)的较简单问题。

来源:百度知道 编辑:UC知道 时间:2024/07/12 10:54:06
FP(free pascal)中的布尔表达式(Boolean):a and not (m>n) and (x<y-m) or (a or b)的值为什么为TRUE?说明:
a=true
b=false
x=7
y=12
m=3
n=35
PASCAL程序是这样的:
var a,b:boolean;x,y,m,n:integer;
begin
a:=true;b:=false;x:=7;y:=12;m:=3;n:=35;
writeln(a and not(m>n) and (x<y-m) or (a or b))
end.
请给我详细点的解题思路!谢谢!
感谢各位高手
我是初学者
多多指教

优先级是这样的:先括号,然后not最高,之后是and、*、/,然后是+、-、or和xor,最后是那些大于号小于号之类的比较符号
所以
a and not (m>n) and (x<y-m) or (a or b)
=a and (not false) and (x<9) or true
=a and true and true or true
=true and true or true
=true or true
=true
明白没?

看下面这个表BOOLEAN达式:
a and not(m>n) and (x<y-m) or (a or b)
……………①……………………OR……②……

AND比OR优先,那么实际上表达式是两个表达式①和②的OR运算,OR的运算规则,只要①为TRUE或者②为TRUE结果就要为TRUE,那么上面的表达式计算就可以下面这样简化(计算机不是这样的步骤):

因为a为TRUE,所有a or b也就是②就为TRUE了,所以整个表达式就为TRUE,前面的①那一大堆根本就不用计算的。

当然是TRUE了