/** \brief Add end marker to bytecode.
      
      \throw nothrow 
  */
  void ParserByteCode::Finalize()
  {
    SToken tok;
    tok.Cmd = cmEND;
    m_vRPN.push_back(tok);
    rpn_type(m_vRPN).swap(m_vRPN);     // shrink bytecode vector to fit

    // Determine the if-then-else jump offsets
    ParserStack<int> stIf, stElse;
    int idx;
    for (int i=0; i<(int)m_vRPN.size(); ++i)
    {
      switch(m_vRPN[i].Cmd)
      {
      case cmIF:
            stIf.push(i);
            break;

      case  cmELSE:
            stElse.push(i);
            idx = stIf.pop();
            m_vRPN[idx].Oprt.offset = i - idx;
            break;
      
      case cmENDIF:
            idx = stElse.pop();
            m_vRPN[idx].Oprt.offset = i - idx;
            break;

      default:
            break;
      }
    }
  }
  /** \brief Add end marker to bytecode.
      
      \throw nothrow 
  */
  void ReversePolishNotation::Finalize()
  {
    SPackedToken tok;
    memset(&tok, 0, sizeof(SPackedToken));
    tok.m_eCode = cmEND;
    m_vRPN.push_back(tok);
    rpn_type(m_vRPN).swap(m_vRPN);

    // Determine the if-then-else jump offsets
    Stack<int> stIf, stElse;
    int idx;
    for (std::size_t i=0; i<m_vRPN.size(); ++i)
    {
      switch(m_vRPN[i].m_eCode)
      {
      case cmIF:
            stIf.push(i);
            break;

      case  cmELSE:
            stElse.push(i);
            idx = stIf.pop();
            m_vRPN[idx].Jmp.offset = i - idx;
            break;
      
      case cmENDIF:
            idx = stElse.pop();
            m_vRPN[idx].Jmp.offset = i - idx;
            break;
      }
    }
  }