I would like to translate some C-Code into objects.
I did this already for functions and expressions:
Writing template functions and passing my expression object as an argument.
Now I want to do this for C-Code, which uses if-statements and variables.
To do this, I would implement some template function for an if-statement.
And some function for an assignment to a variable.
Probably using enumerations to indicate the variable.
Is this the right approach?
phoenix is some library to create lambda functions.
This is not what I need.
I want to get objects out, which I can later work on.
What sort of "work" do you want to do with these objects?
Phoenix *is* a library that creates objects representing
pieces of C++ code - these objects can then be "called"
(operator()) to execute the code they represent.
For example, the phoenix expression
if_(ref(x) > 5)
std::cout << ref(x)
represents an object that, when called, executes the code
if (x > 5)
std::cout << x;
(where x is an already-declared variable in your program).
Whether or not Phoenix is suitable for you depends on what
you want to do with these objects.
I want to manipulate these objects.
I want to iterate over these objects and create a new set of objects.
I don't think anyone understands what you're trying to do.
If you want to capture and manipulate the syntax tree of arbitrary
expressions, consider something like Boost.Proto.
Proto is commonly used to make embedded languages with C++ syntax. This
will not capture things like flow control structures, but you can
trivially define your own if_, for_-alikes through terminals, the
semantics of which you define in your Proto grammar.
If this sounds like something that fits your use case, consider watching
the Boostcon presentations on Proto, and read the documentation.
Lars Viklund | zao*******
Use Phoenix. You can access the underlying expression tree and manipulate your
expression objects however you like.
Have a look here: http://www.boost.org/doc/libs/1_47_0/libs/phoenix/doc/html/p[..]
This example is also explained in the boostcon talk by Hartmut here (to the
end of the talk): http://blip.tv/boostcon/phoenix-v3-an-overview-5250984 https://github.com/boostcon/2011_presentations/blob/master/m[..]