Specific Language Domain in C / C ++, does it Kosher?

I was just fooling myself with some domain-specific language projects for a new C / C ++ project when I came up with this “weird” solution:

define DSL(...) MakeCommand(#__VA_ARGS__\ )->Exec()->GetResults() MyResults results = DSL( for p in people do something ); 

The good part is right by standards (but it is also a Duff Switch), and cross-platform, portable, etc. However, this method is really no better than writing lines to code, but since the DSL Engine parses lines anyway, it seems to look prettier and reduce clutter. But it was interesting what other people thought.

thanks

+4
source share
1 answer

Hmm, and variable macros are C99, in C ++ they are impossible. I wouldn’t do this :) A simple dsl function using std::string or any std::string class used by your framework and returning MakeCommand(str)->Exec()->GetResults() will be my preferred option since it is more friendly to debug, and you can put it in a namespace.

You can also dynamically create command lines and pass them to functions. Using your macro approach, passing the str variable would actually pass "str" to the MakeCommand function. You will need another macro for dynamic commands to make it work, and I would be uncomfortable.

+6
source

All Articles