A Simple Scripting Language – Part 1 

Part 1 | Part 2 | Part 3 | Part 4 | Part 5

I’ve always been intrigued by computer architecture.  At Ryerson I took a course in compiler design and made my first simple JVM compiler.  At Capybara Games I wrote simple scripting languages for Pirates of the Carribean: At World’s End Mobile and Heroes of Might And Magic: Clash of Heroes .  Before I left the company I designed a cross compiler to convert a subset of Java (J2ME) to C++ ( BREW).

Now I find myself doing it all over again; creating a scripting language for the cut scenes in Trudy’s Mechanicals.

Why would you do that when you could use Python, LUA, V8 or some other embeddable language?

Because its fun!  and you get to control exactly what goes in it.  Here’s the feature list:

  • statically typed and linked
  • no dynamic memory allocation
  • continuation like structures
  • support for 32-bit integers and non-mutable strings
  • multi-pass compilation (no &%^%^ header files)
  • objective-c like calling syntax (I find it a lot more readable)
  • simple loops and conditionals

Of course, this isn’t a complete language, but a domain specific one tailored  to a limited device.

So I imagine you’re going to use a tool like Lex or Yacc right?

Actually, NO.

For complex languages or  large source bases these are very useful,  but I’ve found them to be unnecessary with the speed of modern computers.   I find I can brute force parsing and expression matching without any noticeable performance penalty.  Yes this does mean more initial work setting everything up, but it makes parsing order of operations in arithmetic and the various forms of “if” statements found in C like languages easier to work with.

For more information on other “compiler compilers” see The Lex and Yacc Page.

Perhaps this post series should be named the “Brute Force method to Design a Simple Scripting Language”.

This tutorial will be broken down in the following weeks into the following sections:

- Creating a Buffered Reader with look ahead
- Parsing tokens and comments
- Expressions
- Designing your Virtual Machine
- Outputting Assembly

At the end of this tutorial we will have a simple VM written in portable C, with a static scripting language that supports simple types.

See you next week!

Read Part 2

Posted by Tristan Campbell
@igtristan, programmer at Incubator Games
IncubatorGames Says:

[Post] A Simple Scripting Language – Part 1 – http://www.incubatorgames.com/index.php/

Tweets that mention A Simple Scripting Language – Part 1 | Incubator Games -- Topsy.com Says:

[...] This post was mentioned on Twitter by Tristan Campbell, Incubator Games. Incubator Games said: [Post] A Simple Scripting Language – Part 1 – http://bit.ly/aP7HKP [...]

Leon Says:

Great! I’m really looking forward to the next articles.

I myself am playing around with LUA (well actually more than playing – I’m using it for my current problem) and it’s really nice. But somehow I wished I would really understand what goes on inside that little black box :)

infey Says:

RT @IncubatorGames: [Post] A Simple Scripting Language – Part 1 – http://www.incubatorgames.com/index.php/

justradek Says:

RT @IncubatorGames: [Post] A Simple Scripting Language – Part 1 – http://www.incubatorgames.com/index.php/

James Dunne Says:

Oh boy. I can’t wait for next week!

A Simple Scripting Language – Part 5 | Incubator Games Says:

[...] Part 1 | Part 2 | Part 3 | Part 4 | Part 5 [...]

A Simple Scripting Language – Part 4 | Incubator Games Says:

[...] Part 1 | Part 2 | Part 3 | Part 4 | Part 5 [...]

Introducing FFSSL – Sortof | Radstream.com Says:

[...] A Simple Scripting Language [...]

ken Says:

Nice article. I am starting to work on a little hobby scripting language called FFSSL. These articles will hopefully help me in my implementation. Think my interpreter will be more ‘basic’ than what you describe. Having a VM for FFSSL seems to reduce the simplicity of my little project.

Incubator Games » Blog Archive » A Simple Scripting Language – Part 2 Says:

[…] Part 1 | Part 2 | Part 3 | Part 4 | Part 5 […]

Comment: