Well, that was clever

closed account (1yR4jE8b)
http://susam.in/blog/compiler-taking-input-while-compiling/
That's ingenious.
Thats crazy.. In yet i wonder if it's possible to make a C++ command line? LOLS

EDIT
err.. console, rather.
Last edited on
This kind of works:

g++i.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
import sys
import random

cpp_head = """#include <iostream>
#include <string>

int main(int argc, char* argv[])
{
"""

cpp_tail = """	return 0;
}
"""

UINT64_MAX = (2 ** 64) - 1
random.seed()
while True:
	# Get user input
	line = raw_input(">>> ")
	# Create source file
	cpppath = str(random.randint(0, UINT64_MAX)) + ".cpp"
	cppfile = open(cpppath, 'w')
	cppfile.write(cpp_head + line + cpp_tail)
	cppfile.close()
	# Create executable file
	exepath = str(random.randint(0, UINT64_MAX))
	if os.name in [ "nt", "os2", "ce" ]:
		exepath += ".exe"
	os.system("g++ -o " + exepath + " " + cpppath)
	# Delete source file
	os.unlink(cpppath)
	# Run executable file
	if os.name in [ "nt", "os2", "ce" ]:
		os.system(exepath)
	else:
		os.system("./" + exepath)
	# Delete executable file
	os.unlink(exepath)
X:\Projects\Scripts>python "g++i.py"
>>> std::cout << "hello, world" << std::endl;
hello, world
@Chris, That's cheating, IMO :P

Though it would be interesting to design a C++ interpreter that's completely compliant with the current standard.
closed account (1yR4jE8b)
Well, Beanshell (http://www.beanshell.org/) is a Java interpreter, so I suppose it's possible.
I would expect creating an interpreter for a language that already runs on a virtual machine would be easier than one that's compiled to native code.
I don't see why.
chrisname -- heh, that would be interesting creating a full fledged C++ shell, with dynamic library loading.. probably pointless though :D
Well, there's CINT...

http://root.cern.ch/drupal/content/cint

CINT is an interpreter for C and C++ code. It is useful e.g. for situations where rapid development is more important than execution time


CINT covers most of ANSI C (mostly before C99) and ISO C++ 2003.

Last edited on
I hadn't heard of that one O:
Topic archived. No new replies allowed.