views:

128

answers:

1

I've just come across the Ubuntu c-repl package which provides a REPL interface for C programming. Great! It is quite excellent for trying snippets and ideas, and intuitive to use. I love it. But there is no documentation at all, and I'd like to find out more about how to drive it.

Example:

> int foo( double x ) { return x+0.5;}
> foo(5.5);
> int x = foo(5.5);
> x
p x
$1 = 6

Things are going swimmingly well but then:

> #include <stdlib.h>
<stdin>:1:22: warning: extra tokens at end of #include directive

So I guess it doesn't like that... Anyone know of a good tutorial/blog/reference?

+2  A: 

According to the README file on the git repository, it's using gcc to compile each line of code and gccxml for include directives.

How it works

The approach is surprisingly simple: for each line of code you enter, we compile a shared object in the background. If the compilation succeeds, the object is loaded into a child process via dlopen(). Parsing of C #includes uses gccxml. (Unfortunately, I can't figure out how to use gccxml to parse the user's input, and due to the complexity of parsing C the input parser is currently hacky and heuristic.)

The error message is the same wording as the one you get with gcc ( though not with that input ). Maybe try without any whitespace.

Pete Kirkham