help-bison
[Top][All Lists]
Advanced

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

Re: Non-unions value type with C++ paraser


From: Akim Demaille
Subject: Re: Non-unions value type with C++ paraser
Date: Tue, 19 Jun 2012 13:54:33 +0200

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!




reply via email to

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