Making an interpreter...

Discussion about everything. New games, 3d math, development tips...
Post Reply
AutoDMC
Posts: 104
Joined: Sat Sep 18, 2004 3:44 pm

Making an interpreter...

Post by AutoDMC »

Howdy.

I'm trying to set up a miniature interpreter for a project of mine. No, I don't want to use Lua, it's too complex for my needs. I need something a little more along the lines of BeeBasic, but that's complex too. So is ScriptBASIC.

Here's what I'm aiming for:

The language uses a BASIC like syntax. For example:

ADDWARP TO room2 AT 1, 2, 45
ADDTRIGGER AT 2, 4, 5 TO RUN SCRIPT WayTooManyMonsters
CHANGETEXTURE OF hero TO afraid

It should compile to a bytecode that's really close to Irrlicht code.

The interpreter should be able to load ".ib" files which are uncompiled BASIC source, and ".ibc" files which are bytecode.

The problem I have is trying to make the parser for the BASIC language. I was wondering if anyone here could give me a pointer to a tutorial or a page where someone had made up a SIMPLE scripting language like this and made an interpreter? Thanks.
Murphy
Posts: 290
Joined: Mon Dec 13, 2004 12:06 am
Location: United States
Contact:

Post by Murphy »

If it were me, I'd probably consider a sort of indirect approach.

Specifically, I'd consider using the Boost Python library to bind Irrlicht to Python. Then I'd write the BASIC-like interpreter in Python.

Here's my rationale:
The Boost Python library is a fabulously slick way to bind C++ to Python in an OOP and maintainable way.

Writing an interpreter in Python would be easier than C++. Good string handling, easy memory management, flexible typing... a lot of implementation details are already handled.

You stated a desire for a bytecode form. Instead of actually writing an interpreter, I'd suggest writing a BASIC-to-Python translator. Essentially a little compiler that takes in your BASIC code and produces Python code and uses Python's "compiler" package to generate Python bytecode at runtime. Instead of having to do your own fetch-instruction/interpret-instruction/execute-instruction loop, you would simply be executing Python code.


So it may seem like an indirect route, but it instantly came to me as a way of doing it that would fill your requirements, would be pretty easily maintainable, and would require a minimum of reinventing the wheel. It might be vastly over-building for your needs, but I rarely regret over-building. :)
Post Reply