Boost logo

Boost Users :

Subject: Re: [Boost-users] [Proto] Extracting types of sub-expression in transform
From: Ivan Godard (igodard_at_[hidden])
Date: 2008-10-18 22:57:44

  Eric Niebler wrote:

    Joel Falcou wrote:

> > Hello,
> >
> > i have a DSL where terminal are defined like : terminal< simd<proto::_> >
> > What I want is that any binary operator that apply on those terminal should
> > be available only if both lhs and rhs parts have the same underlying
> > type. E.G :
> >
> > simd<float> + simd<float> is ok while
> > (simd<char> + simd<char>)*simd<float> is not ok.
> >
> > How I can enforce this check ? Is having a transform that take an
> > expression and returns
> > the underlying type OR mpl::void_ if an error occurs the good solution ?

    This question has come up a couple of times. The solution isn't very
    pretty ... write a grammar that allows expressions with incompatible
    terminals, and then write a separate transform that checks the terminals
    for compatibility. This issue came up during Proto's review and I posted
    some example code here (see the SameTerminals transform):

    I wish I knew of a better solution.

The canonical way to incorporate typing (including much richer type
systems than this) in a formal grammar is through van Wijngaarden
grammars. See It is possible to
generate both the parser and type analysis from such a grammar, and
compilers that do so still exist.

Sadly, there is no Boost VWG library. Perhaps you'll write one?

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at