Is there an interpreter for C? [closed]

2018-12-31 14:42发布

I was wondering if there is something like an interpreter for C. That is, in a Linux terminal I can type in "python" and then code in that interpreter. (I'm not sure interpreter the right word). This is really helpful for testing different things out and I'm curious if something similar exists for C. Though I doubt it. The only thing I can think of that would do it would be the C shell...

13条回答
栀子花@的思念
2楼-- · 2018-12-31 15:22

There are many - if you narrow down the scope of your question we might be able to suggest some specific to your needs.

A notable interpreter is "Ch: A C/C++ Interpreter for Script Computing" detailed in Dr. Dobbs:

Ch is a complete C interpreter that supports all language features and standard libraries of the ISO C90 Standard, but extends C with many high-level features such as string type and computational arrays as first-class objects.

Ch standard is freeware but not open source. Only Ch professional has the plotting capabilities and other features one might want.

I've never looked at this before, but having a c interpreter on hand sounds very useful, and something I will likely add to my toolset. Thanks for the question!


Edit:

Just found out that one of my favorite compilers, TCC, will execute C scripts:

It also handles C script files (just add the shebang line "#!/usr/local/bin/tcc -run" to the first line of your C source code file on Linux to have it executed directly.

TCC can read C source code from standard input when '-' is used in place of 'infile'. Example:

echo 'main(){puts("hello");}' | tcc -run -
查看更多
伤终究还是伤i
3楼-- · 2018-12-31 15:24

ccons appears to satisfy your constraints:

The goal of the ccons project is to create an interactive console for the C programming language, similar to "python" and "irb" for Python and Ruby respectively. The project builds on top of clang and llvm.

查看更多
柔情千种
4楼-- · 2018-12-31 15:24

CERN has a toolkit called ROOT, which is meant mainly for scientific or data analysis etc.. purposes but it has a Clang - based C/C++ Interpreter called Cling.

They were using a C interpreter called CINT before they adapted Cling. CINT is lightweight & still seems to be available for download.

I think you may get some other by carefully searching through Wikipedia list articles.

查看更多
谁念西风独自凉
5楼-- · 2018-12-31 15:25

Check Out iGCC

查看更多
柔情千种
6楼-- · 2018-12-31 15:26

You can use CompCert. Here are some examples: http://compcert.inria.fr/man/manual004.html

查看更多
路过你的时光
7楼-- · 2018-12-31 15:33

Probably. There are several for c++. See Have you used any of the C++ interpreters (not compilers)? for examples. Certainly cint will eat nearly any c code with good results, and tcc is so fast that you can use it like a interpreter.

查看更多
登录 后发表回答