miSim

misim.asm
Class Context

java.lang.Object
  |
  +--misim.asm.Expr
        |
        +--misim.asm.Context

public class Context
extends Expr

The context class provides information on the labels and parameters in the current scope of the assembler.


Constructor Summary
Context()
          Construct a root context ready for assembly
Context(Context parent)
          Construct a child context for a given parent
 
Method Summary
 void addLabel(Token aToken, int labelType)
          Add a label to this context
 void addLabel(Token aToken, int labelType, int value)
          Add a label to this context
 int defaultRadix()
          Return the current default radix
 int evaluate(TokenIterator tokens, boolean evalBool)
          Evaluate the numeric expression in a file, beginning at the given token position.
 Label getLabel(Token aToken)
          Return the given label in the smallest possible scope
 Context getParent()
          Return the parent context for this context
 int getProgramCounter()
          Return the current program counter
 int getValue(Token aToken)
          Return the value of the given label in the smallest possible scope
 boolean labelExists(java.lang.String text)
          Test to see if a given label has been defined.
 Context rootContext()
          Return the root context for this context
 void setLocal(Token aToken)
           
 void setProgramCounter(int value)
          Set the current program counter to a valid value
 void setRadix(int newRadix)
          Set the current default radix
 void setValue(Token aToken, int value)
          Set the value of the given label in the smallest possible scope
 void undefineVariables()
          Undefine variables in preparation for the second assembly pass, as their value is not global
 
Methods inherited from class misim.asm.Expr
evaluate, evaluate, evaluateOperation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Context

public Context()
Construct a root context ready for assembly

Context

public Context(Context parent)
Construct a child context for a given parent
Parameters:
parent - The parent context
Method Detail

rootContext

public Context rootContext()
Return the root context for this context
Returns:
The root context

getParent

public Context getParent()
Return the parent context for this context
Returns:
The parent context

getProgramCounter

public int getProgramCounter()
Return the current program counter
Returns:
The current value of the program counter

setProgramCounter

public void setProgramCounter(int value)
Set the current program counter to a valid value
Parameters:
value - The new value for the program counter

defaultRadix

public int defaultRadix()
Return the current default radix
Returns:
The current radix

setRadix

public void setRadix(int newRadix)
Set the current default radix
Parameters:
newRadix - the new current default radix

evaluate

public int evaluate(TokenIterator tokens,
                    boolean evalBool)
             throws EditorException
Evaluate the numeric expression in a file, beginning at the given token position.
Parameters:
tokens - The TokenIterator for the line being assembled
context - The local context for this line
evalBool - True if the expression should evaluate as boolean
Returns:
The integer value of the given expression
Throws:
AssemblerException - if the expression contains an error.

getValue

public int getValue(Token aToken)
             throws EditorException
Return the value of the given label in the smallest possible scope
Parameters:
aToken - The token that referred to this label
Returns:
The numeric value of the label
Throws:
EditorException - If the label does not exist

setValue

public void setValue(Token aToken,
                     int value)
              throws EditorException
Set the value of the given label in the smallest possible scope
Parameters:
aToken - The token that referred to this label
value - The new value for this label
Throws:
EditorException - If the label does not exist

getLabel

public Label getLabel(Token aToken)
               throws EditorException
Return the given label in the smallest possible scope
Parameters:
aToken - The token that referred to this label
Returns:
The specified Label
Throws:
EditorException - If the label does not exist

setLocal

public void setLocal(Token aToken)

addLabel

public void addLabel(Token aToken,
                     int labelType,
                     int value)
              throws EditorException
Add a label to this context
Parameters:
aToken - The token that referred to this label
labelType - The label type
value - The value of the label
Throws:
EditorException - if the label already exists

addLabel

public void addLabel(Token aToken,
                     int labelType)
              throws EditorException
Add a label to this context
Parameters:
aToken - The token that referred to this label
labelType - The label type
Throws:
EditorException - if the label already exists

labelExists

public boolean labelExists(java.lang.String text)
Test to see if a given label has been defined.
Returns:
True if the given label exists

undefineVariables

public void undefineVariables()
Undefine variables in preparation for the second assembly pass, as their value is not global

miSim