Hi.
My long term goal is to write a scripting language similar to lua to
replace php (for my own work). At the moment though, I'd be happy just
implemented an interpreter what acted as a calculator.
I've written a (half finished) MIPS emulator in the past, so I'm
hoping that experience will help me with this.
At the moment, my understanding of how to go about implementing this
is as follows:
(we'll call my new language Omega for now)
i. Write a lexical analyzer to convert to Omega code into a tree
structure that the parser can parse.
2. Write a parser to parse the tree structure into bytecode.
C. Write a virtual machine that can execute the bytecode.
The problem is implementing the virtual machine. From my
understanding, it's a lot like writing an emulator, except you get to
choose what the opcodes are. Am I right here? From what I've read, I'd
prefer to write a register-based interpreter as opposed to a stack
based one, because the register based approach seems more intuitive to
me.
Can anyone give me a few tips on how to go about doing this? I'd like
to start out as simple as possible. I've looked through Lua's and
Parrot's source code, but it's more confusing that helpful at this
point.
Thanks.
[Unless you plan to save the bytecode to a file and reload it later,
it's easier just to interpret the trees. -John]


|