[comp.lang.c++] Request for help in simulating an interactive system

kerrin@cathedral.cerc.wvu.wvnet.edu (Kerrin Smith) (10/23/90)

I am in the process of developing a constraint management system in G++.  I am 
interested in being able to dynamically load constraints of a form such
as X = Y + Z, where X, Y and Z are variables.  Upon recognizing a variable,
I will create a new "variable" object.  Here is where my problem lies.
I would like to be able to *bind* the variable name, say X, to the newly
created object so that later I can reference it directly simply by using the
name X.

Now, I know that I can store the character string X in the newly created data
structure, however, an exhaustive search through some list would then be 
required for each access.

I could create enough pointers to variables initially and give them names
that I know will occur.  As each variable is created I can point the existing
variable pointer to the appropriate object.  The problem with this is that
I won't know the variable names or how many variables there will be in advance.

The best method I've come up with is to create a hashing function to map
the variable name to the new variable object.  This solution is okay but
it requires a function call for each variable access.  Instead of being able
to say   R = X + Z,   I'll be required to say something like, 
MAP(R) = MAP(X) + MAP(Z).

I know that what I am trying to do is exactly what separates interpreters
from compilers, but it seems as though there must be a more elegant method
to simulating an interactive system.  Any advice or references would be 
greatly appreciated.   

Kerrin Smith
Graduate Student

School: West Virginia University

Work:   Concurrent Engineering Research Center
        Kerrin@cerc.wvu.wvnet.edu

barnes@cadence.com (Tim Barnes) (10/24/90)

In article <935@babcock.cerc.wvu.wvnet.edu>
kerrin@cathedral.cerc.wvu.wvnet.edu (Kerrin Smith) writes: 

> I am in the process of developing a constraint management system in G++.  I am 
> interested in being able to dynamically load constraints of a form such
> as X = Y + Z, where X, Y and Z are variables.  Upon recognizing a variable,
> I will create a new "variable" object.  Here is where my problem lies.
> I would like to be able to *bind* the variable name, say X, to the newly
> created object so that later I can reference it directly simply by using the
> name X.

> I know that what I am trying to do is exactly what separates interpreters
> from compilers, but it seems as though there must be a more elegant method
> to simulating an interactive system.  Any advice or references would be 
> greatly appreciated.   

Why don't you simply embed a small interpreter?  There's been some work
done at MCC where the XLISP (by David Betz) interpreter is embedded in a
C++ program; you might also choose a Scheme system.  Lisp objects blend
very well with an object-oriented implementation, because they "know"
about their type, and potentially about their own behaviour.  This kind
of system would let you use each language as it was intended to be used.

--
   /		   /    Manager, Framework Technology - Cadence Design Systems
 -/-  o		  /__  ___  __	___  ___  ___           555 River Oaks Parkway
 /   / /\  /\	 /  / ___/ /   /  / /__/ /__                San Jose, CA 95134
/__ / /	 \/  \  /__/ /__/ /   /  / /__  ___/ barnes@cadence.com (408) 944 7222