Table of Contents

Class Interpreter

Namespace
EzrSquared.Runtime
Assembly
ezrSquared-lib.dll

The ezrĀ² Interpreter. The job of the Interpreter is to execute the Abstract Syntax Tree (AST) received from the Parser (as a single Node object)!

public class Interpreter
Inheritance
object
Interpreter

Fields

RuntimeResult

The result of the current execution.

public readonly RuntimeResult RuntimeResult

Field Value

RuntimeResult

Methods

AssignValueToVariable(Reference, IEzrObject, VariableAssignmentNode, Context, Context, AccessMod)

Assigns one of the values to one of the variables defined in the VariableAssignmentNode.

private void AssignValueToVariable(Reference variable, IEzrObject value, VariableAssignmentNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)

Parameters

variable Reference

The variable reference to assign to.

value IEzrObject

The value object to be assigned.

node VariableAssignmentNode

The VariableAssignmentNode being executed.

executionContext Context

The Context in which the variable will be assigned.

callingContext Context

The Context calling on the execution of the Node.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.

AssignValuesToVariables(VariableAssignmentNode, Reference[], bool, Context, Context, AccessMod)

Assigns the value(s) to the variable(s) defined in the VariableAssignmentNode.

private void AssignValuesToVariables(VariableAssignmentNode node, Reference[] variables, bool isSingleVariable, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)

Parameters

node VariableAssignmentNode

The VariableAssignmentNode being executed.

variables Reference[]

The array of variable references to be assigned to.

isSingleVariable bool

Is only one variable being assigned?

executionContext Context

The Context in which the variable will be assigned.

callingContext Context

The Context calling on the execution of the Node.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.

Execute(Node, Context, AccessMod)

Executes an AST under the given Context and returns the result.

public RuntimeResult Execute(Node ast, Context runtimeContext, AccessMod accessibilityModifiers = AccessMod.None)

Parameters

ast Node

The AST, as a single Node object.

runtimeContext Context

The run-time Context in which the AST will be executed.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.

Returns

RuntimeResult

The RuntimeResult object.

ExecuteBinaryOperation(IEzrObject, IEzrObject, Node, TokenType, Context)

Executes a binary operation.

private void ExecuteBinaryOperation(IEzrObject first, IEzrObject second, Node node, TokenType operation, Context executionContext)

Parameters

first IEzrObject

The first value in the operation.

second IEzrObject

The second value in the operation.

node Node

The operation's AST node.

operation TokenType

The operation to perform.

executionContext Context

The context under which the operation will take place.

Exceptions

NotImplementedException

Thrown if a case for the TokenType of the operand was not defined.

ExecuteConjunctiveOperators(BinaryOperationNode, Context, Context, AccessMod)

Executes a boolean conjunctive operation.

private void ExecuteConjunctiveOperators(BinaryOperationNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)

Parameters

node BinaryOperationNode

The operation's AST node.

executionContext Context

The context under which the operation will take place.

callingContext Context

The Context calling on the execution of the Node.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.

ExecuteObjectAttributeAccess(BinaryOperationNode, Context, Context, AccessMod, bool)

Executes an object attribute access operation.

private void ExecuteObjectAttributeAccess(BinaryOperationNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers, bool ignoreUndefinedVariable)

Parameters

node BinaryOperationNode

The operation's AST node.

executionContext Context

The context under which the operation will take place.

callingContext Context

The Context calling on the execution of the Node.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.

ignoreUndefinedVariable bool

Should the interpreter ignore undefined variables?

GetRegisteredReference(Node, Context, Context, AccessMod)

Gets and checks if a node represents a variable reference.

private Reference? GetRegisteredReference(Node node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)

Parameters

node Node

The node to check.

executionContext Context

The Context in which the variable will be assigned.

callingContext Context

The Context calling on the execution of the Node.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.

Returns

Reference

The variable reference. null if any error occurs.

HandleSetStatus(SetStatus, string, Node, Context)

Throws errors for Set(Context?, string, Reference) returns.

private void HandleSetStatus(Context.SetStatus status, string referenceName, Node referenceNode, Context referenceContext)

Parameters

status Context.SetStatus

The set status.

referenceName string

The name of the set reference.

referenceNode Node

The node of the reference object.

referenceContext Context

The context of the reference.

Exceptions

NotImplementedException

Thrown if an unknown set status is encountered.

HandleSetStatus((SetStatus Status, Reference Reference), string, Node, Context)

private Reference HandleSetStatus((Context.SetStatus Status, Reference Reference) setResult, string referenceName, Node referenceNode, Context referenceContext)

Parameters

setResult (Context.SetStatus, Reference)

The set result.

referenceName string

The name of the set reference.

referenceNode Node

The node of the reference object.

referenceContext Context

The context of the reference.

Returns

Reference

The set reference.

IterateLoop(BigInteger?, double?, List<IEzrObject>, CountNode, Context, Context, AccessMod, AccessMod, Reference?, string, Context)

Code to run in an iteration of a count expression.

private int IterateLoop(BigInteger? iBigInteger, double? iDouble, List<IEzrObject> returns, CountNode node, Context callingContext, Context executionContext, AccessMod accessibilityModifiers, AccessMod operationAccessibilityModifiers, Reference? iterationVariableReference, string iterationVariableName, Context iterationVariableRegisteredContext)

Parameters

iBigInteger BigInteger?

The current iteration of the loop as a System.Numerics.BigInteger.

iDouble double?

The current iteration of the loop as a double.

returns List<IEzrObject>

The list of the returns of the loop.

node CountNode

The loop node.

callingContext Context

The Context calling on the execution of the iteration.

executionContext Context

The Context under which the iteration will be executed.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing iteration.

operationAccessibilityModifiers AccessMod

The accessibility modifiers for the iteration variable.

iterationVariableReference Reference

The iteration variable reference.

iterationVariableName string

The name of the iteration variable

iterationVariableRegisteredContext Context

The context under which the iteration variable is registered.

Returns

int

-1 for errors, 1 to skip the iteration, 2 for stopping the loop or 0 for continuation of the loop.

VisitArrayLikeNodeArray(ArrayLikeNode, Context, Context, AccessMod)

Creates an array of objects.

private void VisitArrayLikeNodeArray(ArrayLikeNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)

Parameters

node ArrayLikeNode

The ArrayLikeNode to execute.

executionContext Context

The Context under which the array will be created.

callingContext Context

The Context calling on the execution of the Node.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.

VisitArrayLikeNodeList(ArrayLikeNode, Context, Context, AccessMod)

Creates a list of references to its elements.

private void VisitArrayLikeNodeList(ArrayLikeNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)

Parameters

node ArrayLikeNode

The ArrayLikeNode to execute.

executionContext Context

The Context under which the list will be created.

callingContext Context

The Context calling on the execution of the Node.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.

VisitBinaryOperationNode(BinaryOperationNode, Context, Context, AccessMod, bool)

Executes a BinaryOperationNode and performs a binary operation.

private void VisitBinaryOperationNode(BinaryOperationNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers, bool ignoreUndefinedVariable)

Parameters

node BinaryOperationNode

The BinaryOperationNode to execute.

executionContext Context

The Context under which the operation will be executed.

callingContext Context

The Context calling on the execution of the Node.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.

ignoreUndefinedVariable bool

Should the interpreter ignore undefined variables?

VisitCallNode(CallNode, Context, Context, AccessMod)

private void VisitCallNode(CallNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)

Parameters

node CallNode

The CallNode to execute.

executionContext Context

The Context under which the call takes place.

callingContext Context

The Context calling on the execution of the Node.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.

VisitClassDefinitionNode(ClassDefinitionNode, Context, Context, AccessMod)

Executes a ClassDefinitionNode and creates a class.

private void VisitClassDefinitionNode(ClassDefinitionNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)

Parameters

node ClassDefinitionNode

The ClassDefinitionNode to execute.

executionContext Context

The Context in which the class will be created.

callingContext Context

The Context calling on the execution of the Node.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.

VisitCountNode(CountNode, Context, Context, AccessMod)

Executes a CountNode and creates a counting loop.

private void VisitCountNode(CountNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)

Parameters

node CountNode

The CountNode to execute.

executionContext Context

The Context under which the loop will be executed.

callingContext Context

The Context calling on the execution of the Node.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.

VisitDefineBlockNode(DefineBlockNode, Context, Context, AccessMod)

Executes a DefineBlockNode under its accessibility modifiers in the given Context.

private void VisitDefineBlockNode(DefineBlockNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)

Parameters

node DefineBlockNode

The DefineBlockNode to execute.

executionContext Context

The Context in which the block will be executed.

callingContext Context

The Context calling on the execution of the Node.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.

VisitDictionaryNode(DictionaryNode, Context, Context, AccessMod)

Creates a EzrDictionary object from a DictionaryNode.

private void VisitDictionaryNode(DictionaryNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)

Parameters

node DictionaryNode

The DictionaryNode to execute.

executionContext Context

The Context under which the dictionary will be created.

callingContext Context

The Context calling on the execution of the Node.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.

VisitForEachNode(ForEachNode, Context, Context, AccessMod)

Executes a ForEachNode and creates a for-each loop.

private void VisitForEachNode(ForEachNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)

Parameters

node ForEachNode

The ForEachNode to execute.

executionContext Context

The Context under which the loop will be executed.

callingContext Context

The Context calling on the execution of the Node.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.

VisitFunctionDefinitionNode(FunctionDefinitionNode, Context, Context, AccessMod)

Executes a FunctionDefinitionNode and creates a function.

private void VisitFunctionDefinitionNode(FunctionDefinitionNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)

Parameters

node FunctionDefinitionNode

The FunctionDefinitionNode to execute.

executionContext Context

The Context in which the function will be created.

callingContext Context

The Context calling on the execution of the Node.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.

VisitIfNode(IfNode, Context, Context, AccessMod)

Executes an IfNode and performs a boolean expression.

private void VisitIfNode(IfNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)

Parameters

node IfNode

