C ++ DSL design for labeling and passing trees

In short

I am trying to create a more convenient C ++ interface for the C library, which sends tree expressions through a communication channel (à la iostreams vs stdio). I am not sure that it is generally possible to create DSL in C ++ to denote these trees, while avoiding run-time overhead, and if so, how.

Simplified C Library Explanation

There is a C library that can send "expressions" through a communication channel. "Expression" here means a tree structure that can be conveniently labeled similarly to function calls.

For instance,

f(1, 2, g(3), "foo")

stands for this tree:

Mathematica graphics

Some of you may recognize Mathematica at this point, but I decided to leave it as it is not relevant.

f head 1, 2, g(3).

, :

putHead("f" /* name */, 3 /* argument count */);
  putInteger(1);
  putInteger(2);
  putHead("g" /* name */, 1 /* argument count */);
    putInteger(3);
  putString("foo");

++ API ?

  • ( iostreams vs stdio)
  • ; ( f(1,2,g(3)) ),
  • (2) (.. )
  • C

(1) (.. Integer, String .. ). (2) , . , (2)/(3) ++. , ++.

. DSL ++ , ? , ? , , , , .

+4

All Articles