Wireshark mailing list archives

Re: Display filter and/or precedence


From: Guy Harris <guy () alum mit edu>
Date: Fri, 9 Aug 2013 13:08:15 -0700


On Aug 9, 2013, at 12:32 PM, Jakub Zawadzki <darkjames-ws () darkjames pl> wrote:

On Fri, Aug 09, 2013 at 11:41:59AM -0700, Gerald Combs wrote:
Laura Chappell and Sean Walberg recently discovered that logical OR
takes precedence over logical AND in display filters. Is there any
reason we shouldn't reverse this so that we match the order of
operations elsewhere (including BPF)?

I think in BPF they have the same priority, evaluated from left to right, check dump of:

'port 333 or port 444 and host 192.168.192' same '(port 333 or port 444) and host 192.168.192.1'
'host 192.168.192.1 and port 443 or port 333' same '(host 192.168.192.1 and port 443) or port 333'

Yup.  To quote the pcap-filter man page:

        Alternation and concatenation have equal precedence and associate left to right.

C (and, unless somebody was insane, C++ and Objective-C and Objective-C++) give logical AND a higher precedence than 
logical OR.

And, for those curious about FORTRAN:

        http://www.fortran.com/F77_std/rjcnf0001-sh-6.html#sh-6.4.2

.AND. has a higher precedence than .OR..

Continuing:

Perl:

        http://perldoc.perl.org/perlop.html#Operator-Precedence-and-Associativity

"and" has a higher precedence than "or".

Python:

        http://docs.python.org/2/reference/expressions.html#operator-precedence

same (the list goes from *lowest* precedence to *highest* precedence).

JavaScript:

        https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#Table

same.

In Ada 95, they seem to have the same precedence:

        http://www.infres.enst.fr/~pautet/Ada95/chap04.htm

Pascal appears to give AND a higher precedence than OR:

        http://www.tutorialspoint.com/pascal/pascal_operators_precedence.htm

I have the sneaking suspicion that we may have one of the few, if not the only, expression languages where logical OR 
takes precedence over logical AND, in which case that's probably the wrong thing to do, by the Principle Of Least 
Surprise if nothing else.  The only reason to keep our current behavior would be backwards compatibility.

If we decided to change the precedence, the remaining question is whether to be like C (and languages that have 
followed C) or like libpcap?
___________________________________________________________________________
Sent via:    Wireshark-dev mailing list <wireshark-dev () wireshark org>
Archives:    http://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev
             mailto:wireshark-dev-request () wireshark org?subject=unsubscribe


Current thread: