mentby.com
Blog | Jobs | Help | Signup | Login

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


Peter Foelsche Fri, 29 Jul 2011 19:59:29 -0700

Why not Phoenix?

http://www.boost.org/doc/libs/1_47_0/libs/phoenix/doc/html/i[..]


TONGARI Fri, 29 Jul 2011 23:01:19 -0700

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


Peter Foelsche Sat, 30 Jul 2011 18:52:54 -0700

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 Sat, 30 Jul 2011 21:43:11 -0700

news:BLU162-w391671204D2BB963EB584996390*******...

I want to manipulate these objects.
I want to iterate over these objects and create a new set of objects.


Peter Foelsche Sun, 31 Jul 2011 10:01:31 -0700

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*******


Lars Viklund Sun, 31 Jul 2011 10:32:53 -0700

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[..]

HTH,
Thomas


Thomas Heller Sun, 31 Jul 2011 23:04:09 -0700



Related Topics

Post a Comment