_SBI: The Small Basic Interpreter_
by Steve Reichenthal and Tom Bennett


Example 1:

(a) 
Sub Execute(Controller As _
    SbiController)


(b)
Property Get OpPrec() As _
    Integer

(c)
Property Let InvokeType(
    Expr As SbiExpr, _
    NewValue As Integer)

(d)
Property Get LineNum() _
    As Integer



Example 2: Timing test 

Sub Main
    T = Timer+10
    While Timer < T
        I = I+1
    Wend
    MsgBox I\10 & _
           " loops per second"
End Sub


Listing One
Sub Main
    ...
End Sub
[Let] var = expr
[Let] obj.prop[(args]) = expr
[Let] obj!index = expr
Set var = expr
Set obj.prop[(args]) = expr
Set obj!index = expr
func [args]
obj.method [args]
Call func[(args)]
Call obj.method[(args)]
If expr Then
    ...
[Else
    ...]
End If
While expr
    ...
Wend
For var = expr To expr _
          [Step expr]
    ...
Next [var]
. ' comment
Listing Two
' push (monadicop pop)
Sub Execute _
  (Controller As SbiController)
  Dim Value As Variant
  Controller.PopValue Value
  Select Case m_OpNum
  Case SbiPosOpNum ' +
    Value = Value + 0
  Case SbiNegOpNum ' -
    Value = -Value
  Case SbiNotOpNum ' Not
    Value = Not Value
  End Select
  Controller.PushValue Value
End Sub

Listing Three
Sub InvokeName(_
    ByVal Obj As Object, _
    Name As String, _
    InvokeType As Integer, _
    Exprs As Collection, _
    Optional Result As Variant)
  Dim N As Integer
  Dim Args() As Variant
  If Not Exprs Is Nothing Then
    ' evaluate all of the exprs
    ' place results in Args
     ReDim Args(1 To _
       Exprs.Count) As Variant
     Dim Expr As SbiExpr
     For Each Expr In Exprs
       Expr.Execute Me
       N = N + 1
       PopValue Args(N)
     Next Expr
   End If
  ' call method/prop by name
   VirtualInvokeByName
     Obj, _
     Name, _
     InvokeType, _
     Args, _
     Result
End Sub

Listing Four
Sub Execute _
  (Controller As SbiController)
  m_FactorOp.Execute Controller
  Dim Value As Variant
  Controller.PopValue Value
  Dim Obj As Object
  Set Obj = Value
  Select Case m_InvokeType
  Case imcInvokeMethod + _
       imcInvokePropertyGet
    Controller.InvokeName _
      Obj, _
      m_Method, _
      m_InvokeType, _
      m_Exprs, _
      Value
    Controller.PushValue Value
  Case Else
    Controller.InvokeName _
      Obj, _
      m_Method, _
      m_InvokeType, _
      m_Exprs
  End Select
End Sub






