libAtoms / abcd

2 stars 4 forks source link

Precedence of relation operators #63

Closed fekad closed 4 years ago

fekad commented 5 years ago

During the implementation of the new parser turned out there is a small issue with the ordering. In a case of complex queries string there are multiple ways to group the terms: from left to right:

A | B & C ≡ (A | B) & C

OR operators has precedence level (... >> AND >> OR >> ...)

A | B & C ≡ A | (B & C)
fekad commented 5 years ago

More preciesly:

right-to-left, with precedence:

A | B & C | D = A | ((B & C) | D)

left-to-right, with precedence:

A | B & C | D = (A | (B & C)) | D

right-to-left, without precedence:

A | B & C | D = A | (B & (C | D))

left-to-right, without precedence:

A | B & C | D = ((A | B) & C ) | D
gabor1 commented 5 years ago

I don’t really mind. can you parse parentheses ? one could always do that to be sure. If it’s all the same to you, I prefer precedence, and don’t care if it’s left to right or right to left, I wouldn’t assume either, I would just parenthesise

On 12 Aug 2019, at 17:55, Adam Fekete notifications@github.com wrote:

More preciesly:

right-to-left, with precedence:

A | B & C | D = A | ((B & C) | D)

left-to-right, with precedence:

A | B & C | D = (A | (B & C)) | D

right-to-left, without precedence:

A | B & C | D = A | (B & (C | D))

left-to-right, without precedence:

A | B & C | D = ((A | B) & C ) | D

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub, or mute the thread.

-- Gábor

Gábor Csányi Professor of Molecular Modelling Engineering Laboratory Pembroke College University of Cambridge

Pembroke College supports CARA. A Lifeline to Academics at Risk. http://www.cara.ngo/

fekad commented 5 years ago

yes, you will be able to use parentheses. Meanwhile, I found other special cases:

gabor1 commented 5 years ago

On 15 Aug 2019, at 15:03, Adam Fekete notifications@github.com wrote:

yes, you will be able to use parentheses. Meanwhile, I found other special cases:

• operator names conflict with variable names and or not ?= and & or & not There are two options: • operator names must be excluded from the valid variable names • force to use and or or

we already agreed that keys should use a restricted set of characters, so the same code that checks for that should exclude a set of reserved words.

• To decide how the '-q' should behave and how should combine the queries: • exp1 and exp2 and exp3 • (exp1) and (exp2) and (exp3) where exp2 is: aa or bb and cc If any precedence has defined these statement above provides a different result.

I’m pretty relaxed about this. people who write

aa and bb or cc and dd

either know the code very well or are extremely careless. I don’t particular want to cater for either. if it’s all the same to you, let’s have “and” precedent over “or”. if another design is simpler (e.g. left to right, no precedence), I’m fine with that also.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub, or mute the thread.

-- Gábor

Gábor Csányi Professor of Molecular Modelling Engineering Laboratory Pembroke College University of Cambridge

Pembroke College supports CARA. A Lifeline to Academics at Risk. http://www.cara.ngo/