Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #8699
| From | jacob navia <jacob@spamsink.net> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Evaluating a string as C++ Code |
| Date | 2011-08-12 10:25 +0200 |
| Organization | lccwin |
| Message-ID | <j22o22$e5l$1@speranza.aioe.org> (permalink) |
| References | <c129d820-b60e-4e46-9608-5fb6ff3e6de8@a12g2000vbf.googlegroups.com> |
Le 30/07/11 18:52, Miro a écrit :
> Hello, Usenet.
>
> I come from a background of mostly Perl and Ruby, so C++ is the first
> truly low level programming language that I know. However, I have
> something I'd like to ask the community about. I'm rewriting a BC-
> esque terminal calculator I did in Perl. (You can find it on
> SourceForge as PerlCalc, I believe.), and I've encountered a problem
> that my manual book doesn't cover. In Perl, you can evaluate a string
> as code like this:
> #Getting the string
> my $string =<STDIN>;
> chomp( $string );
> # Evaluate it and print it
> print(eval($string));
>
> How, pray tell, might I do that in C++?
>
> Thanks for your help,
> Miro
If you limit yourself to the C language (not C++) you do:
#include <jit.h>
int (*pfn)(void);
int main(void)
{
pfn = compile("#include <stdio.h>\nint main(void){ printf(\"hello\");}\n");
if (pfn)
pfn();
}
You can do this using a Just In Time compiler. For more
information (and pricing) just contact
jacob at jacob dot remcomp dot fr
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Evaluating a string as C++ Code Miro <nickbergeronsemail@gmail.com> - 2011-07-30 09:52 -0700
Re: Evaluating a string as C++ Code jt@toerring.de (Jens Thoms Toerring) - 2011-07-30 17:40 +0000
Re: Evaluating a string as C++ Code Miro <nickbergeronsemail@gmail.com> - 2011-08-06 13:55 -0700
Re: Evaluating a string as C++ Code jt@toerring.de (Jens Thoms Toerring) - 2011-08-07 00:53 +0000
Re: Evaluating a string as C++ Code Carlo Milanesi <carlo.nospam.milanesi@libero.it> - 2011-07-30 20:08 +0200
Re: Evaluating a string as C++ Code James Kanze <james.kanze@gmail.com> - 2011-08-07 10:26 -0700
Re: Evaluating a string as C++ Code Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-08-11 21:33 +0000
Re: Evaluating a string as C++ Code Paavo Helde <myfirstname@osa.pri.ee> - 2011-07-30 15:33 -0500
Re: Evaluating a string as C++ Code BGB <cr88192@hotmail.com> - 2011-07-30 14:45 -0700
Re: Evaluating a string as C++ Code jacob navia <jacob@spamsink.net> - 2011-08-12 10:25 +0200
Re: Evaluating a string as C++ Code Juha Nieminen <nospam@thanks.invalid> - 2011-08-12 12:07 +0000
Re: Evaluating a string as C++ Code jacob navia <jacob@spamsink.net> - 2011-08-12 14:31 +0200
Re: Evaluating a string as C++ Code Alexei Zakharov <alexeiz@gmail.com> - 2011-08-18 01:53 -0400
Re: Evaluating a string as C++ Code Juha Nieminen <nospam@thanks.invalid> - 2011-08-18 06:22 +0000
Re: Evaluating a string as C++ Code Paavo Helde <myfirstname@osa.pri.ee> - 2011-08-18 12:26 -0500
Re: Evaluating a string as C++ Code Juha Nieminen <nospam@thanks.invalid> - 2011-08-18 18:13 +0000
Re: Evaluating a string as C++ Code Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-08-20 14:57 +0000
Re: Evaluating a string as C++ Code Nobody <nobody@nowhere.com> - 2011-08-20 19:35 +0100
Re: Evaluating a string as C++ Code Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-08-21 19:15 +0000
Re: Evaluating a string as C++ Code Nobody <nobody@nowhere.com> - 2011-08-21 21:50 +0100
csiph-web