Search code examples
xquerylogical-operatorsrelevance

Logical operators relevance in XQuery


what operation is more relevant in XQuery: AND or OR?

For example: (a and b or c) is equal to 1 o 2?

  1. (a and b) or c
  2. a and (b or c)

Cheers, Deborah


Solution

  • I guess that by "is more relevant" you mean what other people would phrase as "binds more tightly" or "has higher precedence". In XQuery, a and b or c is parsed as (a and b) or c, not as a and (b or c).

    This may be seen in productions 46 and 47 of the XQuery grammar:

    [46] OrExpr ::= AndExpr ( "or" AndExpr )*

    [47] AndExpr ::= ComparisonExpr ( "and" ComparisonExpr )*

    It may also be exhibited in an XQuery engine by evaluating the expression false() and true() or true(). That this is a result of operator precedence and not of left-to-right evaluation can be seen by re-ordering the expression and evaluating true() or true() and false().