Re: Grammar validation?

If I understand your example, yes, it’s possible to have a nonterminal
like ‘div’ appear as child of two different parents.  Imagine a
schematic grammar for a subset of HTML, which for simplicity 
has no attributes.

html: -‘<html>’, head, body, -‘</html>'.
body:  -‘<body>’, p*, div*, -‘</body>’.
div: -‘<div>’, heading?, p*, div*, -‘</div>’.
p: -‘<p>’, paragraph-content, -‘</p>’.
heading:  h1; h2; h3; h4; h5.
h1: -‘<h1>’, text-content, -‘</h1>’.
h2: -‘<h2>’, text-content, -‘</h2>’.
…

Here the nonterminal ‘div’ can appear both within a ‘body’ and 
within another ‘div’.  And ‘p’ can appear both within ‘body’ 
and within ‘div’.

If on the other hand we want to say that the RHS for div as 
a child of body should include h1, and the RHS for div as a child
of body/div should include h2, and so on, then no:  once a 
nonterminal is produced, its expansion is not allowed to depend
on its context (parentage or left/right neighbors in the sentential
form).  So the div nonterminal referred to in the RHS of body
and the div nonterminal referred to in the RHS of div will have
the same possible expansions.  

If instead of the above we write something like 

...
body:  ‘<body>’, p*, div1*, ‘</body>’.
div1: ‘<div>’, h1?, p*, div2*, ‘</div>’.
div2: ‘<div>’, h2?, p*, div3*, ‘</div>’.
div3: ‘<div>’, h3?, p*, div4*, ‘</div>’.
div4: ‘<div>’, h4?, p*, div5*, ‘</div>’.
…

then we can successfully require that headings be wrapped in divs
and that the correct headings are used in the input for the level
at which they appear.  But the XML produced by this grammar will
not have generic ‘div’ elements, but ‘div1’, ‘div2’, etc.

Steven Pemberton recently suggested a facility for what I guess one 
might call renaming of nonterminals, which would allow the div1,
div2, and similar nonterminals in the grammar all to be serialized in
XML as ‘div’, but it has not yet been discussed.  I am currently a
little concerned about its possible effect on the task of writing a
schema for the XML produced by an ixml grammar, and on the
task of writing a serializer to go from visible XML to invisible XML
form.

I hope this helps.

Michael

> On 8,Nov2021, at 1:00 AM, Dave Pawson <dave.pawson@gmail.com> wrote:
> 
> 
> 
> On Sun, 7 Nov 2021 at 23:30, C. M. Sperberg-McQueen <cmsmcq@blackmesatech.com> wrote:
> Dave,
> 
> I’m not sure I understand what you are saying or asking about n and m.
> Can you give an example?  (If Steven’s earlier answer has cleared everything
> up, feel free to ignore this inquiry.)
> 
> Take html, doc/div/div vs doc/div
> Same element different location within the tree.
> In xml this is allowed. Is it allowed in i xml?
> Ie. Same name, different xpath location.
>  I don’t think it is with the current spec?
> 
> Regards
> 
> 
> 
> 
> 
> Michael
> 
> > On 7,Nov2021, at 5:14 AM, Dave Pawson <dave.pawson@gmail.com> wrote:
> > 
> > Thanks Steven.
> > 
> > =====================
> > Spec.
> > 
> > The grammar must not contain more than one rule defining any given
> > name. {needed?}
> > May contradict nonterminals defn
> > This name refers to the rule that defines this name, which must exist,
> > and there must only be one such rule.
> > 
> > Which disallows names n and m, each having a different xpath location
> > in the tree?
> > Is this intended?
> > 
> > regards
> > 
> > 
> > On Sun, 7 Nov 2021 at 11:51, Steven Pemberton <steven.pemberton@cwi.nl> wrote:
> >> 
> >> Sure. From the tutorial there is a link where you can upload an ixml
> >> grammar, and a sample input.
> >> See http://www.cwi.nl/~steven/ixml/tutorial and go to the page "How it
> >> works".
> >> 
> >> Steven
> >> 
> >> On Sunday 07 November 2021 12:00:49 (+01:00), Dave Pawson wrote:
> >> 
> >>> If I try to write a grammar for some input, is there any way I can
> >> validate
> >>> what I've written please?
> >>> 
> >>> regards
> >>> 
> > 
> > 
> > 
> > -- 
> > Dave Pawson
> > XSLT XSL-FO FAQ.
> > Docbook FAQ.
> > 
> 
> -- 
> Dave Pawson
> XSLT XSL-FO FAQ.
> Docbook FAQ.

Received on Monday, 8 November 2021 15:28:11 UTC