The ezr² Project 0.1.1
The codebase for the ezr² programming language.
Loading...
Searching...
No Matches
EzrSquared.Runtime.Interpreter Class Reference

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

Public Member Functions

RuntimeResult Execute (Node ast, Context runtimeContext, AccessMod accessibilityModifiers=AccessMod.None)
 Executes an AST under the given Context and returns the result.
 

Public Attributes

readonly RuntimeResult RuntimeResult = new()
 The result of the current execution.
 

Private Member Functions

void HandleSetStatus (Context.SetStatus status, string referenceName, Node referenceNode, Context referenceContext)
 Throws errors for Context.Set(Context?, string, Reference) returns.
 
Reference HandleSetStatus ((Context.SetStatus Status, Reference Reference) setResult, string referenceName, Node referenceNode, Context referenceContext)
 Throws errors for Context.Set(Context?, ValueTuple<IEzrObject, string>, Reference, AccessMod) returns.
 
void VisitValueNode (ValueNode node, Context executionContext)
 Creates a "value" type object - i.e. EzrInteger, EzrFloat, EzrString, EzrCharacter and EzrCharacterList, from a ValueNode.
 
void VisitArrayLikeNode (ArrayLikeNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)
 Creates an array-like object, see ArrayLikeNode, CreateList(ArrayLikeNode, Context, Context, AccessMod) and CreateArray(ArrayLikeNode, Context, Context, AccessMod) for more information.
 
void CreateList (ArrayLikeNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)
 Creates a list of references to its elements.
 
void CreateArray (ArrayLikeNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)
 Creates an array of objects.
 
void VisitDictionaryNode (DictionaryNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)
 Creates a EzrDictionary object from a DictionaryNode.
 
void VisitVariableAccessNode (VariableAccessNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers, bool ignoreUndefinedVariable)
 Executes a VariableAccessNode and access a variable from the given Context.
 
void VisitVariableAssignmentNode (VariableAssignmentNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)
 Executes a VariableAssignmentNode and sets a variable/constant in the given Context.
 
void AssignValuesToVariables (VariableAssignmentNode node, Reference[] variables, bool isSingleVariable, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)
 Assigns the value(s) to the variable(s) defined in the VariableAssignmentNode.
 
void AssignValueToVariable (Reference variable, IEzrObject value, VariableAssignmentNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)
 Assigns one of the values to one of the variables defined in the VariableAssignmentNode.
 
void VisitDefineBlockNode (DefineBlockNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)
 Executes a DefineBlockNode under its accessibility modifiers in the given Context.
 
void VisitUnaryOperationNode (UnaryOperationNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)
 Executes a UnaryOperationNode and performs a unary operation.
 
void VisitBinaryOperationNode (BinaryOperationNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers, bool ignoreUndefinedVariable)
 Executes a BinaryOperationNode and performs a binary operation.
 
void ExecuteObjectAttributeAccess (BinaryOperationNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers, bool ignoreUndefinedVariable)
 Executes an object attribute access operation.
 
void ExecuteConjunctiveOperators (BinaryOperationNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)
 Executes a boolean conjunctive operation.
 
void ExecuteBinaryOperation (IEzrObject first, IEzrObject second, Node node, TokenType operation, Context executionContext)
 Executes a binary operation.
 
void VisitIfNode (IfNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)
 Executes an IfNode and performs a boolean expression.
 
void VisitCountNode (CountNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)
 Executes a CountNode and creates a counting loop.
 
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)
 Code to run in an iteration of a count expression.
 
void VisitWhileNode (WhileNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)
 Executes a WhileNode and creates a while (condition = true) loop.
 
void VisitTryNode (TryNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)
 Executes a TryNode and creates a try-catch block.
 
void VisitFunctionDefinitionNode (FunctionDefinitionNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)
 Executes a FunctionDefinitionNode and creates a function.
 
void VisitClassDefinitionNode (ClassDefinitionNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)
 Executes a ClassDefinitionNode and creates a class.
 
void VisitCallNode (CallNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)
 Executes a CallNode and calls the IEzrObject.Execute(Reference[], Interpreter, RuntimeResult) function in CallNode.Receiver.
 
void VisitNoValueNode (NoValueNode node, Context executionContext)
 Executes a NoValueNode.
 
void VisitReturnNode (ReturnNode node, Context executionContext, Context callingContext, AccessMod accessibilityModifiers)
 Executes a ReturnNode and sets the return flag in RuntimeResult.
 

Detailed Description

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

Member Function Documentation

◆ AssignValuesToVariables()

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

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

Parameters
nodeThe VariableAssignmentNode being executed.
variablesThe array of variable references to be assigned to.
isSingleVariableIs only one variable being assigned?
executionContextThe Context in which the variable will be assigned.
callingContextThe Context calling on the execution of the Node.
accessibilityModifiersThe accessibility modifiers for objects that will be assigned from the executing Node.

