comp.lang.ada
 help / color / mirror / Atom feed
* Mixing logical operators
@ 1993-01-05 18:02 agate!dog.ee.lbl.gov!hellgate.utah.edu!fcom.cc.utah.edu!swillden
  0 siblings, 0 replies; 3+ messages in thread
From: agate!dog.ee.lbl.gov!hellgate.utah.edu!fcom.cc.utah.edu!swillden @ 1993-01-05 18:02 UTC (permalink / raw)


My copy of the Ada standard (ANSI/MIL-STD-1815A) says in 4.5.4:

	...for a sequence of operators of the same precedence level,
	the operators are associated in textual order from left to
	right...

which indicates to me that 

      if i=5 and j=2 or k=3 then
      ...

should be interpreted as 

       if (i=5 and j=2) or k=3 then

but the VAX Ada compiler complains that logical operators cannot be
intermixed.

Is the VAX compiler wrong?  Am I reading the appropriate part of the 
standard?

Shawn.

--
Shawn Willden
swillden@icarus.weber.edu

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Mixing logical operators
@ 1993-01-05 21:08 Alex Blakemore
  0 siblings, 0 replies; 3+ messages in thread
From: Alex Blakemore @ 1993-01-05 21:08 UTC (permalink / raw)


In article <1993Jan5.180216.7426@fcom.cc.utah.edu> swillden@news.ccutah.edu (Sh
awn Willden) writes:
>       if i=5 and j=2 or k=3 then
> the VAX Ada compiler complains that logical operators cannot be intermixed.
> Is the VAX compiler wrong?  

The VAX compiler is correct, as usual.

Parenthesis are required when different logical operators
appear in the same expression.  The LRM expresses this as a
BNF rule (see 4.4(2)), but its also illustrated
in the last two examples in 4.4(6).

Its not such a bad rule.  The extra parenthesis will help others
read your code, but I'm glad they didnt extend the idea to arithmetic
operators (where the precedence conventions are well established).
-- 
---------------------------------------------------
Alex Blakemore alex@cs.umd.edu   NeXT mail accepted

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Mixing logical operators
@ 1993-01-05 23:15 Mark A Biggar
  0 siblings, 0 replies; 3+ messages in thread
From: Mark A Biggar @ 1993-01-05 23:15 UTC (permalink / raw)


In article <1993Jan5.180216.7426@fcom.cc.utah.edu> swillden@news.ccutah.edu (Sh
awn Willden) writes:
>My copy of the Ada standard (ANSI/MIL-STD-1815A) says in 4.5.4:
>	...for a sequence of operators of the same precedence level,
>	the operators are associated in textual order from left to
>	right...
>which indicates to me that 
>      if i=5 and j=2 or k=3 then
>      ...
>should be interpreted as 
>       if (i=5 and j=2) or k=3 then
>but the VAX Ada compiler complains that logical operators cannot be
>intermixed.
>Is the VAX compiler wrong?  Am I reading the appropriate part of the 
>standard?

No, it is implisit in the LRM that even though "and", "or" and "xor" 
are at the same precedence level they DON'T associate with each other.
The grammar given in LRM section 4.4 disallows expressions with mixed logical 
operators. Para 4 section 4.5 only states associativity rules of operators at 
precedence levels below that of the logical operators.  The previous sentence 
to the one you quoted limits the scope of the paragraph to only subexpressions
from relations on down and excludes expressions which is where the logical
operators are found in the grammar.  So you must, in any mixed logical 
expression, explisitly use parens to specifiy evaulation order and the VAX
compler is correct.

--
Mark Biggar
mab@wdl1.wdl.loral.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1993-01-05 23:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1993-01-05 21:08 Mixing logical operators Alex Blakemore
  -- strict thread matches above, loose matches on Subject: below --
1993-01-05 23:15 Mark A Biggar
1993-01-05 18:02 agate!dog.ee.lbl.gov!hellgate.utah.edu!fcom.cc.utah.edu!swillden

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox