Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Partially parse C++ for a domain-specific language

I would like to create a domain specific language as an augmented-C++ language. I will need mostly two types of contructs:

  • Top-level constructs for specialized types or declarations
  • In-code constructs, i.e. to add primitives to make functions calls or idiom easier

The language will be used for scientific computing purposes, and will ultimately be translated into plain C++. C++ has been chosen as it seems to offer a good compromise between: ease of use, efficiency and availability of a wide range of libraries.

A previous attempt using flex and bison failed due to the complexity of the C++ syntax. The existing parser can still fail on some constructs. So we want to start over, but on better bases.

Do you know about similar projects? And if you attempted to do so, what tools would you use? What would be the main pitfalls? Would you have recommendations in term of syntax?

like image 607
PierreBdR Avatar asked May 06 '10 09:05

PierreBdR


2 Answers

There are many (clever) attempts to have domain specific languages within the C++ language.

It's usually called DSEL for Domain Specific Embedded Language. For example, you could look up the Boost.Spirit syntax, or Boost.rdb (in the boost vault).

Those are fully compliant C++ libraries which make use of C++ syntax.

If you want to hide some complexity, you might add in a few macros.

I would be happy to provide some examples if you gave us something to work with :)

like image 180
Matthieu M. Avatar answered Oct 26 '22 22:10

Matthieu M.


You can try extending an open source Elsa C++ parser (it is now a part of a Mozilla's Pork project):

https://wiki.mozilla.org/Pork

like image 39
SK-logic Avatar answered Oct 27 '22 00:10

SK-logic