Appendix D

A Tutorial D Grammar

This appendix gives a simple BNF grammar for Tutorial D relational expressions and assignments.

Keywords: Tutorial D; The Third Manifesto

I never use a big, big D

—W. S. Gilbert:

HMS Pinafore (1878)

This appendix gives for purposes of reference a simple BNF grammar for Tutorial D relational expressions and assignments (only). The grammar is derived from the comprehensive version given in reference [50] but additionally takes account of image relations, which aren’t mentioned in that reference.1 Note: For space reasons, certain of the syntactic categories mentioned in this grammar have names that are slightly abbreviated compared to their counterparts in the body of the book (e.g., <relation selector> instead of <relation selector invocation>). Also, the following are deliberately omitted:

■ Aspects of the language not used in this book

■ Definitional operations, such as those used to define base relvars, views, and constraints

■ Nonrelational expressions, including aggregate operator invocations in particular

■ Everything proposed in this book for dealing with intervals and related matters

Also, the grammar is simplified in certain respects. In particular, it makes no attempt to say where image relations can and can’t be used, nor does it pay any attention to operator precedence. (As a result of this latter point, certain constructs permitted by the grammar—for example, the expression r1 MINUS r2 MINUS r3—are potentially ambiguous. Additional rules are needed to resolve such issues, but such rules are omitted here. Of course, parentheses and/or WITH specifications can always be used to guarantee a desired order of evaluation anyway.)

A few further points of detail:

■ All syntactic categories of the form <… name> are assumed to be <identifier>s and are defined no further in this appendix.

■ Although the category <bool exp> is left undefined, it might help to recall that a relational comparison in particular is a special case.

■ As always, all of the various commalists mentioned are allowed to be empty.

Note: Please don’t be confused by the fact that, in accordance with normal convention, we use brackets “[” and “]” in this grammar to enclose optional material. (In the body of the book, of course, brackets were used in interval selector invocations and were thus part of the language as such, not part of the metalanguage.) By contrast, we depart from normal convention in that braces “{” and “}” in the grammar stand for themselves—i.e., they’re symbols in the language being defined, not, as they usually are, symbols of the metalanguage. To be specific, braces are used in the grammar below to enclose commalists of items when the commalist in question is intended to denote a set of some kind—implying in particular that (a) the order in which the items appear within that commalist is immaterial, and further that (b) if an item appears within that commalist more than once, it’s treated as if it appeared just once.

Expressions

<relation exp>
  ::= <with exp> | <nonwith exp> | ( <relation exp> )
<with exp>
  ::= WITH ( <temp assign commalist> ) : <relation exp>

Note: A <temp assign> is syntactically identical to a <relation assign>, except that an introduced “temporary” name can appear wherever a <relvar name> can appear.2

<nonwith exp>
  ::= <image relation ref> | <relation op> | <relation op> )
<image relation ref>
  ::= !! <relvar name> | !! ( <relation exp> ) | ( <image relation ref> )
<relation op>
  ::= <relation selector> | <monadic op> | <dyadic op> | <n-adic op>
<relation selector>
  ::= RELATION [ <heading> ] { <tuple exp commalist> } | TABLE DUM | TABLE DEE

Note: In the first <relation selector> format, the optional <heading> must be specified if the <tuple exp commalist> is empty. TABLE_DUM and TABLE_DEE are shorthand for the <relation selector>s RELATION { } { } and RELATION { } { TUPLE { }}, respectively.

<heading>
  ::= { <attribute commalist> }
<attribute>
  ::= <attribute name> <type name>
<monadic op>
  ::= <relvar name> | <rename> | <where> | <project> | <extend> | <wrap> | <unwrap> | <group> | <ungroup>
<rename>
  ::= <relation exp> RENAME { <renaming commalist> }
<renaming>
  ::= <attribute name> AS <attribute name>
<where>
  ::= <relation exp> [ WHERE <bool exp> ]
<project>
  ::= <relation exp> { [ ALL BUT ] <attribute name commalist> }
<extend>
  ::= EXTEND <relation exp> : { <attribute assign commalist> }
<wrap>
  ::= <relation exp> WRAP { [ ALL BUT ] <attribute name commalist> } AS <attribute name>
<unwrap>
  ::= <relation exp> UNWRAP <attribute name>
<group>
  ::= <relation exp> GROUP { [ ALL BUT ] <attribute name commalist> } AS <attribute name>
<ungroup>
  ::= <relation exp> UNGROUP <attribute name>
<attribute assign>
  ::= <attribute name> := <exp>

Note: An alternative form of <attribute assign>, syntactically identical to a <relation assign> except that the pertinent <attribute name> (a) can appear wherever a <relvar name> is allowed and (b) must appear in place of the target <relvar name> (in both cases, within that <attribute assign>), is also supported if the attribute in question is relation valued. The same goes for tuple valued attributes, mutatis mutandis.

<dyadic op>

  ::= <relation exp> <dyadic op name> <relation exp>
<dyadic op name>
  ::= UNION | D_UNION | INTERSECT | MINUS | I_MINUS | JOIN | TIMES | MATCHING | NOT MATCHING
<n-adic op>
  ::= <n-adic op name> { <relation exp commalist> }
<n-adic op name>
  ::= UNION | D_UNION | INTERSECT | JOIN | TIMES
<relation comp>
  ::= <relation exp> <relation comp op> <relation exp>
<relation comp op>
  ::= = | ≠ | ⊆ | ⊂ | ⊇ | ⊃

Assignments

<relation assignment>
  ::= [ WITH ( <temp assign commalist> ) : ] <relation assign commalist> ;
<relation assign>
  ::= <relvar name> := <relation exp> | <insert> | <d_insert>| <delete> | <i_delete>| <update>
<insert>
  ::= INSERT <relvar name> <relation exp>
<d_insert>
  ::= D_INSERT <relvar name> <relation exp>
<delete>
  ::= DELETE <relvar name> <relation exp> | DELETE <relvar name> [ WHERE <bool exp> ]
<i_delete>
  ::= I_DELETE <relvar name> <relation exp>
<update>
  ::= UPDATE <relvar name> [ WHERE <bool exp> ] : { <attribute assign commalist> }

1The website www.thethirdmanifesto.com contains the most recent version of reference [50]. It also gives information regarding a variety of existing Tutorial D implementations, as well as other projects related to The Third Manifesto as such (see reference [52]). See also http://dbappbuilder.sourceforge.net/rel.html, which provides access to free downloads for Rel, a prototype implementation of Tutorial D by Dave Voorhis.

2Actually a <temp assign> doesn’t have to be a relational assignment specifically, but we make no attempt to include the nonrelational case in the simplified grammar in this appendix.

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

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