help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C++ exceptions


From: Hans Aberg
Subject: C++ exceptions
Date: Fri, 23 Jul 2004 19:41:16 +0200

I decided to post this, because it was working on this stuff that caused me
to start using Bison. It turned out that C++ itself was not enough for
effectively implementing it, so eventually I needed to start writing my own
language.

I find C++ exceptions important, because I was able to use them as part of
regular programming, in the implementation of dynamic versions of the C/C++
loop constructs. The idea build on a runtime model where f(x) means that
object c hands over a reference to object f for evaluation, which is
initiated by a double dispatch construction. (So f(x) means that the
objects f and x start communicating.)

Then I made a loop-object by the class CLoop::Object:

class CLoop : public DConstruct
{
public:
  ...
  class Object : public DGeneric
  {
  public:
    Data iter;    // Iteration expression
    ...
    Data generic(Data&);
  };
};

Data CLoop::Object::generic(Data& da)
{
  try {
again:
    for (;;)
      iter(da);
  }
  catch (CBreak::Object& dret) {
    return dret.data(da);
  }
  catch (DContinue&) {
    goto again;
  }

  return new DEmpty;
}

Here, if the data argument of this evaluator throws a DContinue object, the
dynamic effect in the loop is the same as a C/C++ static "continue". And,
similarly, a thrown CBreak::Object causes a dynamic loop break.

Then, further, if I assume that all my object in this runtime model will
throw exceptions for the cases they cannot handle, then this means that the
code cannot be broken. This does not need to mean that the exceptions must
be C++ exceptions -- say OS exceptions like memory faults that bring down
the whole program is perfectly OK.

  Hans Aberg






reply via email to

[Prev in Thread] Current Thread [Next in Thread]