[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Writing a simple embedded interpretter

>I'm currently porting/rewriting an adventure game(see BASS in .sig) to
>linux and as most of the original code was asm I decided to rewrite the
>darned thing in C++ for max portability. Anyway, I need to write some sort
>of interpretter to handle the game script, albeit I have never written
>anything like this before, anyone got some suggestions on writing an
>interpetter that allows me to use C++ functions in a manner such as
>                        SETBG INTRO1.PNG
>etc, etc...if anyone catched my drift...

Flex and Bison. They'll do the syntactic analysis for you. You can then produce
something simple to interpret the results. I'd go for a stack based system. So
you'd have opcodes for things like "here comes a string" followed by the byte
count then the string - that routine stores a pointer to the string on the stack
- and then the opcode for "playwav" which uses the data on the stack. Runtime
interpreter is basically a set of routines that are called by pointer based on
the numerical opcode and then fiddle with the program counter and the stack.
Easy to do and easy to bugfix. The Flex code should also be fairly easy to use,
and converts an infix to a pre-fix notation for the program. Basically how Java
works (although its opcodes are more primitive than playing wav files.)