[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: C++ variants in reentrant bison/flex combination
From: |
Hans Åberg |
Subject: |
Re: C++ variants in reentrant bison/flex combination |
Date: |
Mon, 22 Aug 2016 18:15:41 +0200 |
> On 22 Aug 2016, at 11:48, PICHLMEIER Florian <address@hidden> wrote:
> I am trying to modify an existing nonreentrant bison/flex combination to be
> reentrant.
> The parser is built from the C++ skeleton lalr1.cc and the scanner with the
> plain C version of flex.
> The problem I encounter during compilation is the error "YYSTYPE does not
> name type”
There is a C++ calculator example in the Bison distribution that you might
check out. Otherwise, I have the code below, which I think originally comes
from that example:
There, YYSTYPE is defined in a '%code requires’ clause. It also shows how to
use %locations for error messages. And yyrestart() is used in the error
recovery grammar rule.
%skeleton "lalr1.cc" /* -*- C++ -*- */
%require "3.0.4"
%defines
%define api.namespace {my}
%define parser_class_name {my_parser}
%code requires {
#include <string>
...
#define YYSTYPE my::object
class parser;
}
// The parsing context.
%parse-param { parser& driver }
%lex-param { parser& driver }
%locations
%initial-action
{
// Initialize the initial location.
@$.begin.filename = @$.end.filename = &driver.file;
};
%debug
%error-verbose
%code {
#include "driver.hh"
void yyrestart(FILE *input_file);
...
}
%token END 0 "end of file”
...
%%
...
%%
%%
void
my::my_parser::error(const my::my_parser::location_type& l,
const std::string& m)
{
driver.error(l, m);
}