Home page logo

wireshark logo 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'
'host and port 443 or port 333' same '(host 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:


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




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



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




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


Pascal appears to give AND a higher precedence than OR:


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

  By Date           By Thread  

Current thread:
[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]