* 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

@ -1,3 +1,11 @@
2003-05-15 Alexandre Duret-Lutz <aduret@src.lip6.fr>
* 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.
2003-05-12 Alexandre Duret-Lutz <aduret@src.lip6.fr> 2003-05-12 Alexandre Duret-Lutz <aduret@src.lip6.fr>
* src/ltlvisit/tostring.cc: Reindent and strip out superfluous * src/ltlvisit/tostring.cc: Reindent and strip out superfluous

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 %debug
%error-verbose %error-verbose
%union %union
@ -22,18 +25,6 @@ extern spot::ltl::formula* result;
before parsedecl.hh uses it. */ before parsedecl.hh uses it. */
#include "parsedecl.hh" #include "parsedecl.hh"
using namespace spot::ltl; 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. */ /* Logical operators. */
@ -67,20 +58,19 @@ result: ltl_formula END_OF_INPUT
YYACCEPT; YYACCEPT;
} }
| many_errors END_OF_INPUT | many_errors END_OF_INPUT
{ error_list->push_back(parse_error(@1, { error_list.push_back(parse_error(@1,
"couldn't parse anything sensible")); "couldn't parse anything sensible"));
result = $$ = 0; result = $$ = 0;
YYABORT; YYABORT;
} }
| END_OF_INPUT | END_OF_INPUT
{ error_list->push_back(parse_error(@1, { error_list.push_back(parse_error(@1, "empty input"));
"empty input"));
result = $$ = 0; result = $$ = 0;
YYABORT; YYABORT;
} }
many_errors_diagnosed : many_errors many_errors_diagnosed : many_errors
{ error_list->push_back(parse_error(@1, { error_list.push_back(parse_error(@1,
"unexpected input ignored")); } "unexpected input ignored")); }
ltl_formula: subformula ltl_formula: subformula
@ -95,15 +85,15 @@ many_errors: error
subformula: ATOMIC_PROP subformula: ATOMIC_PROP
{ {
$$ = parse_environment->require(*$1); $$ = parse_environment.require(*$1);
if (! $$) if (! $$)
{ {
std::string s = "unknown atomic proposition `"; std::string s = "unknown atomic proposition `";
s += *$1; s += *$1;
s += "' in environment `"; s += "' in environment `";
s += parse_environment->name(); s += parse_environment.name();
s += "'"; s += "'";
error_list->push_back(parse_error(@1, s)); error_list.push_back(parse_error(@1, s));
delete $1; delete $1;
YYERROR; YYERROR;
} }
@ -117,12 +107,12 @@ subformula: ATOMIC_PROP
| PAR_OPEN subformula PAR_CLOSE | PAR_OPEN subformula PAR_CLOSE
{ $$ = $2; } { $$ = $2; }
| PAR_OPEN error PAR_CLOSE | PAR_OPEN error PAR_CLOSE
{ error_list->push_back(parse_error(@$, { error_list.push_back(parse_error(@$,
"treating this parenthetical block as false")); "treating this parenthetical block as false"));
$$ = new constant(constant::False); $$ = new constant(constant::False);
} }
| PAR_OPEN subformula many_errors PAR_CLOSE | PAR_OPEN subformula many_errors PAR_CLOSE
{ error_list->push_back(parse_error(@3, { error_list.push_back(parse_error(@3,
"unexpected input ignored")); "unexpected input ignored"));
$$ = $2; $$ = $2;
} }
@ -168,29 +158,22 @@ yy::Parser::print_()
void void
yy::Parser::error_() 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 spot
{ {
namespace ltl namespace ltl
{ {
parse_error_list* error_list;
environment* parse_environment;
formula* formula*
parse(const std::string& ltl_string, parse(const std::string& ltl_string,
parse_error_list& error_list, parse_error_list& error_list,
environment& env, environment& env,
bool debug) bool debug)
{ {
result = 0; formula* result = 0;
ltl::error_list = &error_list;
parse_environment = &env;
flex_set_buffer(ltl_string.c_str()); flex_set_buffer(ltl_string.c_str());
yy::Parser parser(debug, yy::Location()); yy::Parser parser(debug, yy::Location(), error_list, env, result);
parser.parse(); parser.parse();
return result; return result;
} }