jmathlib.core.interpreter
Class ContextList

java.lang.Object
  extended by jmathlib.core.interpreter.ContextList

public class ContextList
extends java.lang.Object

Stores a list of contexts. A context is a set of variables pluss some code. When a function is called a new context is added to the list. When the function is removed, the context is destroyed.


Field Summary
private  Context globalContext
           
private  Context localContext
           
 
Constructor Summary
ContextList()
          Create an empty context to act as the global context This constructor must only be called ONCE, because it also creates the GLOBAL context
 
Method Summary
 Context createContext(VariableList _variables)
          Used to create a new context and put it on the stack when executing a function
 Variable createVariable(java.lang.String name)
          create a variable in the local or global workspace
 VariableList getGlobalVariables()
           
 Context getLocalContext()
           
 VariableList getLocalVariables()
           
 Variable getVariable(java.lang.String name)
          this method returns a variable from the workspace.
 boolean isGlobalContext()
           
 Context popContext()
          return to the calling context of the function
 void pushContext(Context context)
           
 void setVariable(java.lang.String name, OperandToken value)
          Set a variable in the local or global workspace.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

localContext

private Context localContext

globalContext

private Context globalContext
Constructor Detail

ContextList

public ContextList()
Create an empty context to act as the global context This constructor must only be called ONCE, because it also creates the GLOBAL context

Method Detail

pushContext

public void pushContext(Context context)
Parameters:
context -

createContext

public Context createContext(VariableList _variables)
Used to create a new context and put it on the stack when executing a function

Parameters:
_variables - = the variable list of the function, null if it's a script file

popContext

public Context popContext()
return to the calling context of the function


getLocalVariables

public VariableList getLocalVariables()
Returns:
the variable list of the current context

getGlobalVariables

public VariableList getGlobalVariables()
Returns:
the variable list of the global context

getVariable

public Variable getVariable(java.lang.String name)
this method returns a variable from the workspace. It also checks if the variable is local or global and returns the value from the correct local or global workspace.

Parameters:
name -
Returns:

createVariable

public Variable createVariable(java.lang.String name)
create a variable in the local or global workspace

Parameters:
-
Returns:

setVariable

public void setVariable(java.lang.String name,
                        OperandToken value)
Set a variable in the local or global workspace. In case the variable is not yet created, create it, too.

Parameters:
-
-

isGlobalContext

public boolean isGlobalContext()
Returns:
true if the current context is the global one

getLocalContext

public Context getLocalContext()
Returns:

FOOTER

BOTTOM