This is the watered down framework for a scripting language:
clsInstruction:
Public Enum Instruction
END_SCRIPT = 0
NO_OPCODE
End Enum
Private menumInstruction As Instruction
Public Property Get Instruction() As Instruction
Instruction = menumInstruction
End Property
Public Property Let Instruction(ByVal Instruction As Instruction)
menumInstruction = Instruction
End Property
clsScript:
Private mcolInstructionList As Collection
Private Sub Class_Initialize()
Set mcolInstructionList = New Collection
End Sub
Public Function Add(ByVal Instruction As Instruction) As clsInstruction
Dim objNewMember As clsInstruction
Set objNewMember = New clsInstruction
objNewMember.Instruction = Instruction
mcolInstructionList.Add objNewMember
Set Add = objNewMember
Set objNewMember = Nothing
End Function
Public Property Get Item(ByVal vntIndexKey As Variant) As clsInstruction
Set Item = mcolInstructionList(vntIndexKey)
End Property
Public Property Get Count() As Long
Count = mcolInstructionList.Count
End Property
Public Sub Remove(ByVal vntIndexKey As Variant)
mcolInstructionList.Remove vntIndexKey
End Sub
Public Property Get NewEnum() As IUnknown
Set NewEnum = mcolInstructionList.[_NewEnum]
End Property
Private Sub Class_Terminate()
Set mcolInstructionList = Nothing
End Sub
clsVirtualMachine:
Private mcolScriptList As Collection
Private Sub Class_Initialize()
Set mcolScriptList = New Collection
End Sub
Public Sub Add(ByVal Script As clsScript, ByVal strKey As String)
If (LenB(strKey) = 0) Then
mcolScriptList.Add Script
Else
mcolScriptList.Add Script, strKey
End If
End Sub
Public Sub ExecuteScript(ByVal strKey As String)
Dim Script As clsScript
Dim Instruction As clsInstruction
Dim Counter As Long
Set Script = mcolScriptList.Item(strKey)
Do
Counter = Counter + 1
Set Instruction = Script.Item(Counter)
Select Case Instruction.Instruction
Case NO_OPCODE
'Do Nothing
End Select
Loop While Instruction.Instruction <> END_SCRIPT
End Sub
Public Property Get Item(ByVal vntIndexKey As Variant) As clsInstruction
Set Item = mcolScriptList(vntIndexKey)
End Property
Public Property Get Count() As Long
Count = mcolScriptList.Count
End Property
Public Sub Remove(ByVal vntIndexKey As Variant)
mcolScriptList.Remove vntIndexKey
End Sub
Public Property Get NewEnum() As IUnknown
Set NewEnum = mcolScriptList.[_NewEnum]
End Property
Private Sub Class_Terminate()
Set mcolScriptList = Nothing
End Sub
Example of Use:
Dim Instruction As clsInstruction
Dim Script As clsScript
Dim VirtualMachine As clsVirtualMachine
Set Instruction = New clsInstruction
Instruction.Instruction = NO_OPCODE
Set Script = New clsScript
Script.Add Instruction.Instruction
'OR
Script.Add NO_OPCODE
Script.Add END_SCRIPT
Set VirtualMachine = New clsVirtualMachine
VirtualMachine.Add Script, ObjPtr(Script) 'ObjPtr(x) should always be unique
VirtualMachine.ExecuteScript ObjPtr(Script)