Re: (non) associativity slash operator

Jan Hidders wrote:
> 
> 2. Is the slash operator left- or right-associative?
> 
> In XPath 1.0 the slash operator was left-associative because of the way that
> the syntax was defined. In the current XPath 2.0 syntax I think this is not
> clear anymore, at least not from the syntax definition. If I look at the
> normalization rules for the slash operator then there is only a rule for the
> binary case (<stepExpr> / <stepExpr>) which means that if I have an
> expression of the form
> 
>   <stepExpr> / <stepExp> / <stepExpr>
> 
> I can choose which slash I am going to normalize first, which makes the
> semantics more ambiguous than is probably wanted.

The normalization rules are assumed to operate on (and produce)
syntactic structures that conform to the grammar(s) defined elsewhere.
In this case, the corresponding production is

 [69 (XQuery)] RelativePathExpr ::= StepExpr (("/" |  "//") StepExpr)*

but that doesn't actually define the associativity of the slash
operator. To do so, I believe you need to invoke Appendix A.4 of
"XML Path Language (XPath) 2.0",  which says (in rather confused
terms):

      In the cases where a number of statements are a choice
      at the same production level, the expressions are always
      evaluated from left to right.

So for example, if a RelativePathExpr is A/B/C, this tells us to
evaluate A/B, then (the result of that)/C. (Actually, strictly
speaking, all it says is to evaluate A, then B, then C, and doesn't
say anything about how to group the results as operands of the
slashes. But I'm pretty sure I've given the *intended* meaning.)
So the slash operator (along with most binary operators) is
left-associative.

-Michael Dyck

Received on Friday, 18 July 2003 17:20:54 UTC