Partially parse C ++ for a domain specific language

I would like to create a domain specific language as an extended C ++ language. I will mainly need two types of constructions:

  • Top-level constructs for specialized types or declarations
  • Intracode designs, i.e. to add primitives to facilitate the execution of functions or idioms

The language will be used for scientific computing purposes and will ultimately be translated into simple C ++. C ++ was chosen as if it offers a good compromise between: ease of use, efficiency and availability of a wide range of libraries.

a previous attempt to use flex and bison failed due to the complexity of C ++ syntax. An existing parser may still fail on some constructs. Therefore, we want to start all over again, but on better grounds.

Do you know about similar projects? And if you try to do this, what tools would you use? What would be the main pitfalls? Did you have any syntax recommendations?

+6
c ++ parsing code-generation dsl
source share
5 answers

There are many (smart) attempts to have domain specific languages ​​in C ++.

It is usually called DSEL for the embedded domain language. For example, you can find the syntax of Boost.Spirit or Boost.rdb (in the boost repository).

These are fully compatible C ++ libraries that use C ++ syntax.

If you want to hide some complexity, you can add several macros.

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

+3
source share

You can try decrypting the open source Elsa C ++ parser (now it is part of the Mozilla Pork project):

https://wiki.mozilla.org/Pork

+2
source share

If you really want to extend C ++, you will need a full C ++ parser plus name and type resolution. As you know, this is quite difficult. The best solution is to get an existing one and change it.

Our DMS Software Reengineering Toolkit is an infrastructure for implementing langauge processors. it is intended to support the construction of tools that analyze languages, perform transformations, and splash out the same language (with extended code) or another language / dialect.

DMS has a complete C ++ Front End , which analyzes C ++, builds abstract syntax trees and symbol tables (for example, all this name and type resolution).

The front of DMS / C ++ comes with DMS in its original form, so it can be customized to achieve the desired effect. You would define your DSL as an extension of the front end of C ++, and then write down transformations that convert your custom constructs into C ++ vanilla constructors and then spill out the compiled result.

DMS / C ++ was used for a wide range of conversion tasks, including those that included the C ++ extension, as you described, and included tasks that perform massive reorganizations of large C ++ applications. (See Publications on this website).

0
source share

The way to extend C ++ is not an attempt to expand the language, which will be extremely difficult and may break, as new releases of the base compiler implement new functions, but to write class libraries to support your problem domain. This has been what C ++ has been programmed about since the language was created.

0
source share

To solve the first bullet, perhaps you can use C ++ 0x with the new functions “initializer lists” and “user-defined letters”, avoiding the need for a new parser. They can help for the second bullet.

-one
source share

All Articles