◆ AssignValueToVariable()

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

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

Parameters
variableThe variable reference to assign to.
valueThe value object to be assigned.
nodeThe VariableAssignmentNode being executed.
executionContextThe Context in which the variable will be assigned.
callingContextThe Context calling on the execution of the Node.
accessibilityModifiersThe accessibility modifiers for objects that will be assigned from the executing Node.

◆ CreateArray()

void EzrSquared.Runtime.Interpreter.CreateArray ( ArrayLikeNode node,
Context executionContext,
Context callingContext,
AccessMod accessibilityModifiers )
private

Creates an array of objects.

Parameters
nodeThe ArrayLikeNode to execute.
executionContextThe Context under which the array will be created.
callingContextThe Context calling on the execution of the Node.
accessibilityModifiersThe accessibility modifiers for objects that will be assigned from the executing Node.

◆ CreateList()

void EzrSquared.Runtime.Interpreter.CreateList ( ArrayLikeNode node,
Context executionContext,
Context callingContext,
AccessMod accessibilityModifiers )
private

Creates a list of references to its elements.

Parameters
nodeThe ArrayLikeNode to execute.
executionContextThe Context under which the list will be created.
callingContextThe Context calling on the execution of the Node.
accessibilityModifiersThe accessibility modifiers for objects that will be assigned from the executing Node.

◆ Execute()

RuntimeResult EzrSquared.Runtime.Interpreter.Execute ( Node ast,
Context runtimeContext,
AccessMod accessibilityModifiers = AccessMod::None )

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

Parameters
astThe AST, as a single Node object.
runtimeContextThe run-time Context in which the AST will be executed.
accessibilityModifiersThe accessibility modifiers for objects that will be assigned from the executing Node.
Returns
The Runtime.RuntimeResult object.

◆ ExecuteBinaryOperation()

void EzrSquared.Runtime.Interpreter.ExecuteBinaryOperation ( IEzrObject first,
IEzrObject second,
Node node,
TokenType operation,
Context executionContext )
private

Executes a binary operation.

Parameters
firstThe first value in the operation.
secondThe second value in the operation.
nodeThe operation's AST node.
operationThe operation to perform.
executionContextThe context under which the operation will take place.
Exceptions
NotImplementedExceptionThrown if a case for the TokenType of the operand was not defined.

◆ ExecuteConjunctiveOperators()

void EzrSquared.Runtime.Interpreter.ExecuteConjunctiveOperators ( BinaryOperationNode node,
Context executionContext,
Context callingContext,
AccessMod accessibilityModifiers )
private

Executes a boolean conjunctive operation.

Parameters
nodeThe operation's AST node.
executionContextThe context under which the operation will take place.
callingContextThe Context calling on the execution of the Node.
accessibilityModifiersThe accessibility modifiers for objects that will be assigned from the executing Node.

◆ ExecuteObjectAttributeAccess()

void EzrSquared.Runtime.Interpreter.ExecuteObjectAttributeAccess ( BinaryOperationNode node,
Context executionContext,
Context callingContext,
AccessMod accessibilityModifiers,
bool ignoreUndefinedVariable )
private

Executes an object attribute access operation.

Parameters
nodeThe operation's AST node.
executionContextThe context under which the operation will take place.
callingContextThe Context calling on the execution of the Node.
accessibilityModifiersThe accessibility modifiers for objects that will be assigned from the executing Node.
ignoreUndefinedVariableShould the interpreter ignore undefined variables?

◆ HandleSetStatus() [1/2]

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

Throws errors for Context.Set(Context?, ValueTuple<IEzrObject, string>, Reference, AccessMod) returns.

Parameters
setResultThe set result.
referenceNameThe name of the set reference.
referenceNodeThe node of the reference object.
referenceContextThe context of the reference.
Returns
The set reference.

◆ HandleSetStatus() [2/2]

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

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

Parameters
statusThe set status.
referenceNameThe name of the set reference.
referenceNodeThe node of the reference object.
referenceContextThe context of the reference.
Exceptions
NotImplementedExceptionThrown if an unknown set status is encountered.

◆ IterateLoop()

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

Code to run in an iteration of a count expression.

Parameters
iBigIntegerThe current iteration of the loop as a BigInteger.
iDoubleThe current iteration of the loop as a double.
returnsThe list of the returns of the loop.
nodeThe loop node.
callingContextThe Context calling on the execution of the iteration.
executionContextThe Context under which the iteration will be executed.
accessibilityModifiersThe accessibility modifiers for objects that will be assigned from the executing iteration.
operationAccessibilityModifiersThe accessibility modifiers for the iteration variable.
iterationVariableReferenceThe iteration variable reference.
iterationVariableNameThe name of the iteration variable
iterationVariableRegisteredContextThe context under which the iteration variable is registered.
Returns
-1 for errors, 1 to skip the iteration, 2 for stopping the loop or 0 for continuation of the loop.

