tgbaparse: Return a tgba_digraph.

* src/tgbaparse/parsedecl.hh, src/tgbaparse/public.hh,
src/tgbaparse/tgbaparse.yy: Adjust to return a tgba_digraph.
* src/priv/accmap.hh: New file to help creating acceptance
conditions from strings.
* src/priv/Makefile.am: Add accmap.hh
* src/tgba/tgbagraph.hh (tgba_digraph::named_t): New typedef.
* wrap/python/spot.i: Declare that tgba_digraph inherits from tgba.
* src/tgbatest/complementation.cc, src/tgbatest/explpro2.test,
src/tgbatest/explpro3.test, src/tgbatest/explpro4.test,
src/tgbatest/explprod.cc, src/tgbatest/explprod.test,
src/tgbatest/ltl2tgba.cc, src/tgbatest/maskacc.cc,
src/tgbatest/maskacc.test, src/tgbatest/mixprod.cc,
src/tgbatest/powerset.cc, src/tgbatest/randtgba.test,
src/tgbatest/readsave.test, src/tgbatest/tgbaread.cc,
src/tgbatest/tgbaread.test, src/tgbatest/tripprod.cc,
src/tgbatest/tripprod.test: Adjust to the change.
This commit is contained in:
Alexandre Duret-Lutz 2014-06-26 23:07:33 +02:00
parent c0b28dc9c8
commit 4170080c35
24 changed files with 277 additions and 159 deletions

View file

@ -1,5 +1,7 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2003, 2005, 2013 Laboratoire d'Informatique de Paris
// Copyright (C) 2013, 2014 Laboratoire de Recherche et
// Développement de l'Epita.
// Copyright (C) 2003, 2005 Laboratoire d'Informatique de Paris
// 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
// Université Pierre et Marie Curie.
//
@ -37,17 +39,4 @@ namespace spot
}
// Gross kludge to compile yy::Parser in another namespace (tgbayy::)
// but still use yy::Location. The reason is that Bison's C++
// skeleton does not support anything close to %name-prefix at the
// moment. All parser are named yy::Parser which makes it somewhat
// difficult to define multiple parsers.
// namespace tgbayy
// {
// using namespace yy;
// }
// #define yy tgbayy
#endif // SPOT_TGBAPARSE_PARSEDECL_HH

View file

@ -1,6 +1,6 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2009, 2012, 2013 Laboratoire de Recherche et Développement
// de l'Epita.
// Copyright (C) 2009, 2012, 2013, 2014 Laboratoire de Recherche et
// Développement de l'Epita.
// Copyright (C) 2003, 2004, 2005, 2006 Laboratoire
// d'Informatique de Paris 6 (LIP6), département Systèmes Répartis
// Coopératifs (SRC), Université Pierre et Marie Curie.
@ -23,7 +23,7 @@
#ifndef SPOT_TGBAPARSE_PUBLIC_HH
# define SPOT_TGBAPARSE_PUBLIC_HH
# include "tgba/tgbaexplicit.hh"
# include "tgba/tgbagraph.hh"
# include "misc/location.hh"
# include "ltlenv/defaultenv.hh"
# include <string>
@ -46,7 +46,7 @@ namespace spot
struct tgba_parse_error_list {};
#endif
/// \brief Build a spot::tgba_explicit from a text file.
/// \brief Build a spot::tgba_digraph from a text file.
/// \param filename The name of the file to parse.
/// \param error_list A list that will be filled with
/// parse errors that occured during parsing.
@ -66,14 +66,14 @@ namespace spot
///
/// \warning This function is not reentrant.
SPOT_API
tgba_explicit_string* tgba_parse(const std::string& filename,
tgba_parse_error_list& error_list,
bdd_dict* dict,
ltl::environment& env
= ltl::default_environment::instance(),
ltl::environment& envacc
= ltl::default_environment::instance(),
bool debug = false);
tgba_digraph* tgba_parse(const std::string& filename,
tgba_parse_error_list& error_list,
bdd_dict* dict,
ltl::environment& env
= ltl::default_environment::instance(),
ltl::environment& envacc
= ltl::default_environment::instance(),
bool debug = false);
/// \brief Format diagnostics produced by spot::tgba_parse.
/// \param os Where diagnostics should be output.

View file

@ -32,25 +32,29 @@
{
#include <string>
#include "public.hh"
#include "priv/accmap.hh"
#include "tgba/formula2bdd.hh"
/* Cache parsed formulae. Labels on arcs are frequently identical and
it would be a waste of time to parse them to formula* over and
over, and to register all their atomic_propositions in the
bdd_dict. Keep the bdd result around so we can reuse it. */
typedef std::map<std::string, bdd> formula_cache;
typedef std::map<std::string, bdd> formula_cache;
typedef typename spot::tgba_digraph::namer<std::string>::type named_tgba_t;
}
%parse-param {spot::tgba_parse_error_list& error_list}
%parse-param {spot::ltl::environment& parse_environment}
%parse-param {spot::ltl::environment& parse_envacc}
%parse-param {spot::tgba_explicit_string*& result}
%parse-param {spot::acc_mapper& acc_map}
%parse-param {spot::tgba_digraph*& result}
%parse-param {named_tgba_t*& namer}
%parse-param {formula_cache& fcache}
%union
{
int token;
std::string* str;
const spot::ltl::formula* f;
std::list<const spot::ltl::formula*>* list;
bdd* acc;
}
%code
@ -72,28 +76,25 @@ typedef std::pair<bool, spot::ltl::formula*> pair;
%token <str> IDENT
%type <str> strident string
%type <str> condition
%type <list> acc_list
%type <acc> acc_list
%token ACC_DEF
%destructor { delete $$; } <str>
%destructor {
for (std::list<const spot::ltl::formula*>::iterator i = $$->begin();
i != $$->end(); ++i)
(*i)->destroy();
delete $$;
} <list>
%destructor { delete $$; } <acc>
%printer { debug_stream() << *$$; } <str>
%printer { debug_stream() << *$$; } <acc>
%%
tgba: acceptance_decl lines
| acceptance_decl
{ result->add_state("0"); }
{ namer->new_state("0"); }
| lines
|
{ result->add_state("0"); };
{ namer->new_state("0"); };
acceptance_decl: ACC_DEF acc_decl ';'
{ acc_map.commit(); }
/* At least one line. */
lines: line
@ -102,8 +103,7 @@ lines: line
line: strident ',' strident ',' condition ',' acc_list ';'
{
spot::state_explicit_string::transition* t
= result->create_transition(*$1, *$3);
bdd cond = bddtrue;
if ($5)
{
formula_cache::const_iterator i = fcache.find(*$5);
@ -113,35 +113,34 @@ line: strident ',' strident ',' condition ',' acc_list ';'
const formula* f =
spot::ltl::parse_boolean(*$5, pel, parse_environment,
debug_level());
for (parse_error_list::iterator i = pel.begin();
i != pel.end(); ++i)
for (auto& j: pel)
{
// Adjust the diagnostic to the current position.
spot::location here = @5;
here.end.line = here.begin.line + i->first.end.line - 1;
here.end.column =
here.begin.column + i->first.end.column;
here.begin.line += i->first.begin.line - 1;
here.begin.column += i->first.begin.column;
error_list.emplace_back(here, i->second);
here.end.line = here.begin.line + j.first.end.line - 1;
here.end.column = here.begin.column + j.first.end.column;
here.begin.line += j.first.begin.line - 1;
here.begin.column += j.first.begin.column;
error_list.emplace_back(here, j.second);
}
if (f)
result->add_condition(t, f);
else
result->add_conditions(t, bddfalse);
fcache[*$5] = t->condition;
{
cond = formula_to_bdd(f, result->get_dict(), result);
f->destroy();
}
fcache[*$5] = cond;
}
else
{
t->condition = i->second;
cond = i->second;
}
delete $5;
}
std::list<const formula*>::iterator i;
for (i = $7->begin(); i != $7->end(); ++i)
result->add_acceptance_condition(t, *i);
unsigned s = namer->new_state(*$1);
unsigned d = namer->new_state(*$3);
namer->graph().new_transition(s, d, cond, *$7);
delete $1;
delete $3;
delete $5;
delete $7;
}
;
@ -167,26 +166,21 @@ condition:
acc_list:
{
$$ = new std::list<const formula*>;
$$ = new bdd(bddfalse);
}
| acc_list strident
{
if (*$2 == "true")
if (*$2 != "" && *$2 != "false")
{
$1->push_back(constant::true_instance());
}
else if (*$2 != "" && *$2 != "false")
{
const formula* f = parse_envacc.require(*$2);
if (! result->has_acceptance_condition(f))
auto p = acc_map.lookup(*$2);
if (! p.first)
{
error_list.emplace_back(@2,
"undeclared acceptance condition `" + *$2 + "'");
f->destroy();
// $2 will be destroyed on error recovery.
YYERROR;
}
$1->push_back(f);
*$1 |= p.second;
}
delete $2;
$$ = $1;
@ -197,18 +191,16 @@ acc_list:
acc_decl:
| acc_decl strident
{
const formula* f = parse_envacc.require(*$2);
if (! f)
if (! acc_map.declare(*$2))
{
std::string s = "acceptance condition `";
s += *$2;
s += "' unknown in environment `";
s += parse_envacc.name();
s += acc_map.get_env().name();
s += "'";
error_list.emplace_back(@2, s);
YYERROR;
}
result->declare_acceptance_condition(f);
delete $2;
}
;
@ -224,7 +216,7 @@ tgbayy::parser::error(const location_type& location,
namespace spot
{
tgba_explicit_string*
tgba_digraph*
tgba_parse(const std::string& name,
tgba_parse_error_list& error_list,
bdd_dict* dict,
@ -239,12 +231,24 @@ namespace spot
return 0;
}
formula_cache fcache;
tgba_explicit_string* result = new tgba_explicit_string(dict);
tgbayy::parser parser(error_list, env, envacc, result, fcache);
tgba_digraph* result = new tgba_digraph(dict);
auto* namer = result->create_namer<std::string>();
spot::acc_mapper acc_map(result, envacc);
tgbayy::parser parser(error_list, env, acc_map, result, namer, fcache);
parser.set_debug_level(debug);
parser.parse();
tgbayyclose();
return result;
if (namer) // No fatal error
{
delete namer;
return result;
}
else // Fatal error
{
delete result;
return nullptr;
}
}
}