This is the mail archive of the
docbook@lists.oasis-open.org
mailing list for the DocBook project.
RE: [docbook] Using the EBNF module for space-structured languages
- From: Ruth Ivimey-Cook <Ruth dot Ivimey-Cook at ivimey dot org>
- To: Mauritz Jeanson <mj at johanneberg dot com>
- Cc: 'Ruth Ivimey-Cook' <Ruth dot Ivimey-Cook at ivimey dot org>, docbook at lists dot oasis-open dot org
- Date: Wed, 09 Feb 2005 00:34:56 +0000
- Subject: RE: [docbook] Using the EBNF module for space-structured languages
- References: <200502081959.j18JxTdD149408@mailhost.bostream.com>
On Tue, 2005-02-08 at 20:59 +0100, Mauritz Jeanson wrote:
> > On Mon, 2005-02-07 at 13:45 +0000, Ruth Ivimey-Cook wrote:
> > > Occam-Pi is a space-structured language, (in the same way
> > > as Python and occam from which Occam-Pi is derived. How can I define
> > > EBNF grammars for it in DocBook?
> Or maybe you haven't described the problem clearly enough. Are
> space-structured languages especially complicated? Is there something
> missing in the DocBook documentation about EBNF
> (http://docbook.org/tdg/en/html/productionset.html)? (I don't know much
> about grammars and such, I am just curious).
Sorry if I wasn't clear. I'll try again.
What I mean by 'space structured languages' are languages in which the
layout of the statements (newlines, spaces and so forth) conveys
information about the context to the compiler. In the C language, for
example, you could say either:
if(a==b){c=g;printf(e);}
or
if (a==b)
{
c=g;
printf(e);
}
and they mean exactly the same thing. In Occam-Pi, you might write:
IF
a = b
SEQ
c := g
printf(e)
TRUE
SKIP
and you couldn't lay it out any other way: the following code is
invalid:
IF a = b SEQ
c := g
printf(e)
because the condition of an IF must be on a new line, and the SEQ must
also be on a new line, and even if SEQ were allowed, the indentation
level of the assignment is wrong.
Now, if I want to describe this sort of language in EBNF, I could write:
if-statement := 'IF' newline-indent ( condition newline-indent
process )+
newline := '\n'
newline-indent := newline increment-level indent-to-current
indent-to-current := ' ' x level # 'level' is current statement
level
to describe the fact that an IF statement has the sort of structure
shown above. However, it is very hard to indicate the indentation level
of, say, "process" in the production above - you have to resort to the
'tricks' above to do so. Am I making sense here?
In the existing occam books, the authors resorted to a sort of partial
BNF, in which the layout is presented rather than written. I was sort of
hoping that something of the sort might be reasonably easy in
DocBook/EBNF.
Is the problem really that I shouldn't be using EBNF at all?
Regards,
Ruth
--
Ruth Ivimey-Cook <ruth@ivimey.org>