translate C-code into objects
Dear All, 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? Peter
2011/7/30 Peter Foelsche
Dear All,
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?
Why not Phoenix? http://www.boost.org/doc/libs/1_47_0/libs/phoenix/doc/html/index.html
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. Peter
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. Regards, Nate.
"Nathan Ridge"
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?
I want to manipulate these objects. I want to iterate over these objects and create a new set of objects.
On Sun, Jul 31, 2011 at 10:00:18AM -0700, Peter Foelsche wrote:
"Nathan Ridge"
wrote in message news:BLU162-w391671204D2BB963EB584996390@phx.gbl... 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?
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@acc.umu.se
On Sunday, July 31, 2011 10:00:18 AM Peter Foelsche wrote:
"Nathan Ridge"
wrote in message news:BLU162-w391671204D2BB963EB584996390@phx.gbl... 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?
I want to manipulate these objects. I want to iterate over these objects and create a new set of objects.
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/phoenix/examples/... 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/mon/phoenix_v3.pd... HTH, Thomas
participants (5)
-
Lars Viklund
-
Nathan Ridge
-
Peter Foelsche
-
Thomas Heller
-
TONGARI