Le 19 juin 2012 à 11:30, Timothy Madden a écrit :

> Hello
> 
> I would like to use std::string as the only semantic value type in my C++ 
> parser.
> 
> Is there a way to do that without redefining YYSTYPE (which the C++ interface 
> says it should not be used) ?

It seems to work though.

$ cat foo.y
%language "C++"
%defines
%code top
{
#include <string>
}

%{
  #define YYSTYPE std::string
  int yylex(YYSTYPE*) { return 0; }
%};

%%
exp: { $$ = "Hello, world!"; std::cerr << $$ << std::endl; }
;
%%
void
yy::parser::error(const location&, const std::string&)
{}

int
main ()
{
  yy::parser p;
  return p.parse();
}
$ /opt/local/bin/bison foo.y && g++-mp-4.7 -Wall foo.tab.cc -o foo
$ ./foo
Hello, world!


_______________________________________________
[email protected] https://lists.gnu.org/mailman/listinfo/help-bison

Reply via email to