Public MustInherit Class InterpChain
  Implements Chain

  Private nextChain As Chain
  Protected stk As Stack
  '------------------------------------------
  Public Sub addtoChain(ByVal c As Chain) Implements Chain.addToChain
    nextChain = c                 'Następny w łańcuchu
  End Sub
  '------------------------------------------
  Public MustOverride Function interpret() As Boolean
  '------------------------------------------
  Public Sub sendToChain(ByVal stk_ As Stack) Implements Chain.sendToChain
    stk = stk_
    If (Not interpret()) Then     'Interpretuj stos
      'W przeciwnym razie przekaż dalej w łańcuchu
      nextChain.sendToChain(stk)
    End If
  End Sub
  '-----------------------------------------
  Protected Sub addArgsToVerb()
    Dim v As ParseObject = CType(stk.pop(), ParseObject)
    Dim verb As ParseVerb = CType(stk.pop(), ParseVerb)
    verb.addArgs(v)
    stk.push(verb)
  End Sub
  '----------------------------------------
  Protected Function topStack(ByVal c1 As Integer, ByVal c2 As Integer) As Boolean
    Dim pobj1, pobj2 As ParseObject
    pobj1 = stk.top
    pobj2 = stk.nextTop
    Try
      Return (pobj1.get_Type() = c1) And (pobj2.get_Type() = c2)
    Catch e As NullReferenceException
      Return False
    End Try
  End Function

  Public Function getChain() As Interp.Chain Implements Interp.Chain.getChain
    Return nextChain
  End Function
End Class
