An interesting project...

"Jon Frisby" <>
21 Apr 1998 00:38:16 -0400

          From comp.compilers

Related articles
An interesting project... (Jon Frisby) (1998-04-21)
Re: An interesting project... (Mark Harrison) (1998-04-29)
| List of all articles for this month |

From: "Jon Frisby" <>
Newsgroups: comp.compilers
Date: 21 Apr 1998 00:38:16 -0400
Organization: Pacific Bell Internet Services
Keywords: interpreter, question

Ok y'all, I have a question and I'm looking for people's experience on

I'm developing a script language that has some unique requirements... This
project involves the script language, and two meta languages... There will
be one main script per program that can define variables in a global
namespace, and declare functions also in the global namespace.

The meta data however can also can "snippets" of code... Example:

Interaction "Foo" {
        Occurence: Daily;
        Mood: 1..3;
        Execute: `x = myFunction(me.mood * x);`;

And the main script might look something like:

Globals {
        int x = 0;

Functions {
        void main() {
                # Whatever...

        int myFunction(int y) {
                        return sqroot(y) + 2;

So the question here is how to represent this internally in a reasonably
coherent manner...

I'm doing this in Java, so here is my plan... The internal script engine
would store everything like such:

public class ScriptEngine {
        public static Hashtable globalVars = new Hashtable();
        public static Hashtable globalFunctions = new Hashtable();

The globalVars would have names associated with Variable objects... The
Variable heirarchy would represent the data types, and each class would
store the appropriate type of value...

For the globalFunctions, names could be associated with Function objects
which would look like:

public class Function {
        private Opcode[] ops;

        public Object run(Stack parms) {
                Hashtable localVars = new Hashtable();
                int index = 0;
                # Load the values from the parm stack into the Hashtable,
associating the values with
                # the appropriate names...
                while(index < ops.length) {
                        index =
                return localVars.get("__return");

And the Opcode class would be subclassed to implement each opcode

This way the "snippets" of code could just be (unnamed) functions not in the
global function namespace with no parameters...

Also, the global namespace, and each snippet of code could be serialized to
disk for persistence (that's another thing... global vars need to be
persistent... With sanity checking and multiple backups for recovery...)

Can anyone tell me if this is a good way of doing this? Any suggestions on
a better way to do it?



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.