Is there an interpreter for C?

CInterpreterRead Eval-Print-Loop

C Problem Overview


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

C Solutions


Solution 1 - C

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 -

Solution 2 - C

picoc - A very small C interpreter

> PicoC is a very small C interpreter for scripting. It was originally > written as the script language for a UAV's on-board flight system. > It's also very suitable for other robotic, embedded and non-embedded > applications.

Solution 3 - C

the ROOT project provides a very functional C and C++ interpreter called Cint. I'm quite fond of it. It takes a little getting used to interpretively, though.

TCC is a very good choice as well, but i'm not able to vouch for its REPL

Solution 4 - C

Probably. There are several for c++. See https://stackoverflow.com/questions/69539/have-you-used-any-of-the-c-interpreters-not-compilers/72792#72792 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.

Solution 5 - C

Give a look to the Ch Interpreter.

> Ch is an embeddable C/C++ interpreter > for cross-platform scripting, shell > programming, 2D/3D plotting, numerical > computing, and embedded scripting.

Solution 6 - C

I know we use CINT in class. It seemed pretty good you might want to give it a try!

Solution 7 - C

Check Out iGCC

Solution 8 - C

cinterp is one for a start.

Solution 9 - C

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.

Solution 10 - C

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

Solution 11 - C

More recently there is Cling (based on LLVM/Clang)

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

Solution 12 - C

It has been done, even though the vast majority of C work is compiled. One example is CH

Solution 13 - C

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondevinView Question on Stackoverflow
Solution 1 - CAdam DavisView Answer on Stackoverflow
Solution 2 - CalerootView Answer on Stackoverflow
Solution 3 - CSingleNegationEliminationView Answer on Stackoverflow
Solution 4 - Cdmckee --- ex-moderator kittenView Answer on Stackoverflow
Solution 5 - CChristian C. SalvadóView Answer on Stackoverflow
Solution 6 - CJaved AhamedView Answer on Stackoverflow
Solution 7 - CNeel BasuView Answer on Stackoverflow
Solution 8 - CpaxdiabloView Answer on Stackoverflow
Solution 9 - CicktoofayView Answer on Stackoverflow
Solution 10 - CJanus TroelsenView Answer on Stackoverflow
Solution 11 - Cideasman42View Answer on Stackoverflow
Solution 12 - CRob LachlanView Answer on Stackoverflow
Solution 13 - Cuser9600383View Answer on Stackoverflow