简体   繁体   中英

Lisp Interpreter in a C++ Program

I'm not sure I'm phrasing this right, but I'm pretty sure I'm looking for a LISP interpreter I can put in my C++ program.

The ideal situation I'm imagining is a function or something to which I can pass either a string, file, or filename containing the LISP code and then use the output from the LISP code in other parts.

To put it in terms of (print (eval (read))) , I want read to be something I input to be what's read, and a string or something I can parse from print.

There is also ECL ("Embeddable Common Lisp"). It has the advantage, that it provides the full Common Lisp standard. Unfortunately, the documentation with respect to embedding is... well... a little bit scarce.

I never used it myself, so I cannot really tell, whether this would actually be an easy thing to embed into your application. IMHO, the Guile interpreter would be a reasonable choice.

Another embeddable Lisp is Rep , which is, for example, the extension language used by the Sawfish window manager. It started as Emacs lisp clone, but became something different over time, and is nowadays closer to Scheme.

If you're interested in Common Lisp, there's ECL .

From the FAQ :

2.1 What does this "embedding" stuff mean?

ECL is a full fledge implementation of the Common-Lisp language. However, due to the way it is implemented, the implementation can be used as an extensibility language for your own application, much like Guile works for the Scheme language. By a rather simple set of functions, you can parse, compile and execute Common-Lisp forms, and using the Foreign Function Interface (FFI), you can add new functions to Common-Lisp which suit your Domain-Specific Language.

And:

2.2 How do I embed ECL into my application?

You have to use the ECL library, which is called libecl.so, libecl.dyld or ecl.dll, depending on your operating system (Unix, Mac OSX or Windows). The program ecl-config will provide you with the flags you have to pass to the C/C++ compiler and to the linker, using either ecl-config --cflags or ecl-config --ldflags, respectively. Regarding your program, apart from linking against the ECL library, you have to call the proper initialization routine, cl_boot(), so that ECL sets up the appropiate internal structures. After calling this routine, you will be able to run lisp code and create or manipulate lisp data

.

It's not Lisp, but Guile is the GNU cross platform scripting language, and is an interpreter/compiler for Scheme, which is pretty close to Lisp.

You can use GNU Guile , which is a Scheme interpreter specifically designed to be easily embeddable in C/C++ programs.

Try anything that comes up under this search: http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=embedded+lisp

It turns out that a lot of people have wanted to do this.

For something even more embeddable than Guile, there's also Chibi .

(I <3 Guile BTW, so this answer isn't trying to take away from that---it just offers another option.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM