Tim Berners-Lee
Date: 1998, last change: $Id: Notation3.html,v 1.49 2001/11/27 23:59:33 timbl Exp $
Status: Tries to keep ahead of changes to the code. There are now machine-readable grammars for N3.

Up to Design Issues

An RDF language for the Semantic Web


n3

Notation 3 - original handwritten grammar

See the main Notation3 page.

Original hand-written grammar

Tokenizing not explicitly specified in that white space is not in the BNF for simplicity here. White space must be inserted whenever the following token could start with a character which could extend the preceding token.

All URIs are quoted with angle brackets. Qualified names have colons, so unquoted alphanumerics are all keywords, unless the @keywords directive is given, in which case the keywords given are keywords and anything else is a localname in the default namespace. Any keyword may be given even if not in the keyword list by prefacing it with "@".

Non-terminal productions are defined first, terminals after

document
void

statementlist period

statement
subject propertylist

directive

universal

existential

statementlist
void

subject property-list
statement period statementlist

subject
item
verb

prop (same as: has xxx)

has prop (same as: xxx )

is prop of (inverse direction)

a (same as: has rdf:type )

= (same as: has daml:equivaent)

=> (same as: log:implies )

<= (same as: is log:implies of )

prop
node
node
uri-ref2

anonnode

variable

number

string

this (identifies the current formula - deprectaed from 2002/08

anonnode

[ property-list ] (a blank node, rerad as "something which ..." )

{ statementlist } ( a formula, the statementlist itself as a literal resource )

( itemlist ) ( short for: eg [rdf:first node1; rdf:rest [ rdf:first node2; rdf:rest: rdf:nil ]])

universal

@forAll uriref2list period

existential

@forSome urirefslist period

uriref2list
void

uriref2 uriref2list

prefix
alpha

prefix alphanumeric
_ (special ntuples hack. Everything in _ namespace is implictly existentially qualified at the current scope. Must not be used in >1 scope.)

variable
? localname (rule writing hack - implicitly universally quantified in parent formula of current)
propertylist
void ( to allow an anonymous node by itself [:a :b ]. But :a. generates no statements. )

verb objectlist

verb objectlist ; propertylist

objectlist
object

object , objectlist

item
path

node of path (Not implemented, just an idea)

itemlist
void

item itemlist

path
node

path traverse node ( same as [ is node of path ] )

path uparrow node (same as [node path] )

uri-ref2
qname

< URI-Reference >

qname
prefix : localname

localname ??? Allow omit colon when prefix void - keyword clash

object
item
directive
@prefix prefix : uri-ref2 period ( Namespace declaration, valid until changed. )

@keywords keywordlist period

localname
alpha

localname alphanumeric

keywordlist
void

keywordlist localname

number
integer

rational
real

integer
sign

digitstring

sign
+

-
void

digitstring
digit

digit digitstring

rational
integer / digitstring ratio between first integer and digitstring

integer . digitstring rational number expressed as a decimal

real
integer e integer (a real number roughly equal to i1 * ten ^ i2)

Terminals:

@prefix @keywords a this = => <= < > : are all terminals which are just the strings themselves. The following are other terminal symbols:

alpha
any letter a-z or A-Z case sensitive
ialpha
any unicode character not in the USASCII set and not puctuation. Be conservative. @@ need precise category membership, but beware that unicode character categories change with addition of new characters.
ichar
any unicode character > U+007F. @@ Must excluse weird cases such as byte-order mark
alphanumeric
alpha

any digit 0-9
_ (the underscore)

digit
any digit 0 - 9
period
A dot ".". (Was: a dot which, looking ahead, is not followed by anything except a closing bracket, brace, or whitespace.)
traverse
An exclamation mark, "!". (was: A full stop "." which is followed by alphanuemric, or open bracket or brace or uriref etc)
string
" constant-value-with-escaping "
""" constant value with escaping including single or double occurences of quotes and/or newlines """
uparrow
"^"
URI-Reference
An absolute or relative URI, with or without a "#" in it. See RFC____ as being amedended. Whitespace within the URI-reference is ignored to ease the inclusion oflong URIs in files. ASCII space (-0x20) characters should obviously be escaped if they are actually part of the URI.
void
nothing at all.