
Larry Evans wrote:
On 03/23/08 16:02, Larry Evans wrote:
On 03/22/08 22:12, Eric Niebler wrote:
Larry Evans wrote: [snip]
The following grammar I think summarizes the difference between grammar and expression:
expr //describes an expression. = terminal | expr+ //i.e. 1 or more expressions (e.g. expr<tag::plus,expr0,expr1>) ;
In addition, I wanted some way to tell what's a valid 1st arg to matches. The above description of expr is for a grammar. Now a valid 1st arg to matches would apply ::type to each node in the above tree, AFAICT. At first, I thought of:
expr_type = terminal::type | expr_type+ ;
but that would make:
( terminal::type, terminal::type, terminal::type )
a valid expresion when what's needed is:
( terminal::type, terminal::type, terminal::type )::type
OOPS (again). I guess this would produce what's needed:
expr_type = terminal::type | (expr_type+)::type ;
I'm confused by your syntax, so I can't say whether this is right or not. I'm pretty sure the use of ::type is wrong. Let me see if I can put in words what an expression is, and what a grammar is, and what the relationship is between the two. Maybe you can combine this with your understanding of morphisms to formulate this. An expression is one of: * expr<tag::terminal, args0<X> > * expr<Tag, argsN<A0,A1,...> > where A0,A1,... are expressions * ref_<E> where E is an expression * Some class type T that inherits from extends<E,T,D>, where E is an expression, and D is the domain of T. * Some class type T that uses BOOST_PROTO_EXTENDS(E,T,D) to extend an expression type E in the domain D. A grammar is: * _ * An expression * expr<tag::terminal, args0<exact<X> > > * expr<tag::terminal, args0<convertible_to<X> > > * expr<Tag, argsN<A0,A1,...> > where A0,A1,... are grammars * expr<_, argsN<A0,A1,...> > where A0,A1,... are grammars * expr<Tag, argsN<A0,A1,...,vararg<B> > > where A0,A1,... are grammars, and B is a grammar. * expr<_, argsN<A0,A1,...,vararg<B> > > where A0,A1,... are grammars, and B is a grammar. * or_<A0,A1,...> where A0,A1,... are grammars * and_<A0,A1,...> where A0,A1,... are grammars * switch_<C> where C is class type representing a set of grammars. * if_<T> where T is a transform that yields a compile-time Boolean * if_<T,Then> where T is a transform that yields a compile-time Boolean and Then is a grammar * if_<T,Then,Else> where T is a transform that yields a compile- time Boolean and Then and Else are grammars * not_<A> where A is a grammar * Some type T for which T::proto_base_expr is a grammar (e.g., negate<X>) -- Eric Niebler Boost Consulting www.boost-consulting.com