I have one program which takes a set of statements into a variable,
and how can i place that block of code(which is given into a variable as string) dynamically into present executing code for compilation and execution.
i am eagerly waiting for this solution.
any programming language having this facility..
if yes please paste the code for this question
I have one program which takes a set of statements into a variable, and
Share
Perl makes this simple.
In Perl:
or
See eval.
Note, you should be careful where you get your code from. You’re exposing the full power of your language to whoever provides you with the input. Make sure it’s coming from a safe source. “string eval”, as it’s called, is high risk behavior in any language that supports it. Accepting input from a web user and running it as code on your server, for example, is just asking for a disaster.
With respect to C: C is a compiled language, and the compiler isn’t available at run-time. On the other hand, there’s nothing stopping you from embedding a Perl interpreter in a C program, which would give you run-time compilation and execution of Perl code from within your compiled C application. For the record, C++ is in the same boat. It’s a compiled language, and the compiler isn’t a component of the runtime environment.
As for Java, there’s this article: The Java 6.0 Compiler API.