By Peter Bell

Describing Grammars – Defining a Syntax

I have spent some time looking at Backus-Naur Form, Extended BNF, schemas, DTDs, Relax NG and various other concrete textual syntaxes for describing grammars (some of them define XML specific grammars, but the concepts are close enough to compare both grammar and schema languages). I am currently playing with my own syntax, which I find a little more useful for me than any of the alternatives I’ve found to date for the class of declarative DSLs I’m focused on as an Active Data Modeler . . .

I like the general structure of EBNF but want to distinguish between attributes that are concepts in their own right and those that just have a primitive data type. It is a slightly less generalized approach than EBNF, but I find it useful to distinguish the tree leafs (which would be implemented as columns in an Active Data Model) from the other nodes (which would be implemented as tables). Apart from anything else I find the concepts to be more “important” and like the ability to get a sense of the grammar without worrying about primitive data types and then to see the data type information below. Here is a sample:

Concepts:
Object: Name [ShortDescription] [Description] [“extends” Object.Name] {Attribute}
Attribute: Name [ShortDescription]

Attributes:
Object.Name: text(100)
Object.ShortDescription: text(250)
Object.Description: ntext
Attribute.Name: text(100)
Attribute.ShortDescription: text(250)

I’ve kept the “::=” for “is comprised of”, square brackets still define optionality and curly brackets still define elements that there can be 0..n of. Note that the dot notation (Object.Name) for allows different concepts to have attributes with the same name without necessarily being the same data type.

I just find this a little easier to understand, but I am extremely new to playing with grammars and haven’t looked into the notations used by the tooling out there, so I may well find I’ve been reinventing the wheel. However, the good news is that as long as the underlying abstract grammar I support matches EBNF, I could always write a transformation to map one to the other automatically.

Any thoughts/suggestions/ideas?!

Comments
Am I the only person who reads Peter's blog and feels like I'm re-reading my compsci text books? BNF? Jeez, it's been over 14 years since someone asked me a quesion about BNF! I'll grab my NLP text book tonight and see if I can find a more suitable response.
# Posted By Adam Howitt | 1/29/07 6:11 PM
HEy Adam,

Yeah, sorry for all of the CompSci, but it's for a good cause - less code to provide more functionality. Now that it is solving a real problem (how can I write a generic tool that will automatically create a schema for storing and scripting for accessing the metadata in any generalized DSL), it actually becomes important/interesting to me :->
# Posted By Peter Bell | 1/29/07 8:55 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.005.