The IfNode to execute.

executionContext Context

The Context under which the expression will be executed.

callingContext Context

The Context calling on the execution of the Node.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.

VisitNoValueNode(NoValueNode, Context)

Executes a NoValueNode.

private void VisitNoValueNode(NoValueNode node, Context executionContext)

Parameters

node NoValueNode

The NoValueNode to execute.

executionContext Context

The Context under which the node is executed.

Remarks

This is (currently) only used for executing loop skip (calling SetSkipFlag(Reference)) and loop stop (calling SetStopFlag(Reference)) expressions.

Exceptions

NotImplementedException

Thrown when an unimplemented or unexpected ValueType is encountered.

VisitNode(Node, Context, Context?, AccessMod, bool)

Vists a Node and sends it to the appropriate execution function.

internal void VisitNode(Node astNode, Context executionContext, Context? callingContext, AccessMod accessibilityModifiers, bool ignoreUndefinedVariable = false)

Parameters

astNode Node

The Node to execute.

executionContext Context

The Context under which the execution will take place.

callingContext Context

The Context calling on the execution of the Node.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.

ignoreUndefinedVariable bool

Should the interpreter ignore undefined variables?

Exceptions

ArgumentException

Raised if astNode is of type InvalidNode. This should never happen as this means something has gone very wrong in the Parser.

NotImplementedException

Raised if the method for executing astNode has not been implemented.

VisitReturnNode(ReturnNode, Context, Context, AccessMod)

Executes a ReturnNode and sets the return flag in RuntimeResult.

private void VisitReturnNode(ReturnNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)

Parameters

node ReturnNode

The ReturnNode to execute.

executionContext Context

The Context from which the arguments of the ReturnNode will be taken, if any.

callingContext Context

The Context calling on the execution of the Node.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.

VisitStatementsNode(StatementsNode, Context, Context, AccessMod)

Interprets multiple statements.

private void VisitStatementsNode(StatementsNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)

Parameters

node StatementsNode

The StatementsNode to execute.

executionContext Context

The Context under which the statements will be executed.

callingContext Context

The Context calling on the execution of the statements.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from executing the statements.

VisitTryNode(TryNode, Context, Context, AccessMod)

Executes a TryNode and creates a try-catch block.

private void VisitTryNode(TryNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)

Parameters

node TryNode

The TryNode to execute.

executionContext Context

The Context under which the block will be executed.

callingContext Context

The Context calling on the execution of the Node.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.

VisitUnaryOperationNode(UnaryOperationNode, Context, Context, AccessMod)

Executes a UnaryOperationNode and performs a unary operation.

private void VisitUnaryOperationNode(UnaryOperationNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)

Parameters

node UnaryOperationNode

The UnaryOperationNode to execute.

executionContext Context

The Context under which the operation will be executed.

callingContext Context

The Context calling on the execution of the Node.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.

Exceptions

NotImplementedException

Thrown if a case for the TokenType of the operand was not defined.

VisitValueNode(ValueNode, Context)

Creates a "value" type object - i.e. EzrInteger, EzrFloat, EzrString, EzrCharacter and EzrCharacterList, from a ValueNode.

private void VisitValueNode(ValueNode node, Context executionContext)

Parameters

node ValueNode

The ValueNode to execute.

executionContext Context

The Context under which the value will be created.

Exceptions

NotImplementedException

Raised if an unimplemented or unexpected TokenType is encountered in node.

VisitVariableAccessNode(VariableAccessNode, Context, Context, AccessMod, bool)

Executes a VariableAccessNode and access a variable from the given Context.

private void VisitVariableAccessNode(VariableAccessNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers, bool ignoreUndefinedVariable)

Parameters

node VariableAccessNode

The VariableAccessNode to execute.

executionContext Context

The Context from which the variable will be accessed.

callingContext Context

The Context calling on the execution of the Node.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.

ignoreUndefinedVariable bool

Should the interpreter ignore undefined variables?

Exceptions

NotImplementedException

Thrown if a case for the Context.GetStatus of the operation was not defined.

VisitVariableAssignmentNode(VariableAssignmentNode, Context, Context, AccessMod)

Executes a VariableAssignmentNode and sets a variable/constant in the given Context.

private void VisitVariableAssignmentNode(VariableAssignmentNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)

Parameters

node VariableAssignmentNode

The VariableAssignmentNode to execute.

executionContext Context

The Context in which the variable will be assigned.

callingContext Context

The Context calling on the execution of the Node.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.

Remarks

A binary operation may also be executed depending on AssignmentOperator.
In the case a ArrayLikeNode is provided as Variable, multiple variables/constants will be assigned.

VisitWhileNode(WhileNode, Context, Context, AccessMod)

Executes a WhileNode and creates a while (condition = true) loop.

private void VisitWhileNode(WhileNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)

Parameters

node WhileNode

The WhileNode to execute.

executionContext Context

The Context under which the loop will be executed.

callingContext Context

The Context calling on the execution of the Node.

accessibilityModifiers AccessMod

The accessibility modifiers for objects that will be assigned from the executing Node.