◆ VisitArrayLikeNode()

void EzrSquared.Runtime.Interpreter.VisitArrayLikeNode ( ArrayLikeNode node,
Context executionContext,
Context callingContext,
AccessMod accessibilityModifiers )
private

Creates an array-like object, see ArrayLikeNode, CreateList(ArrayLikeNode, Context, Context, AccessMod) and CreateArray(ArrayLikeNode, Context, Context, AccessMod) for more information.

Parameters
nodeThe ArrayLikeNode to execute.
executionContextThe Context under which the array-like object will be created.
callingContextThe Context calling on the execution of the Node.
accessibilityModifiersThe accessibility modifiers for objects that will be assigned from the executing Node.

◆ VisitBinaryOperationNode()

void EzrSquared.Runtime.Interpreter.VisitBinaryOperationNode ( BinaryOperationNode node,
Context executionContext,
Context callingContext,
AccessMod accessibilityModifiers,
bool ignoreUndefinedVariable )
private

Executes a BinaryOperationNode and performs a binary operation.

Parameters
nodeThe BinaryOperationNode to execute.
executionContextThe Context under which the operation will be executed.
callingContextThe Context calling on the execution of the Node.
accessibilityModifiersThe accessibility modifiers for objects that will be assigned from the executing Node.
ignoreUndefinedVariableShould the interpreter ignore undefined variables?

◆ VisitCallNode()

void EzrSquared.Runtime.Interpreter.VisitCallNode ( CallNode node,
Context executionContext,
Context callingContext,
AccessMod accessibilityModifiers )
private

Executes a CallNode and calls the IEzrObject.Execute(Reference[], Interpreter, RuntimeResult) function in CallNode.Receiver.

Parameters
nodeThe CallNode to execute.
executionContextThe Context under which the call takes place.
callingContextThe Context calling on the execution of the Node.
accessibilityModifiersThe accessibility modifiers for objects that will be assigned from the executing Node.

◆ VisitClassDefinitionNode()

void EzrSquared.Runtime.Interpreter.VisitClassDefinitionNode ( ClassDefinitionNode node,
Context executionContext,
Context callingContext,
AccessMod accessibilityModifiers )
private

Executes a ClassDefinitionNode and creates a class.

Parameters
nodeThe ClassDefinitionNode to execute.
executionContextThe Context in which the class will be created.
callingContextThe Context calling on the execution of the Node.
accessibilityModifiersThe accessibility modifiers for objects that will be assigned from the executing Node.

◆ VisitCountNode()

void EzrSquared.Runtime.Interpreter.VisitCountNode ( CountNode node,
Context executionContext,
Context callingContext,
AccessMod accessibilityModifiers )
private

Executes a CountNode and creates a counting loop.

Parameters
nodeThe CountNode to execute.
executionContextThe Context under which the loop will be executed.
callingContextThe Context calling on the execution of the Node.
accessibilityModifiersThe accessibility modifiers for objects that will be assigned from the executing Node.

◆ VisitDefineBlockNode()

void EzrSquared.Runtime.Interpreter.VisitDefineBlockNode ( DefineBlockNode node,
Context executionContext,
Context callingContext,
AccessMod accessibilityModifiers )
private

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

Parameters
nodeThe DefineBlockNode to execute.
executionContextThe Context in which the block will be executed.
callingContextThe Context calling on the execution of the Node.
accessibilityModifiersThe accessibility modifiers for objects that will be assigned from the executing Node.

◆ VisitDictionaryNode()

void EzrSquared.Runtime.Interpreter.VisitDictionaryNode ( DictionaryNode node,
Context executionContext,
Context callingContext,
AccessMod accessibilityModifiers )
private

Creates a EzrDictionary object from a DictionaryNode.

Parameters
nodeThe DictionaryNode to execute.
executionContextThe Context under which the dictionary will be created.
callingContextThe Context calling on the execution of the Node.
accessibilityModifiersThe accessibility modifiers for objects that will be assigned from the executing Node.

◆ VisitFunctionDefinitionNode()

void EzrSquared.Runtime.Interpreter.VisitFunctionDefinitionNode ( FunctionDefinitionNode node,
Context executionContext,
Context callingContext,
AccessMod accessibilityModifiers )
private

Executes a FunctionDefinitionNode and creates a function.

Parameters
nodeThe FunctionDefinitionNode to execute.
executionContextThe Context in which the function will be created.
callingContextThe Context calling on the execution of the Node.
accessibilityModifiersThe accessibility modifiers for objects that will be assigned from the executing Node.

