views:

330

answers:

5

I know there is one, but it's not easy to implement the way I want.

I would like to know the steps to interpret the lisp language and what functions are essential to be implemented.

A: 

If you have to ask - you can't do it.

Implementing a programming language is a terribly complicated thing, even if you don't have to do it from scratch. And I don't think there will be many supporting tools/libraries for Actionscript. On top of that, LISP is a functional programming language which will require quite an amount of extra trickery in addition to the usual language implementation in order to get a decent performance.

Vilx-
I write complicated applications using as3, but I never implemented a language, that doesn't mean I can't do it.
M28
As I said - it's terribly complicated. If you really want to know, start by studying things like Context-Free grammars and finite state automata. Look up wikipedia pages for Parser and Lexical Analysis, dig around from there until you understand these and related concepts like the back of your hand. And then you might start thinking about implementing your own programming language.
Vilx-
This is wrong on two fronts: the semantics of as3 (from what I have read) are very close to Lisp. Reuse of the built-in structures like functions, garbage-collection, etc, should be nearly trivial. Second, parsing a simple Lisp is not super hard. You can write a s-expression parser with a simple recursive function, transformed if necessary to a tight loop and an externalised stack. No need for a complicated parser or lexer.
Nathan Sanders
A: 

I would recommend reading one of the famous dragon books. It pretty much explains the entire process of parsing, compiling, code generation, optimization etc

Toad
You don't need to do any of those things to write a simple Lisp interpreter. Also, the Dragon Book is awesome, but it doesn't teach you how to write an interpreter. The title is "Principles of *Compiler* Design", after all.
Nathan Sanders
if you compile or interpret, a lot of things are in common. You still need to parse, perhaps even put it in intermediate code (especially if you want any kind of performance (which you want since you are already on a not very performant language (as3)))
Toad
Lisp "parsing" (we usually call it "reading") is wicked easy though.
Pillsy
+6  A: 

First, you learn Lisp, then read LiSP and (given you know ActionScript well enough) you just start. PAIP also has sections about implementing Lisp interpreters and compilers.

To get an idea how it generally can be approached, you can have a look at Write Yourself a Scheme in 48 hours. It uses Haskell as an implementation language, but it would give you an idea.

It surely wouldn't be trivial, but it has been done quite often, and there is much to learn from doing it.

danlei
Well, I suppose the guys voting me down here have NOT read LiSP or tried to write a simple Lisp interpreter. For a minimal Lisp interpreter, you'll need a reader, some way to handle environments, and seven basic primitives. Given that core, it is possible to build the rest in the Lisp itself. Sure, that won't be a full blown CL or Scheme, but it's not rocket science to get something useful implemented. One of the reasons so many dialects exist is the homoiconic, simple and regular syntax. Sure, if you want a compliant CL or Scheme, things get more involved, but that was not the OP's question.
danlei
I don't know as3 but if it's similar enough to javascript in the browser (and I think it is), then the semantics are very similar to Lisp. If that's the case then most of the work is writing a s-expression parser (not hard) and implementing cons cells (also not hard, it's just an object with two fields).
Nathan Sanders
@Nathan In the syntax, it looks like the same, but it is totally OOP.
M28
I don't know much about as3 either, but the books I linked above should cover the topic pretty good. For example, in Chapter 23 of PAIP (Compiling Lisp), the compilation to an intruction set of a virtual stack machine is shown, LiSP covers even compilation to C (if I recall correctly).I agree that, given a modern dynamic language, getting something useable done wouldn't be that hard. (Of course also depends on motivation, skills and what one considers useable)
danlei
(After they show how to implement interpreters, mostly Lisp inside Lisps, but the principles can be transferred to other dynamic languages.)
danlei
+2  A: 

danlei's recommendations are excellent. If you want to learn Lisp, PAIP is a better choice to start with, because it will teach you a lot about Common Lisp and a smallish chunk of Scheme.

However, my recommendation would be to start with The Structure and Interpretation of Computer Programs, which will teach you at least as much about Lisp as PAIP (you won't learn as much about AI, though), has a longer and more complete section on how to write Lisp interpreters, and is an awesome book all around. In addition, it's available in its entirety online. I had to order both PAIP and LiSP by mail.

Pillsy
I agree, SICP should be mentioned. Both PAIP and SICP are enlightening reads (I didn't work through them completely, but still), not only as far as Lisp is concerned, but programming in general.
danlei
+1  A: 

Check out the 'Essentials of Programming Languages' book (also known as EoPL).

Mr.Cat