* src/ltlparse/ltlparse.yy (error_list, parse_environment, result):

CVS Bison now supports %parse-param for the C++ skeleton; pass these
variables as arguments to the Parser::Parser constructor instead of
using globals.
(parse): Adjust Parser::Parser call.
This commit is contained in:
Alexandre Duret-Lutz 2003-05-15 08:10:38 +00:00
parent 8e988470b1
commit a92327d30b
2 changed files with 54 additions and 63 deletions

View file

@ -7,6 +7,9 @@ extern spot::ltl::formula* result;
%}
%parse-param {spot::ltl::parse_error_list &error_list}
%parse-param {spot::ltl::environment &parse_environment}
%parse-param {spot::ltl::formula* &result}
%debug
%error-verbose
%union
@ -22,18 +25,6 @@ extern spot::ltl::formula* result;
before parsedecl.hh uses it. */
#include "parsedecl.hh"
using namespace spot::ltl;
// At the time of writing C++ support in Bison is quite
// new and there is still no way to pass error_list to
// the parser. We use a global variable instead.
namespace spot
{
namespace ltl
{
extern parse_error_list* error_list;
extern environment* parse_environment;
}
}
%}
/* Logical operators. */
@ -55,7 +46,7 @@ namespace spot
%token <str> ATOMIC_PROP
/* Constants */
%token CONST_TRUE
%token CONST_TRUE
%token CONST_FALSE
%token END_OF_INPUT
@ -63,24 +54,23 @@ namespace spot
%%
result: ltl_formula END_OF_INPUT
{ result = $$ = $1;
{ result = $$ = $1;
YYACCEPT;
}
| many_errors END_OF_INPUT
{ error_list->push_back(parse_error(@1,
"couldn't parse anything sensible"));
{ error_list.push_back(parse_error(@1,
"couldn't parse anything sensible"));
result = $$ = 0;
YYABORT;
}
| END_OF_INPUT
{ error_list->push_back(parse_error(@1,
"empty input"));
{ error_list.push_back(parse_error(@1, "empty input"));
result = $$ = 0;
YYABORT;
}
many_errors_diagnosed : many_errors
{ error_list->push_back(parse_error(@1,
many_errors_diagnosed : many_errors
{ error_list.push_back(parse_error(@1,
"unexpected input ignored")); }
ltl_formula: subformula
@ -94,21 +84,21 @@ many_errors: error
| many_errors error
subformula: ATOMIC_PROP
{
$$ = parse_environment->require(*$1);
{
$$ = parse_environment.require(*$1);
if (! $$)
{
std::string s = "unknown atomic proposition `";
s += *$1;
s += "' in environment `";
s += parse_environment->name();
s += parse_environment.name();
s += "'";
error_list->push_back(parse_error(@1, s));
delete $1;
error_list.push_back(parse_error(@1, s));
delete $1;
YYERROR;
}
else
delete $1;
delete $1;
}
| CONST_TRUE
{ $$ = new constant(constant::True); }
@ -117,13 +107,13 @@ subformula: ATOMIC_PROP
| PAR_OPEN subformula PAR_CLOSE
{ $$ = $2; }
| PAR_OPEN error PAR_CLOSE
{ error_list->push_back(parse_error(@$,
"treating this parenthetical block as false"));
{ error_list.push_back(parse_error(@$,
"treating this parenthetical block as false"));
$$ = new constant(constant::False);
}
| PAR_OPEN subformula many_errors PAR_CLOSE
{ error_list->push_back(parse_error(@3,
"unexpected input ignored"));
{ error_list.push_back(parse_error(@3,
"unexpected input ignored"));
$$ = $2;
}
| OP_NOT subformula
@ -149,11 +139,11 @@ subformula: ATOMIC_PROP
| OP_X subformula
{ $$ = new unop(unop::X, $2); }
// | subformula many_errors
// { error_list->push_back(parse_error(@2,
// "ignoring these unexpected trailing tokens"));
// { error_list->push_back(parse_error(@2,
// "ignoring these unexpected trailing tokens"));
// $$ = $1;
// }
;
%%
@ -161,37 +151,30 @@ subformula: ATOMIC_PROP
void
yy::Parser::print_()
{
if (looka_ == ATOMIC_PROP)
if (looka_ == ATOMIC_PROP)
YYCDEBUG << " '" << *value.str << "'";
}
void
yy::Parser::error_()
{
error_list->push_back(parse_error(location, message));
error_list.push_back(parse_error(location, message));
}
formula* result = 0;
namespace spot
{
namespace ltl
{
parse_error_list* error_list;
environment* parse_environment;
formula*
parse(const std::string& ltl_string,
parse(const std::string& ltl_string,
parse_error_list& error_list,
environment& env,
bool debug)
{
result = 0;
ltl::error_list = &error_list;
parse_environment = &env;
formula* result = 0;
flex_set_buffer(ltl_string.c_str());
yy::Parser parser(debug, yy::Location());
parser.parse();
yy::Parser parser(debug, yy::Location(), error_list, env, result);
parser.parse();
return result;
}
}