◆ VisitIfNode()

void EzrSquared.Runtime.Interpreter.VisitIfNode ( IfNode node,
Context executionContext,
Context callingContext,
AccessMod accessibilityModifiers )
private

Executes an IfNode and performs a boolean expression.

Parameters
nodeThe IfNode to execute.
executionContextThe Context under which the expression will be executed.
callingContextThe Context calling on the execution of the Node.
accessibilityModifiersThe accessibility modifiers for objects that will be assigned from the executing Node.

◆ VisitNoValueNode()

void EzrSquared.Runtime.Interpreter.VisitNoValueNode ( NoValueNode node,
Context executionContext )
private

Executes a NoValueNode.

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

Parameters
nodeThe NoValueNode to execute.
executionContextThe Context under which the node is executed.
Exceptions
NotImplementedExceptionThrown when an unimplemented or unexpected NoValueNode.ValueType is encountered.

◆ VisitReturnNode()

void EzrSquared.Runtime.Interpreter.VisitReturnNode ( ReturnNode node,
Context executionContext,
Context callingContext,
AccessMod accessibilityModifiers )
private

Executes a ReturnNode and sets the return flag in RuntimeResult.

Parameters
nodeThe ReturnNode to execute.
executionContextThe Context from which the arguments of the ReturnNode will be taken, if any.
callingContextThe Context calling on the execution of the Node.
accessibilityModifiersThe accessibility modifiers for objects that will be assigned from the executing Node.

◆ VisitTryNode()

void EzrSquared.Runtime.Interpreter.VisitTryNode ( TryNode node,
Context executionContext,
Context callingContext,
AccessMod accessibilityModifiers )
private

Executes a TryNode and creates a try-catch block.

Parameters
nodeThe TryNode to execute.
executionContextThe Context under which the block will be executed.
callingContextThe Context calling on the execution of the Node.
accessibilityModifiersThe accessibility modifiers for objects that will be assigned from the executing Node.

◆ VisitUnaryOperationNode()

void EzrSquared.Runtime.Interpreter.VisitUnaryOperationNode ( UnaryOperationNode node,
Context executionContext,
Context callingContext,
AccessMod accessibilityModifiers )
private

Executes a UnaryOperationNode and performs a unary operation.

Parameters
nodeThe UnaryOperationNode to execute.
executionContextThe Context under which the operation will be executed.
callingContextThe Context calling on the execution of the Node.
accessibilityModifiersThe accessibility modifiers for objects that will be assigned from the executing Node.
Exceptions
NotImplementedExceptionThrown if a case for the TokenType of the operand was not defined.

◆ VisitValueNode()

void EzrSquared.Runtime.Interpreter.VisitValueNode ( ValueNode node,
Context executionContext )
private

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

Parameters
nodeThe ValueNode to execute.
executionContextThe Context under which the value will be created.
Exceptions
NotImplementedExceptionRaised if an unimplemented or unexpected TokenType is encountered in node .

◆ VisitVariableAccessNode()

void EzrSquared.Runtime.Interpreter.VisitVariableAccessNode ( VariableAccessNode node,
Context executionContext,
Context callingContext,
AccessMod accessibilityModifiers,
bool ignoreUndefinedVariable )
private

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

Parameters
nodeThe VariableAccessNode to execute.
executionContextThe Context from which the variable will be accessed.
callingContextThe Context calling on the execution of the Node.
accessibilityModifiersThe accessibility modifiers for objects that will be assigned from the executing Node.
ignoreUndefinedVariableShould the interpreter ignore undefined variables?
Exceptions
NotImplementedExceptionThrown if a case for the Context.GetStatus of the operation was not defined.

◆ VisitVariableAssignmentNode()

void EzrSquared.Runtime.Interpreter.VisitVariableAssignmentNode ( VariableAssignmentNode node,
Context executionContext,
Context callingContext,
AccessMod accessibilityModifiers )
private

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

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

Parameters
nodeThe VariableAssignmentNode to execute.
executionContextThe Context in which the variable will be assigned.
callingContextThe Context calling on the execution of the Node.
accessibilityModifiersThe accessibility modifiers for objects that will be assigned from the executing Node.

◆ VisitWhileNode()

void EzrSquared.Runtime.Interpreter.VisitWhileNode ( WhileNode node,
Context executionContext,
Context callingContext,
AccessMod accessibilityModifiers )
private

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

Parameters
nodeThe WhileNode to execute.
executionContextThe Context under which the loop will be executed.
callingContextThe Context calling on the execution of the Node.
accessibilityModifiersThe accessibility modifiers for objects that will be assigned from the executing Node.

The documentation for this class was generated from the following file: