Re: design question? or puzzle?

Sorry, it got sent by accident before I was finished.  Continuing:
> This may be a design question for ixml, or it may be just a puzzle about how to use ixml to achieve the goal. I’m not sure.

I think the latter. People are pressurising me to do something on ixml for Declarative Amsterdam (advert: 4 and 5 November 2021), and maybe I should do a tutorial. Which means I have to finish a releasable implementation. Oh well, at least I have something to do over the summer.

 I was sure I already published an example of doing the sort of thing you are asking for here, but I don't seem to be able to find it. Did I dream it? Or do I have to search harder. I'll do the latter.

> > First, consider a simple grammar for arithmetic expressions:
> >
> > expression: sum.
> > sum: product+addop.
> > product: factor+mulop.
> > factor: number; identifier; ‘(‘, expression, ‘).
> > addop: ‘+’; ‘-‘.
> > mulop: ‘/‘; ‘*’; ‘×’; ‘÷’.
> > …
> >
> > An XML representation of this, as an ixml parser would produce it, works nicely to exhibit the structure of an expression like 2 x^3 + 17 x^2 -5x + 7:
>

The above grammar neither recognises this expression, nor produces the following serialisation, since it doesn't accept an implicit multiply sign, nor convert x^2 to x x.

> > But this XML representation for the number 3 might feel ... a bit heavy in some contexts:
> >
> > <expression>
> > <sum>
> > <product>
> > <factor>
> > <number>3</number>
> > </factor>
> > </product>
> > </sum>
> > </expression>
>
> True, but you can elide all of the unnecessary bits: you never need product or factor, since they are there for syntactic reasons, not semantic:

expression: expr. 
-expr: term; sum.
sum: term, "+", term+"+".
-term: factor; prod.
prod: factor, "×", factor+"×".
-factor: id; number; "(", expr, ")".
id: ["a"-"z"]+.
number: ["0"-"9"]+, (".", ["0"-"9"]+)?.

would give

<expression><number>3</number></expression>

Steven

Received on Tuesday, 13 April 2021 13:07:06 UTC