Cling – an interactive C++ interpreter

Computer screen
Image by Markus Spiske from Pixabay

When I first learned to program back in 1976, I had a teletype and a BASIC interpreter. Apart from a couple of years writing BASIC programs in my first job, all my work after that was with compilers.

So I’m a bit rusty with interpreters. The idea is that the interpreter reads a line of code and then executes it; parsing it and calling various routines to execute statements and parse then evaluate expressions. It’s kind if unusual to do this with C++. Cling is built on the top of LLVM and Clang libraries.

This is different to sites like repl.it, codepad.org or ideone.com; they compile the whole program and run it. With an interpreter, it runs line by line and you can print out variables at any time.  Interpreters are probably more like debuggers.

As well as C++, cling can execute C, Objective-C and that even less used language Objective-C++.  Developed at Cern it has a very extensive set of tutorials.