Boost logo

Boost :

From: joel de guzman (joel_at_[hidden])
Date: 2001-05-25 00:16:54


From: "Douglas Gregor" :

> However, the prefix + and * are doubly bad. The overloaded meanings have
> absolutely nothing to do with the original meanings of either operator
and,
> perhaps worse, it doesn't conform to the syntax used in theoretical
language
> applications either. Essentially the syntax conforms to neither C++ nor
the
> domain it is intended to model, and I think that will become overly
> confusing.
>

But it's close.

a* ----> *a
a+ ----> +a

I find that very easy to comprehend given the proper documentation.
Consider also the audience that Spirit addresses. I doubt that it will
be useful by novices. At least some background in parsing is required.
I'm sure people with this background will not find the slight shift in
meaning "overly confusing".

Also all the EBNF operators have absolutely nothing to do with the
original meanings in C++. So does cout << "Hello World". As to what
constitute an abuse, that's also very subjective.

We cannot avoid having a shift in the meaning of operators here.
After all, what we are trying to do is 'inline' EBNF in C++. These
are totally different languages. What I do is to clearly separate the
declarative EBNF from straight C++. Here's a snippet from
the test.cpp file:

// Start grammar definition

 ChLit<> plus('+');
 ChLit<> minus('-');
 ChLit<> times('*');
 ChLit<> divide('/');
 ChLit<> oppar('(');
 ChLit<> clpar(')');

 Rule<> expr;
 Rule<> integer = Lexeme[ !(plus | minus) >> +digit ];
 Rule<> group = oppar >> expr >> clpar;
 Rule<> group2 = integer >> plus;
 Rule<> expr1 = doInt(integer) | group;
 Rule<> expr2 = expr1 >> *(doMult(times >> expr1) | doDiv(divide >>
expr1));
 expr = expr2 >> *(doAdd(plus >> expr2) | doSubt(minus >> expr2));

 // End grammar definition

The opposite extreme is:

rule = alt(a, (seq(b, c)); // rule = a | b c

... Reminds me of lisp/scheme

I'd like to be consistent. If we are to reuse | to mean alternative,
what's wrong with reusing prefix + and *? Still I'd go for the
iterator since it addresses something that the * and + couldn't do:

repeat<8, 8>(a); // repeat 'a' exactly 8 times

Cheers,
Joel de Guzman


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk