spot/src/tgbaparse/tgbaparse.yy
Alexandre Duret-Lutz cab3be9795 Before this change, all automata would construct their own
dictionaries (map of BDD variables to LTL formulae).  This was
cumbersome, because to multiply two automata we had to build a
common dictionary (the union of the two LTL formula spaces), and
install wrappers to translate each automaton's BDD answers into
the common dictionary.  This translation, that had to be repeated
when several products were nested, was time consuming and was a
hindrance for some optimizations.
In the new scheme, all automata involved in a product must
share the same dictionary.  An empty dictionary should be
constructed by the user and passed to the automaton' constructors
as necessary.
This huge change removes most code than it adds.

* src/Makefile.am (libspot_la_LIBADD): Add misc/libmisc.la.
* src/misc/bddalloc.hh, src/misc/bddalloc.cc: New files.  These
partly replace src/tgba/bddfactory.hh and src/tgba/bddfactory.cc.
* src/misc/Makefile.am: Adjust to build bddalloc.hh and bddalloc.cc.
* src/tgba/bddfactory.hh, src/tgba/bddfactory.cc,
src/tgba/dictunion.hh, src/tgba/dictunion.cc,
src/tgba/tgbabdddict.hh, src/tgba/tgbabdddict.cc,
src/tgba/tgbabddtranslatefactory.hh,
src/tgba/tgbabddtranslatefactory.cc,
src/tgba/tgbatranslateproxy.hh, src/tgba/tgbatranslateproxy.cc:
Delete.
* src/tgba/bdddict.hh, src/tgba/bdddict.cc: New files.  These
replaces tgbabdddict.hh and tgbabdddict.cc, and also part of
bddfactory.hh and bddfactory.cc.
* src/tgba/bddprint.cc, src/tgba/bddprint.hh: Adjust to
use bdd_dict* instead of tgba_bdd_dict&.
* src/tgba/succiterconcrete.cc (succ_iter_concrete::next()):
Get next_to_now from the dictionary.
* src/tgba/tgba.hh (tgba::get_dict): Return a bdd_dict*,
not a const tgba_bdd_dict*.
* src/tgba/tgbabddconcrete.cc, src/tgba/tgbabddconcrete.hh:
Adjust to use the new dictionary, stored in data_.
* src/tgba/tgbabddconcretefactory.cc,
src/tgba/tgbabddconcretefactory.hh: Likewise.  Plus
now_to_next_ is now also stored in the dictionary.
* src/tgba/tgbabddconcreteproduct.cc: Likewise.  Now
that both operand share the same product, there is not
point in using tgba_bdd_translate_factory.
* src/tgba/tgbabddcoredata.cc, src/tgba/tgbabddcoredata.hh:
Store a bdd_dict (taken as constructor argument).
(tgba_bdd_core_data::~tgba_bdd_core_data): Remove.
(tgba_bdd_core_data::translate): Remove.
(tgba_bdd_core_data::next_to_now): Remove (now in dict).
(tgba_bdd_core_data::dict): New pointer.
* src/tgba/tgbabddfactory.hh: (tgba_bdd_factory::get_dict): Remove.
* src/tgba/tgbaexplicit.cc, src/tgba/tgbaexplicit.hh:
Adjust to use the new dictionary.
* src/tgba/tgbaproduct.cc, src/tgba/tgbaproduct.hh: Likewise.  Do
not use tgba_bdd_dict_union and tgba_bdd_translate_proxy anymore.
* src/tgbaalgos/lbtt.cc, src/tgbaalgos/save.cc: Adjust to
use bdd_dict* instead of tgba_bdd_dict&.
* src/tgbaalgos/ltl2tgba.cc, src/tgbaalgos/ltl2tgba.cc: Likewise.
(ltl_to_tgba): Take a dict argument.
* src/tgbaparse/public.hh (tgba_parse): Take a dict argument.
* src/tgbaparse/tgbaparse.yy (tgba_parse): Take a dict argument.
* src/tgbatest/explicit.cc, src/tgbatest/explprod.cc,
src/tgbatest/ltlprod.cc, src/tgbatest/mixprod.cc,
src/tgbatest/readsave.cc, src/tgbatest/spotlbtt.cc,
src/tgbatest/tgbaread.cc, src/tgbatest/tripprod.cc: Instantiate
a dictionary, and pass it to the automata' constructors.
* src/tgbatest/ltl2tgba.cc: Likewise, and remove the -o (defrag)
option.
* iface/gspn/gspn.hh (tgba_gspn::tgba_gspn): Take a bdd_dict argument.
(tgba_gspn::get_dict): Adjust return type.
* iface/gspn/gspn.cc: Do not use bdd_factory, adjust to
use the new dictionary instead.
2003-07-14 21:42:59 +00:00

179 lines
3.5 KiB
Text

%{
#include <string>
#include "public.hh"
%}
%parse-param {spot::tgba_parse_error_list &error_list}
%parse-param {spot::ltl::environment &parse_environment}
%parse-param {spot::tgba_explicit* &result}
%debug
%error-verbose
%union
{
int token;
std::string* str;
std::list<std::pair<bool, spot::ltl::formula*> >* listp;
std::list<spot::ltl::formula*>* list;
}
%{
#include "ltlast/constant.hh"
#include "ltlvisit/destroy.hh"
/* tgbaparse.hh and parsedecl.hh include each other recursively.
We mut ensure that YYSTYPE is declared (by the above %union)
before parsedecl.hh uses it. */
#include "parsedecl.hh"
using namespace spot::ltl;
/* Ugly hack so that Bison use tgbayylex, not yylex.
(%name-prefix doesn't work for the lalr1.cc skeleton
at the time of writing.) */
#define yylex tgbayylex
typedef std::pair<bool, spot::ltl::formula*> pair;
%}
%token <str> STRING
%token <str> IDENT
%type <str> strident
%type <listp> cond_list
%type <list> acc_list
%token ACC_DEF
%%
tgba: accepting_decl lines | lines;
accepting_decl: ACC_DEF acc_decl ';'
/* At least one line. */
lines: line
| lines line
;
line: strident ',' strident ',' cond_list ',' acc_list ';'
{
spot::tgba_explicit::transition* t
= result->create_transition(*$1, *$3);
std::list<pair>::iterator i;
for (i = $5->begin(); i != $5->end(); ++i)
if (i->first)
result->add_neg_condition(t, i->second);
else
result->add_condition(t, i->second);
std::list<formula*>::iterator i2;
for (i2 = $7->begin(); i2 != $7->end(); ++i2)
result->add_accepting_condition(t, *i2);
delete $1;
delete $3;
delete $5;
delete $7;
}
;
strident: STRING | IDENT;
cond_list:
{
$$ = new std::list<pair>;
}
| cond_list strident
{
if (*$2 != "")
{
$1->push_back(pair(false, parse_environment.require(*$2)));
}
delete $2;
$$ = $1;
}
| cond_list '!' strident
{
if (*$3 != "")
{
$1->push_back(pair(true, parse_environment.require(*$3)));
}
delete $3;
$$ = $1;
}
;
acc_list:
{
$$ = new std::list<formula*>;
}
| acc_list strident
{
if (*$2 == "true")
{
$1->push_back(constant::true_instance());
}
else if (*$2 != "" && *$2 != "false")
{
formula* f = parse_environment.require(*$2);
if (! result->has_accepting_condition(f))
{
error_list.push_back(spot::tgba_parse_error(@2,
"undeclared accepting condition"));
destroy(f);
delete $2;
YYERROR;
}
$1->push_back(f);
}
delete $2;
$$ = $1;
}
;
acc_decl:
| acc_decl strident
{
formula* f = parse_environment.require(*$2);
result->declare_accepting_condition(f);
delete $2;
}
;
%%
void
yy::Parser::print_()
{
if (looka_ == STRING || looka_ == IDENT)
YYCDEBUG << " '" << *value.str << "'";
}
void
yy::Parser::error_()
{
error_list.push_back(spot::tgba_parse_error(location, message));
}
namespace spot
{
tgba_explicit*
tgba_parse(const std::string& name,
tgba_parse_error_list& error_list,
bdd_dict* dict,
environment& env,
bool debug)
{
if (tgbayyopen(name))
{
error_list.push_back
(tgba_parse_error(yy::Location(),
std::string("Cannot open file ") + name));
return 0;
}
tgba_explicit* result = new tgba_explicit(dict);
tgbayy::Parser parser(debug, yy::Location(), error_list, env, result);
parser.parse();
tgbayyclose();
return result;
}
}
// Local Variables:
// mode: c++
// End: