Grammar for DAWG query language

I have done a first attempt at a grammar that parses the outline syntax
from the F2F.  
It parses the example query.  There is also a rather long query below
that exhibits most features at the end.

The grammar is more general than the example:
 + Has OPTIONAL as well as [] for optionals
 + Has grouping by () - this allows blocks after "SOURCE ?src"

One issue arose:

  SOURCE ?src (?x ?y ?z) AND ?z < 2
  
Does the AND apply to the inner SOURCE triple
e.g. is it:

 ( SOURCE ?src (?x ?y ?z) ) AND ?z < 2
or 
 SOURCE ?src ( (?x ?y ?z) AND ?z < 2 )

Because SOURCE is a conjunctive element, the answer is the same even
though the parse trees are different.  I hope! 

Attached is an HTML file mechanically produced by jjdoc.
Terminals can be found in the full grammar.

Full details, including terminals in:
http://cvs.sourceforge.net/viewcvs.py/jena/BRQL/Grammar/dawg.jj?rev=1.5
but do check for the latest version.  It takes a while for the web
interface to catch up with the true state of CVS.  

	Andy

---------------------------------------------------------

The example query was:

# Query from Bristol-F2F
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT ?name1 ?name2 ?hpage2
WHERE
  (?x foaf:knows ?y)
  SOURCE <http:D2> (?x foaf:age ?n)
  (?x foaf:age ?n) 
  AND ?n < 18
  (?x foaf:name ?name1 )
 
  SOURCE <http:D2> (?x foaf:status ?status)

  SOURCE ?src (?x foaf:status1 ?status1)
  SOURCE ?src (?x foaf:status2 ?status2)
  
  [ ( ?y foaf:name ?name2 ) 
    ( ?y foaf:age  ?m) 
    AND ?m < 18
  ]

---------------------------------------------------------

A long, and silly, query would be:

PREFIX : <http://example.org/>
SELECT *
WHERE
  (?x ?y ?z) (?a ?b ?c)

  # Optional, [] syntax
  [ (?x ?y ?z) ]
  [ (?x ?y ?z) AND ?z < 2 ]
  [ (?x ?y ?z) (?x ?y ?z) ]
  [ (?x ?y ?z) (?x ?y ?z) AND ?z < 2 ]
  [ (?x ?y ?z) [ (?x ?y ?z) ] ]
 
  # OPTIONAL keyword
  OPTIONAL (?x ?y ?z) 
  OPTIONAL ( (?x ?y ?z) (?x ?y ?z) AND ?z < 2 )

  # SOURCE
  SOURCE ?src (?x ?y ?z)
  SOURCE ?src ( (?x ?y ?z) (?a ?b ?c) )

  # Careful - AND does not bind to the SOURCE pattern
  SOURCE ?src (?x ?y ?z) AND ?z < 2

  # It parses like (adding explicit grouping for clarity:)
  ( ( SOURCE ?src (?x ?y ?z) ) AND ?z < 2 )

  # Not as:
  SOURCE ?src ( (?x ?y ?z) AND ?z < 2 )

  # SOURCE/OPTIONAL mix 
  SOURCE ?src [ (?x ?y ?z) ]
  [ SOURCE ?src (?x ?y ?z) ]

  OPTIONAL ( (?x ?y ?z) SOURCE ?src ( :x :y :z ) )
  OPTIONAL ( (?x ?y ?z) OPTIONAL ( ( :x :y :z ) ) )

 

Received on Monday, 20 September 2004 16:41:33 UTC