Appendix C

Grammars

C.1 Introduction

In this appendix, we provide the grammar of SQL/XML and of XQuery. Both are presented in a variation of Backus-Naur Form (BNF) and both of these variations are called “extended BNF” (which XQuery calls EBNF). In each section, we summarize the meanings of the notations used in the grammar. We do not present the grammar for XPath 2.0, largely because it is a subset of the XQuery grammar.

C.2 XQuery Grammar

The XQuery grammar1 (which is used by all W3C specifications) involves a variation of EBNF that uses a notation derived from regular expressions. For example, in the XQuery grammar, the BNF nonterminal symbol digits is defined to be any sequence of one or more instances of the characters 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9:

image

In this production, the notation [0–9] means “every character in the range starting with 0 and ending with 9,” and the plus sign + means “one or more.”

As in almost all uses of BNF, the notation A : : = B C is a production that is equivalent to the statement “the nonterminal symbol A is defined to be the nonterminal symbol B followed by the nonterminal symbol C.” Nonterminal symbols are those that are defined by an EBNF production, while terminal symbols are those that are not defined in EBNF productions (except for a few that are defined in special productions used to specify the internal syntax of some terminal symbols).

The rules associated with matching strings of one or more characters in a terminal symbol are provided in Table C–1.

Table C1

Rules for Matching Terminal Symbols

Notation Meaning
#xN (“N” is a hexadecimal integer) Matches the character in ISO 10646 whose canonical (UCS-4) code value has the specified value
[a-zA-Z] Matches any Char with a value in the range(s) indicated (inclusive)
[abc] Matches any Char with a value among the characters enumerated
[imagea-z] Matches any Char with a value outside the range indicated
[imageabc] Matches any Char with a value not among the characters given
“string” or Matches the sequence of characters that
’string’ appear inside the double quotes or single quotes, respectively

Table C-2 gives the rules for interpreting the notations used to define nonterminal symbols in this variation of EBNF.

Table C2

Rules for Matching Nonterminal Symbols

Notation Meaning
(A) A is treated as a unit and may be combined as described in this list.
A? Matches A or nothing; equivalent to saying that A is optional.
A B Matches A followed by B. In this variation of EBNF, this operator has higher precedence than alternation; thus A B | C D is identical to (A B) | (C D).
A | B Matches either A or B but not both.
A – B Matches any string that matches A but does not match B.
A+ Matches one or more occurrences of A. Con- catenation has higher precedence than alter- nation; thus A+ | B+ is identical to (A+) | (B+).
A* Matches zero or more occurrences of A. Concatenation has higher precedence than alternation; thus A* | B* is identical to (A*) | (B*).
“(”, “comment” Matches a literal open parenthesis or a literal example of the word “comment,” respectively.

Note that, in this variation of EBNF, nonterminal symbols are not delineated by any special characters, while terminal symbols are always enclosed in double quotes.

XQuery’s EBNF notation that defines all nonterminal symbols other than single-character nonterminals and keywords appears in Grammar C–1.

Grammar C—1   XQuery Terminal Symbol EBNF

image

image

XQuery’s EBNF notation for all of the nonterminal symbol productions of the XQuery language appears in Grammar C–2.

Grammar C—2   XQuery Nonterminal Symbol EBNF

image

image

image

image

image

C.3 SQL/XML Grammar

The version of EBNF used to specify SQL/XML2 is significantly different from that used by XQuery. For one thing, it does not use any regular expression notation. For another, nonterminal symbols are delineated by leading left angle brackets and trailing right angle brackets <…>, while terminal symbols in general stand for themselves – the exceptions are those characters specified in Table C-3. The SQL/XML EBNF includes a few productions for nonterminal symbols that stand for terminal symbols that are the same characters as the characters in this table. (Many of this sort of production appear in SQL/Foundation3 instead of in SQL/XML; we repeat them in this appendix only if required for comprehension.)

Table C3

Symbols Used in SQL/XML EBNF

Symbol Meaning
< > A character string enclosed in angle brackets is the name of a BNF nonterminal symbol.
: : = The nonterminal symbol appears to the left of the operator, and the formula that defines the element appears to the right.
[ ] Square brackets indicate optional elements in a formula. The material within the brackets may be omitted or it may be specified explicitly.
{ } Braces group elements in a formula.
| The vertical bar indicates that the material to the left of the bar and the material to the right of the bar are alternatives; either one, but not both, can be used.
The ellipsis indicates that the element to which it applies in a formula may be repeated any number of times.
! ! Introduces normal English text, used when the definition of a syntactic element is not expressed in BNF.

Grammar C–3 contains the essential parts of the SQL/XML grammar. Some productions have been omitted because they are not necessary for comprehension. A number of the productions define nonterminal symbols that are originally defined in SQL/Foundation but are augmented in SQL/XML. Such productions begin with an alternative that indicates that there are alternatives that are defined in SQL/Foundation:

!! All alternatives from ISO/IEC 9075-2

A few other productions in SQL/XML completely replace a production for the same nonterminal symbol that appears in SQL/Foundation; the replacement is done to add new syntax on the right-hand side of the production in some form other than a new alternative. Such productions are not specially noted in Grammar C-3 because their replacement is all that is needed for understanding SQL/XML. In this grammar, we have omitted the grammar associated with embedding SQL statements, including those that use SQL/XML, into various host programming languages.

Grammar C—3   SQLIXML EBNF

image

image

image

image

image

image

image

image

image

C.4 Chapter Summary

In this appendix, we have presented the grammar for XQuery and the grammar for SQL/XML. These two languages are defined using different versions of EBNF, but it’s reasonably easy to mentally map between the two notations.


1The grammar presented here is taken from the XQuery Last Call Working Draft published on 4 April 2005 at http://www.w3.org/TR/2005/WD-xquery-20050404/.

2The SQL/XML grammar presented here is taken from SQL/XML:2005.

3ISO/IEC 9075-2:2003, Information technology – Database languages – SQL – Part 2: Foundation (SQL/Foundation), International Organization for Standardization (Geneva, Switzerland: 2003).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.27.251