More SIMPL

Tom Kelliher, CS23

May 6, 1996

The Parts of the Language Interpreter

Some Code

I'll quickly fake up a symbol table so that the operators can be tested.

The abstract base class statement:

class Statement
{
 protected:
   int label;

 public:
   Statement(int l) : label(l) {}
   virtual void Perform(void) = 0;
   virtual void Display(void) = 0;
};

Some statement hash table declarations:

typedef Statement* SListP;

struct SListItem
{
   SListItem* next;
   SListP stmt;
};

A small example:

#include <iostream.h>

class abstract
{
 protected:
   int i;

 public:
   abstract(int val) : i(val) {}
   virtual void display(void) = 0;
};

class derived : public abstract
{
 public:
   derived(int val) : abstract(val) {}
   virtual void display(void)
   {
      cout << i << endl;
   }
};

int main()
{
   abstract* p;

   p = new derived(4321);
   p->display();

   return 0;
}

Pseudocode for the Interpreter

Open the program file (command line argument).
Parse statements, creating appropriate class instances and inserting
   into hash table for the program.

pc = 0

while (forever)
   get the statement whose label has value pc.
   if there is such a statement
      ++pc
      execute the statement, passing pc for possible modification.
   else
      ++pc
   end if
end while



Thomas P. Kelliher
Sun May 5 18:40:48 EDT 1996
Tom Kelliher