RE: Precedence rules for QuantifiedExpr - OrExpr - AndExpr

Michael,

Thanks for your reply. 

Perhaps you can educate me on where I went wrong, because it indicates a
fundamental misunderstanding of how to read BNF's from my side, and I would
certainly like to avoid that in the future.

I always thought that the EBNF (A.1) and the precedence rules (A.4) contain
"duplicate" information. In other words the non-terminals of the EBNF or
chosen so that they "reduce" in a way that the operator priorities are
implemented as expected. A.4 also says that in case of doubt (the same
level), the rules are applied left to right (left associative I believe it
is called in "grammar" lingo). 

In other words, and in this case it does not matter, but it illustrates what
I want to say

1 + 2 - 3 means ( 1 + 2 ) - 3

The same reasoning led me to believe that

"some .... or ...." has to be interpreted as "(some ....) or (....)" and not
as "some ... or ...."

Can you indicate where my failure is.

As a side remark, I am not sure I get the relevance of your explanation on
the relative priorities of "and" and "or", but perhaps that is "the/my
problem".

Thanks for your help,

Peter
 

-----Original Message-----
From: Michael Brundage [mailto:xquery@comcast.net] 
Sent: Saturday, December 20, 2003 7:37 PM
To: pgp.coppens@pandora.be; www-ql@w3.org 2
Subject: Re: Precedence rules for QuantifiedExpr - OrExpr - AndExpr


Hi Peter,

I think you're misreading the spec.  Both expressions parse as

for $x in (1,2,3)
where some $y in (1,2) satisfies ((1 = $y) OP ($y =1)) return $x

where OP is "or" or "and".

The "and" operator has a precedence level immediately greater than "or" --
there is no intervening expression.   Quoting from section A.1 of the
current (Nov 12, 2003) draft:

[55]   OrExpr  ::=   AndExpr ( "or" AndExpr )
[56]   AndExpr ::=   InstanceofExpr ( "and" InstanceofExpr)*

So for example,

A or B and C
parses as
A or (B and C)


Hope this helps,

Michael Brundage
xquery@comcast.net

Writing as
Author, XQuery: The XML Query Language (Addison-Wesley, 2004) Co-author,
Professional XML Databases (Wrox Press, 2000)

not as
Technical Lead
Common Query Runtime/XML Query Processing WebData XML Team Microsoft



On 12/19/03 7:36 AM, "Peter Coppens" <pgp.coppens@pandora.be> wrote:
> All,
> 
> Looking at the XQuery spec, I am somewhat surprised by the 
> consequences of the precedence rules for QuantifiedExpr - OrExpr and 
> AndExpr
> 
> What I mean is:
> 
> Take the query
> 
> for $x in (1,2,3)
> where
> some $y in (1,2) satisfies 1 = $y and $y = 1 return $x
> 
> Which, I think, is equivalent to
> 
> for $x in (1,2,3)
> where
> some $y in (1,2) satisfies (1 = $y and $y = 1) return $x
> 
> But now take the query
> 
> for $x in (1,2,3)
> where
> some $y in (1,2) satisfies 1 = $y or $y = 1 return $x
> 
> 
> Which, I think, is equivalent to
> 
> for $x in (1,2,3)
> where 
> (some $y in (1,2) satisfies 1 = $y) or $y = 1
> return $x
> 
> I find that rather confusing.
> 
> So I guess I have the following questions
> 
> (1) is the above interpretation correct?
> (2) is this a deliberate choice and if yes, are there any motivations for
> that decision that can be shared?
> (3) would it not be possible to add an extra level of precendence where
the
> OrExpr comes to sit between QuantifiedExpr and AndExpr, or would that
> propagate to have other side effects?
> 
> Thanks,
> 
> Peter
> 

Received on Saturday, 20 December 2003 14:33:20 UTC