The ezr² Project 0.1.1
The codebase for the ezr² programming language.
|
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. | |
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)!
|
private |
Assigns the value(s) to the variable(s) defined in the VariableAssignmentNode.
node | The VariableAssignmentNode being executed. |
variables | The array of variable references to be assigned to. |
isSingleVariable | Is only one variable being assigned? |
executionContext | The Context in which the variable will be assigned. |
callingContext | The Context calling on the execution of the Node. |
accessibilityModifiers | The accessibility modifiers for objects that will be assigned from the executing Node. |
|
private |
Assigns one of the values to one of the variables defined in the VariableAssignmentNode.
variable | The variable reference to assign to. |
value | The value object to be assigned. |
node | The VariableAssignmentNode being executed. |
executionContext | The Context in which the variable will be assigned. |
callingContext | The Context calling on the execution of the Node. |
accessibilityModifiers | The accessibility modifiers for objects that will be assigned from the executing Node. |
|
private |
Creates an array of objects.
node | The ArrayLikeNode to execute. |
executionContext | The Context under which the array will be created. |
callingContext | The Context calling on the execution of the Node. |
accessibilityModifiers | The accessibility modifiers for objects that will be assigned from the executing Node. |
|
private |
Creates a list of references to its elements.
node | The ArrayLikeNode to execute. |
executionContext | The Context under which the list will be created. |
callingContext | The Context calling on the execution of the Node. |
accessibilityModifiers | The accessibility modifiers for objects that will be assigned from the executing Node. |
RuntimeResult EzrSquared.Runtime.Interpreter.Execute | ( | Node | ast, |
Context | runtimeContext, | ||
AccessMod | accessibilityModifiers = AccessMod::None ) |
Executes an AST under the given Context and returns the result.
ast | The AST, as a single Node object. |
runtimeContext | The run-time Context in which the AST will be executed. |
accessibilityModifiers | The accessibility modifiers for objects that will be assigned from the executing Node. |
|
private |
Executes a binary operation.
first | The first value in the operation. |
second | The second value in the operation. |
node | The operation's AST node. |
operation | The operation to perform. |
executionContext | The context under which the operation will take place. |
NotImplementedException | Thrown if a case for the TokenType of the operand was not defined. |
|
private |
Executes a boolean conjunctive operation.
|
private |
Executes an object attribute access operation.
node | The operation's AST node. |
executionContext | The context under which the operation will take place. |
callingContext | The Context calling on the execution of the Node. |
accessibilityModifiers | The accessibility modifiers for objects that will be assigned from the executing Node. |
ignoreUndefinedVariable | Should the interpreter ignore undefined variables? |
|
private |
Throws errors for Context.Set(Context?, ValueTuple<IEzrObject, string>, Reference, AccessMod) returns.
setResult | The set result. |
referenceName | The name of the set reference. |
referenceNode | The node of the reference object. |
referenceContext | The context of the reference. |
|
private |
Throws errors for Context.Set(Context?, string, Reference) returns.
status | The set status. |
referenceName | The name of the set reference. |
referenceNode | The node of the reference object. |
referenceContext | The context of the reference. |
NotImplementedException | Thrown if an unknown set status is encountered. |
|
private |
Code to run in an iteration of a count expression.
iBigInteger | The current iteration of the loop as a BigInteger. |
iDouble | The current iteration of the loop as a double. |
returns | The list of the returns of the loop. |
node | The loop node. |
callingContext | The Context calling on the execution of the iteration. |
executionContext | The Context under which the iteration will be executed. |
accessibilityModifiers | The accessibility modifiers for objects that will be assigned from the executing iteration. |
operationAccessibilityModifiers | The accessibility modifiers for the iteration variable. |
iterationVariableReference | The iteration variable reference. |
iterationVariableName | The name of the iteration variable |
iterationVariableRegisteredContext | The context under which the iteration variable is registered. |
|
private |
Creates an array-like object, see ArrayLikeNode, CreateList(ArrayLikeNode, Context, Context, AccessMod) and CreateArray(ArrayLikeNode, Context, Context, AccessMod) for more information.
node | The ArrayLikeNode to execute. |
executionContext | The Context under which the array-like object will be created. |
callingContext | The Context calling on the execution of the Node. |
accessibilityModifiers | The accessibility modifiers for objects that will be assigned from the executing Node. |
|
private |
Executes a BinaryOperationNode and performs a binary operation.
node | The BinaryOperationNode to execute. |
executionContext | The Context under which the operation will be executed. |
callingContext | The Context calling on the execution of the Node. |
accessibilityModifiers | The accessibility modifiers for objects that will be assigned from the executing Node. |
ignoreUndefinedVariable | Should the interpreter ignore undefined variables? |
|
private |
Executes a CallNode and calls the IEzrObject.Execute(Reference[], Interpreter, RuntimeResult) function in CallNode.Receiver.
|
private |
Executes a ClassDefinitionNode and creates a class.
node | The ClassDefinitionNode to execute. |
executionContext | The Context in which the class will be created. |
callingContext | The Context calling on the execution of the Node. |
accessibilityModifiers | The accessibility modifiers for objects that will be assigned from the executing Node. |
|
private |
Executes a CountNode and creates a counting loop.
|
private |
Executes a DefineBlockNode under its accessibility modifiers in the given Context.
node | The DefineBlockNode to execute. |
executionContext | The Context in which the block will be executed. |
callingContext | The Context calling on the execution of the Node. |
accessibilityModifiers | The accessibility modifiers for objects that will be assigned from the executing Node. |
|
private |
Creates a EzrDictionary object from a DictionaryNode.
node | The DictionaryNode to execute. |
executionContext | The Context under which the dictionary will be created. |
callingContext | The Context calling on the execution of the Node. |
accessibilityModifiers | The accessibility modifiers for objects that will be assigned from the executing Node. |
|
private |
Executes a FunctionDefinitionNode and creates a function.
node | The FunctionDefinitionNode to execute. |
executionContext | The Context in which the function will be created. |
callingContext | The Context calling on the execution of the Node. |
accessibilityModifiers | The accessibility modifiers for objects that will be assigned from the executing Node. |
|
private |
Executes an IfNode and performs a boolean expression.
|
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.
node | The NoValueNode to execute. |
executionContext | The Context under which the node is executed. |
NotImplementedException | Thrown when an unimplemented or unexpected NoValueNode.ValueType is encountered. |
|
private |
Executes a ReturnNode and sets the return flag in RuntimeResult.
node | The ReturnNode to execute. |
executionContext | The Context from which the arguments of the ReturnNode will be taken, if any. |
callingContext | The Context calling on the execution of the Node. |
accessibilityModifiers | The accessibility modifiers for objects that will be assigned from the executing Node. |
|
private |
Executes a TryNode and creates a try-catch block.
|
private |
Executes a UnaryOperationNode and performs a unary operation.
node | The UnaryOperationNode to execute. |
executionContext | The Context under which the operation will be executed. |
callingContext | The Context calling on the execution of the Node. |
accessibilityModifiers | The accessibility modifiers for objects that will be assigned from the executing Node. |
NotImplementedException | Thrown if a case for the TokenType of the operand was not defined. |
|
private |
Creates a "value" type object - i.e. EzrInteger, EzrFloat, EzrString, EzrCharacter and EzrCharacterList, from a ValueNode.
node | The ValueNode to execute. |
executionContext | The Context under which the value will be created. |
NotImplementedException | Raised if an unimplemented or unexpected TokenType is encountered in node . |
|
private |
Executes a VariableAccessNode and access a variable from the given Context.
node | The VariableAccessNode to execute. |
executionContext | The Context from which the variable will be accessed. |
callingContext | The Context calling on the execution of the Node. |
accessibilityModifiers | The accessibility modifiers for objects that will be assigned from the executing Node. |
ignoreUndefinedVariable | Should the interpreter ignore undefined variables? |
NotImplementedException | Thrown if a case for the Context.GetStatus of the operation was not defined. |
|
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.
node | The VariableAssignmentNode to execute. |
executionContext | The Context in which the variable will be assigned. |
callingContext | The Context calling on the execution of the Node. |
accessibilityModifiers | The accessibility modifiers for objects that will be assigned from the executing Node. |
|
private |
Executes a WhileNode and creates a while (condition = true) loop.