bison-patches
[Top][All Lists]
Advanced

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

Re: proposal: simplify prologue alternatives into %code


From: Hans Aberg
Subject: Re: proposal: simplify prologue alternatives into %code
Date: Tue, 9 Jan 2007 14:28:13 +0100

On 9 Jan 2007, at 12:21, Paolo Bonzini wrote:

I agree in that. Though important to get a nice syntax, getting the other stuff together is more important. :-) In order to get the C++ class polymorphy working with the Bison static type system, would need an additional feature, and I am not sure exactly how it relates to %define and %code, though some additional macro is needed:

You can set up the skeleton like this:

%define "cast" "dynamic_cast"
%define "cast" "static_cast"
%define "cast" "" (or default) -> union

Or perhaps a Bison command %cast, like:

%cast(type, variable) {dynamic_cast<type>(*(variable).data())}

Then a special directive %typed triggering the Bison type system may not be required, as this if %cast appears, one knows the .y file is typed. Another way would that %cast can appear, but is not used, unless a %typed also appears. This way, one can put in in, just case.

The implementation of %typed would be the same as %union, only that the semantic type isn't defined to anything. I think it would only trigger a flag in Bison, saying that typing is used.

This would provide for different solutions.

In the C++ class polymorphy variations, I had to write something like
  dynamic_cast<type>(*$k.data())
  static_cast<type>(*$k.data())

... if you are ok with

dynamic_cast<type>(*$k)

that is, instead of

struct container {
  top_class *member;
  top_class *data () { return member; }
}

you have to write this:

struct container {
  top_class *member;
  top_class &operator *() { return *member; }
}

So then one can play around with different solutions, and need to rely in any particular syntax.

  Hans Aberg






reply via email to

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