Re: [Boost-users] [Proto] Extracting types of sub-expression in transform
Eric Niebler wrote: Joel Falcou wrote:
> Hello, > > i have a DSL where terminal are defined like : terminal< simdproto::_ > > 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): http://lists.boost.org/Archives/boost/2008/03/135169.php 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 http://en.wikipedia.org/wiki/Algol68. 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?
van Godard wrote:
The canonical way to incorporate typing (including much richer type systems than this) in a formal grammar is through van Wijngaarden grammars. See http://en.wikipedia.org/wiki/Algol68. 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?
I hadn't even considered the notion of a type system for a DSEL, but it makes perfect sense. Unfortunately, the only tutorial I found for van Wijngaarden grammars is here: http://homepages.cwi.nl/~steven/vw.html Perhaps it's because I'm tired, but I'm not making heads or tails of it at the moment. Can you point me to a gentler introduction? (Way back when I started with expression templates, I thought that calling them an "embedded language" was just a cute metaphor, but much can be gained from taking the serious view that these really *are* languages, deserving of grammars, semantic actions, ... type systems, too. Once we fully embrace that view, there's decades worth of programming language theory we can leverage.) -- Eric Niebler BoostPro Computing http://www.boostpro.com
Eric Niebler a écrit :
(Way back when I started with expression templates, I thought that calling them an "embedded language" was just a cute metaphor, but much can be gained from taking the serious view that these really *are* languages, deserving of grammars, semantic actions, ... type systems, too. Once we fully embrace that view, there's decades worth of programming language theory we can leverage.)
You just have described parts of my research plans ;) My current work try to get a way using ET and Concept in C++ to have a condensed way to describe operationnal and/or denotanionnal semantic for C++ DSEL. Guess I'll indeed have to swallow up this typing system rules myself. Ivan : Thanks for the references. -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35
Eric Niebler a écrit :
http://homepages.cwi.nl/~steven/vw.html
Perhaps it's because I'm tired, but I'm not making heads or tails of it at the moment. Can you point me to a gentler introduction?
Foudn this myself : ftp://ftp.cs.vu.nl/pub/dick/publications/How_to_produce_all_sentences_from_a_two-level_grammar.ps Seems to me that vW meta-rules *looks like* tempalte grammar rule but maybe the example is too simple. -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35
participants (3)
-
Eric Niebler
-
Ivan Godard
-
Joel Falcou