Le 27 mai 09 à 10:32, Vincent Zweije a écrit :

In short, I see no problem with this union at all as bison uses it,
semantics-wise, but it is unfortunate that you cannot put your own
classes in there in general.

You will be able to do that in Bison 2.6.  A preview is available at

http://www.lrde.epita.fr/~akim/download/bison-2.4.266-4ff3b.tar.bz2

Using that version, you can use actual objects (not pointers to), as in the attached sample file.

%token <::std::string> TEXT;
%token <int> NUMBER;
%printer { debug_stream () << $$; }
   <int> <::std::string> <::std::list<std::string>>;
%token END_OF_FILE 0;

%type <::std::string> item;
%type <::std::list<std::string>> list;

%%

result:
  list  { std::cout << $1 << std::endl; }
;

list:
  /* nothing */ { /* Generates an empty string list */ }
| list item     { std::swap ($$, $1); $$.push_back ($2); }
;

item:
  TEXT          { std::swap ($$, $1); }
| NUMBER        { $$ = string_cast ($1); }
;
%%



Attachment: variant.yy
Description: Binary data


_______________________________________________
help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison

Reply via email to