Table of Contents

Class StoredProgram

Namespace
BOOSE
Assembly
BOOSE.dll

A collection class for storing a program of Command objects, extends ArrayList to add a program counter and a flag to indicate that the syntax is ok and the program valid. Adds methods below to process variables and methods and implements flow of control for ifs and loops.

public class StoredProgram : ArrayList, IList, ICollection, IEnumerable, ICloneable, IStoredProgram
Inheritance
StoredProgram
Implements
Inherited Members

Constructors

StoredProgram(ICanvas)

Create a blank program which will output to the provided Canvas object. There are a lot of methods in here and it implements the IStoredProgram interface and extends ArrayList. This makes it easier to extend StoredProgram and reimplement the methods you need.

public StoredProgram(ICanvas canvas)

Parameters

canvas ICanvas

Properties

PC

Program Counter, points at the next command object.

public virtual int PC { get; set; }

Property Value

int

Methods

Add(Command)

Adds Command to a stored program

public virtual int Add(Command C)

Parameters

C Command

Returns

int

index at which member was added

AddMethod(Method)

Add a Method object to the methods table so it can be linked to a call.

public virtual void AddMethod(Method M)

Parameters

M Method

Method Object to add

AddVariable(Evaluation)

Add a variable/evaluation to the Stored Program.

public virtual void AddVariable(Evaluation Variable)

Parameters

Variable Evaluation

Evaluation Object

Commandsleft()

Are there any commands left to execute in the program? i.e. pc (Program Counter) has not yet reached the end of the program

public virtual bool Commandsleft()

Returns

bool

true if commands left to execute, false if the end has been reached

DeleteVariable(string)

If the passed in variable name exists then delete it.

public virtual void DeleteVariable(string varName)

Parameters

varName string

Variable name to delete.

EvaluateExpression(string)

Evaluate the given expression by finding the values of any variables and passing the final evaluated result as a String. Uses the DataTable Class Compute() method which can parse an expression as a string, but it doesn't know about boose variable so they have to be converted to values and the expression assembled with them.

public virtual string EvaluateExpression(string Exp)

Parameters

Exp string

Returns

string

Exceptions

StoredProgramException

Throws StoredProgramException is it cannot be evaluated. Use IsExpression() before calling to prevent this exception being thrown.

EvaluateExpressionWithString(string)

Evaluate an expression with a string. i.e. area + " cm^2"

public virtual string EvaluateExpressionWithString(string expression)

Parameters

expression string

Expression as a String

Returns

string

Resulting string to display.

FindVariable(Evaluation)

Finds the position of a Variable Object in the Variable table.

public virtual int FindVariable(Evaluation Variable)

Parameters

Variable Evaluation

Evaluation Object to find.

Returns

int

Position or -1 if not found

FindVariable(string)

Get a variable's position in the Variable table. The variable is expressed by its string name.

public virtual int FindVariable(string varName)

Parameters

varName string

The string name of the variable.

Returns

int

-1 if not found, otherwise the position.

GetMethod(string)

Get the method object from the StoredProgram's method table from its string name.

public virtual Method GetMethod(string MethodName)

Parameters

MethodName string

String name of method.

Returns

Method

Exceptions

StoredProgramException

Thrown if method does not exist

GetVarValue(string)

Returns a variables value from it string name.

public virtual string GetVarValue(string varName)

Parameters

varName string

Variable name.

Returns

string

String value of variable.

Exceptions

StoredProgramException

If variable is not found.

GetVariable(int)

Return the Variable object at the given index in the Variable table.

public virtual Evaluation GetVariable(int index)

Parameters

index int

Position in Variables table to extract.

Returns

Evaluation

Position of object in Variables Table.

Exceptions

StoredProgramException

Thrown if invalid index is passed.

GetVariable(string)

Get a Variable Object. Evaluation is the base class, it could itself be a subclass of the actual types (int, real boolean etc).

public virtual Evaluation GetVariable(string VarName)

Parameters

VarName string

Returns

Evaluation

Evaluation Object of the found type

Exceptions

StoredProgramException

Throws exception if cannot be found, should check that it is there first.

IsExpression(string)

public virtual bool IsExpression(string expression)

Parameters

expression string

Returns

bool

IsValidProgram()

Returns true if the StoredProgram contains a program with no syntaxErrors. Probably shouldn't try and tun one that does.

public bool IsValidProgram()

Returns

bool

NextCommand()

public virtual object NextCommand()

Returns

object

Pop()

Pop a compound command onto the stack. Used for whiles/if/fors/methods to move the PC.

public virtual ConditionalCommand Pop()

Returns

ConditionalCommand

Exceptions

StoredProgramException

Throws StoredProgramException if it can't pop, which is assumed to be because there is a compound statement without and end.

Push(ConditionalCommand)

Push a compound command onto the stack. Used for whiles/if/fors/methods to move the PC.

public virtual void Push(ConditionalCommand Com)

Parameters

Com ConditionalCommand

Compound Command Object

ResetProgram()

Once a program has finished executing it needs to be reset (Program Counter set to zero)

public virtual void ResetProgram()

Run()

Attempt to execute the program, throws a StoredProgram if it cannot run to completion. It is probably better to not try and run a program that passed an errorlist back from Parser.ParseProgram() but it will try. The parser object should have generated a runnable program before running. Attempts to detect infinite loops by detecting it has gione fround the run loop a lot.

public virtual void Run()

Exceptions

StoredProgramException

SetSyntaxStatus(bool)

Set the syntax status of this program, true = no errors, false = errors. Called by a parser that created the program.

public void SetSyntaxStatus(bool status)

Parameters

status bool

UpdateVariable(string, bool)

Update integer variable value.

public virtual void UpdateVariable(string varName, bool value)

Parameters

varName string

String name of variable.

value bool

New integer value.

UpdateVariable(string, double)

Update real variable value.

public virtual void UpdateVariable(string varName, double value)

Parameters

varName string

String name of variable.

value double

New real value.

UpdateVariable(string, int)

Update an existing variable's integer value if it is found, do nothing if not found.

public virtual void UpdateVariable(string varName, int value)

Parameters

varName string

String name of variable.

value int

Integer value to change the variable to.

VariableExists(string)

Returns true if the variable specified by its name exists.

public virtual bool VariableExists(string varName)

Parameters

varName string

String variable name.

Returns

bool

true if variable has been declared previously.