Creating your own scripting language

Started by
7 comments, last by ldeej 18 years, 7 months ago
I have been thinking for some time now to start a couple of small projects: a small scripting language that would be easy to embed (think Lua, Angelscript, Small), and a language for shading (think HLSL, CG, but at a higher level) The excersice would be mainly academic, and the goal would be to learn more about language processors and compilers (given that I never took a compiler class in school) So I am looking for some references, and some suggestions, on how to build an interpreter. Some of the resources I am aware of so far: Game Scripting Mastery (Not sure if this book is good, I have seen very bad and inaccurate books from the same publisher) Engineering a Compiler (Took a look at it on Borders and looked very interesting) Writing Compilers and Interpreters Constructing Language Processors for little languages Programming Language Processors in Java: Compilers and Interpreters I was wondering if anybody had feedback about the resources above (or other resources), and had any suggestions for material on how to write a small compiler or interpreter. I would prefer a hands-on approach, and I am mostly interested on techniques used on popular languages such as python and lua.
Advertisement
I have "Writing Compilers and Interpreters" and "A Retargetable C Compiler: Design and Implementation"(one you didn't mention but that I've often seen put into the same category as those you did list) and I have to say both are absolutely TERRIBLE books for learning how to make a scripting language (or even any kind of compiler or interpreter than the one they tell you how to make). The problem is they say things like "Ok we need a symbol table so here is the code for ours:" and have a huge listing of code without really explaining any of the concepts or ideas behind them.
Really, I think all of the books you listed are like that except for Game Scripting Mastery just based on what I've heard, but I can't say if the many good things I've heard about GSM are valid or not.

Personally, I'd suggest the 'red dragon book ' - Compilers: Principles, Techniques, and Tools because it does exactly the opposite of what I mentioned about. It tells you what you need to do, why, and how to acomplish that task without pulling in tons of irrelevant code that applies only to a single specific situation. After reading both the books I mentioned in the first paragraph and every tutorial I could find, it was the red dragon book that actually taught me something.

The only problem with the book is that it is dated somewhat, but the parts I needed to make a scripting language worked fine. The only parts I kind of skipped over were the ones that detail how a computer can generate a compiler (like the lex and yacc programs do). I've recently looked over various books at amazon, and there seem to be some more modern books that cover the subject just as well as the red dragon book, but I haven't read them so I can't comment.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
Compiler Construction - Principles & Practices. Pain in the ass to read, very useful to have.
"I must not fear. Fear is the mindkiller. Fear is the little death that brings total obliteration. I will face my fear. I will permit it to pass over me and through me. And when it has gone past me I will turn to see fear's path. Where the fear has gone there will be nothing. Only I will remain." ~Frank Herbert, DuneMy slice of the web
I've read an interesting article here:

http://www.divil.co.uk/net/articles/plugins/scripting.asp

which teaches how to implement CSharp/VB as a scripting language. It take 2 days to me to adapt the code to a scripting language which could interact with my game.

Pros:

- very simple to program
- no need to specify the syntax: use the syntax from VB or C#
- can limit to some functions or lib (with wrappers) or just plain access to the system (for advanced scripts)

Cons:

- Windows only
- Need the .Net framework

Hope this helps!
"Lisp in small pieces" has a very hands-on approach, it shows no less than 11 interpreters and 2 compilers for a lisp-family language, all of them implemented in lisp.

In a way it is more a book about lisp than it is about compilers, but if you don't mind lisp I think it's worth reading. Especially if your language should be a dynamic one like lisp.
Thanks all for responding,

PERECil, thanks for the link, but what I am looking for is to learn about the theory on how to build a scripting language (parser, scanner, interpreter), and not how to use a language as an embedded language. I am already familiar on how to do that. Now that you mentioned C# as a scripting language I believe the DirectX SDK has a good sample on how to do this as well.

I took a look at both:

Language processors in Java
Constructing language processors for little languages

Both look good, and they seem to cover the basics. I can then use a more academic book to lookup more advanced topics I might be interested on.

Any other suggestions for resources? (Websites, articles, etc)
Quote:Original post by Trap
"Lisp in small pieces" has a very hands-on approach, it shows no less than 11 interpreters and 2 compilers for a lisp-family language, all of them implemented in lisp.

In a way it is more a book about lisp than it is about compilers, but if you don't mind lisp I think it's worth reading. Especially if your language should be a dynamic one like lisp.


Lisp is just too much fun and too useful to consider ;-)

++good book++
"It's such a useful tool for living in the city!"
Have you checked the articles on this site? There's an entire section devoted to scripting languages. Also, here is the first part of Jan Niestadt's series on making your own scripting language from scratch:

http://www.flipcode.com/articles/scripting_issue01.shtml

That's probably the best resource you'll find.

GDNet+. It's only $5 a month. You know you want it.

I will look into it. Thanks!

This topic is closed to new replies.

Advertisement