Automatic mass renaming. * src/bin/autfilt.cc, src/bin/common_aoutput.cc, src/bin/common_aoutput.hh, src/bin/common_conv.cc, src/bin/common_conv.hh, src/bin/common_output.hh, src/bin/dstar2tgba.cc, src/bin/ltlcross.cc, src/bin/ltldo.cc, src/bin/randaut.cc, src/dstarparse/dra2ba.cc, src/dstarparse/dstar2tgba.cc, src/dstarparse/dstarparse.yy, src/dstarparse/nra2nba.cc, src/dstarparse/nsa2tgba.cc, src/dstarparse/public.hh, src/graphtest/tgbagraph.cc, src/hoaparse/hoaparse.yy, src/hoaparse/public.hh, src/ltlvisit/contain.hh, src/ltlvisit/exclusive.cc, src/ltlvisit/exclusive.hh, src/priv/accmap.hh, src/taalgos/minimize.cc, src/tgba/fwd.hh, src/tgba/tgba.cc, src/tgba/tgbagraph.cc, src/tgba/tgbagraph.hh, src/tgba/tgbasafracomplement.cc, src/tgba/tgbasafracomplement.hh, src/tgbaalgos/are_isomorphic.cc, src/tgbaalgos/are_isomorphic.hh, src/tgbaalgos/canonicalize.cc, src/tgbaalgos/canonicalize.hh, src/tgbaalgos/cleanacc.cc, src/tgbaalgos/cleanacc.hh, src/tgbaalgos/complete.cc, src/tgbaalgos/complete.hh, src/tgbaalgos/compsusp.cc, src/tgbaalgos/compsusp.hh, src/tgbaalgos/cycles.hh, src/tgbaalgos/degen.cc, src/tgbaalgos/degen.hh, src/tgbaalgos/dotty.cc, src/tgbaalgos/dtbasat.cc, src/tgbaalgos/dtbasat.hh, src/tgbaalgos/dtgbacomp.cc, src/tgbaalgos/dtgbacomp.hh, src/tgbaalgos/dtgbasat.cc, src/tgbaalgos/dtgbasat.hh, src/tgbaalgos/dupexp.cc, src/tgbaalgos/dupexp.hh, src/tgbaalgos/emptiness.cc, src/tgbaalgos/emptiness.hh, src/tgbaalgos/hoa.cc, src/tgbaalgos/isdet.cc, src/tgbaalgos/isdet.hh, src/tgbaalgos/lbtt.cc, src/tgbaalgos/ltl2tgba_fm.cc, src/tgbaalgos/ltl2tgba_fm.hh, src/tgbaalgos/mask.cc, src/tgbaalgos/mask.hh, src/tgbaalgos/minimize.cc, src/tgbaalgos/minimize.hh, src/tgbaalgos/neverclaim.cc, src/tgbaalgos/postproc.cc, src/tgbaalgos/postproc.hh, src/tgbaalgos/powerset.cc, src/tgbaalgos/powerset.hh, src/tgbaalgos/product.cc, src/tgbaalgos/product.hh, src/tgbaalgos/randomgraph.cc, src/tgbaalgos/randomgraph.hh, src/tgbaalgos/randomize.cc, src/tgbaalgos/randomize.hh, src/tgbaalgos/relabel.cc, src/tgbaalgos/relabel.hh, src/tgbaalgos/remfin.cc, src/tgbaalgos/remfin.hh, src/tgbaalgos/remprop.cc, src/tgbaalgos/remprop.hh, src/tgbaalgos/safety.cc, src/tgbaalgos/safety.hh, src/tgbaalgos/sbacc.cc, src/tgbaalgos/sbacc.hh, src/tgbaalgos/sccfilter.cc, src/tgbaalgos/sccfilter.hh, src/tgbaalgos/sccinfo.cc, src/tgbaalgos/sccinfo.hh, src/tgbaalgos/simulation.cc, src/tgbaalgos/simulation.hh, src/tgbaalgos/stats.cc, src/tgbaalgos/stats.hh, src/tgbaalgos/stripacc.cc, src/tgbaalgos/stripacc.hh, src/tgbaalgos/stutter.cc, src/tgbaalgos/stutter.hh, src/tgbaalgos/totgba.cc, src/tgbaalgos/totgba.hh, src/tgbaalgos/translate.cc, src/tgbaalgos/translate.hh, src/tgbatest/checkpsl.cc, src/tgbatest/complementation.cc, src/tgbatest/emptchk.cc, src/tgbatest/ltl2tgba.cc, src/tgbatest/randtgba.cc, wrap/python/spot_impl.i, wrap/python/tests/automata-io.ipynb, wrap/python/tests/automata.ipynb, wrap/python/tests/piperead.ipynb, wrap/python/tests/testingaut.ipynb: Rename tgba_digraph as twa_graph.
349 lines
7.7 KiB
Text
349 lines
7.7 KiB
Text
/* -*- coding: utf-8 -*-
|
|
** Copyright (C) 2013, 2014, 2015 Laboratoire de Recherche et
|
|
** Développement de l'Epita (LRDE).
|
|
**
|
|
** This file is part of Spot, a model checking library.
|
|
**
|
|
** Spot is free software; you can redistribute it and/or modify it
|
|
** under the terms of the GNU General Public License as published by
|
|
** the Free Software Foundation; either version 3 of the License, or
|
|
** (at your option) any later version.
|
|
**
|
|
** Spot is distributed in the hope that it will be useful, but WITHOUT
|
|
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
** or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
** License for more details.
|
|
**
|
|
** You should have received a copy of the GNU General Public License
|
|
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
%language "C++"
|
|
%locations
|
|
%defines
|
|
%expect 0 // No shift/reduce
|
|
%name-prefix "dstaryy"
|
|
%debug
|
|
%error-verbose
|
|
%lex-param { spot::dstar_parse_error_list& error_list }
|
|
%define api.location.type "spot::location"
|
|
|
|
%code requires
|
|
{
|
|
#include <string>
|
|
#include <cstring>
|
|
#include "ltlast/constant.hh"
|
|
#include "public.hh"
|
|
|
|
inline namespace dstaryy_support
|
|
{
|
|
typedef std::map<int, bdd> map_t;
|
|
|
|
struct result_
|
|
{
|
|
spot::dstar_aut_ptr d;
|
|
spot::ltl::environment* env;
|
|
std::vector<bdd> guards;
|
|
std::vector<bdd>::const_iterator cur_guard;
|
|
map_t dest_map;
|
|
int cur_state;
|
|
|
|
unsigned state_count = 0;
|
|
unsigned start_state = 0;
|
|
std::vector<std::string> aps;
|
|
|
|
bool state_count_seen:1;
|
|
bool accpair_count_seen:1;
|
|
bool start_state_seen:1;
|
|
bool aps_seen:1;
|
|
|
|
result_():
|
|
state_count_seen(false),
|
|
accpair_count_seen(false),
|
|
start_state_seen(false),
|
|
aps_seen(false)
|
|
{
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
%parse-param {spot::dstar_parse_error_list& error_list}
|
|
%parse-param {result_& result}
|
|
%union
|
|
{
|
|
std::string* str;
|
|
unsigned int num;
|
|
}
|
|
|
|
%code
|
|
{
|
|
#include <sstream>
|
|
/* dstarparse.hh and parsedecl.hh include each other recursively.
|
|
We must ensure that YYSTYPE is declared (by the above %union)
|
|
before parsedecl.hh uses it. */
|
|
#include "parsedecl.hh"
|
|
|
|
static void fill_guards(result_& res);
|
|
}
|
|
|
|
%token DRA "DRA"
|
|
%token DSA "DSA"
|
|
%token V2 "v2"
|
|
%token EXPLICIT "explicit"
|
|
%token ACCPAIRS "Acceptance-Pairs:"
|
|
%token AP "AP:";
|
|
%token START "Start:";
|
|
%token STATES "States:";
|
|
%token STATE "State:";
|
|
%token ACCSIG "Acc-Sig:";
|
|
%token ENDOFHEADER "---";
|
|
%token EOL "new line";
|
|
%token <str> STRING "string";
|
|
%token <num> NUMBER "number";
|
|
|
|
%type <num> sign
|
|
|
|
%destructor { delete $$; } <str>
|
|
%printer {
|
|
if ($$)
|
|
debug_stream() << *$$;
|
|
else
|
|
debug_stream() << "\"\""; } <str>
|
|
%printer { debug_stream() << $$; } <num>
|
|
|
|
%%
|
|
dstar: header ENDOFHEADER eols states
|
|
|
|
eols : EOL | eols EOL
|
|
opt_eols: | opt_eols EOL
|
|
|
|
auttype: DRA { result.d->type = spot::Rabin; }
|
|
| DSA { result.d->type = spot::Streett; }
|
|
|
|
|
|
header: auttype opt_eols V2 opt_eols EXPLICIT opt_eols sizes
|
|
{
|
|
bool err = false;
|
|
if (!result.state_count_seen)
|
|
{
|
|
error(@5, "missing state count");
|
|
err = true;
|
|
}
|
|
if (!result.accpair_count_seen)
|
|
{
|
|
error(@5, "missing acceptance-pair count");
|
|
err = true;
|
|
}
|
|
if (!result.start_state_seen)
|
|
{
|
|
error(@5, "missing start-state number");
|
|
err = true;
|
|
}
|
|
if (!result.aps_seen)
|
|
{
|
|
error(@5, "missing atomic proposition definition");
|
|
err = true;
|
|
}
|
|
if (err)
|
|
{
|
|
result.d->aut = nullptr;
|
|
YYABORT;
|
|
}
|
|
result.d->aut->new_states(result.state_count);;
|
|
result.d->aut->set_init_state(result.start_state);
|
|
fill_guards(result);
|
|
}
|
|
|
|
aps:
|
|
| aps STRING opt_eols
|
|
{
|
|
result.aps.push_back(*$2);
|
|
delete $2;
|
|
}
|
|
|
|
sizes:
|
|
| sizes error eols
|
|
{
|
|
error(@2, "unknown header ignored");
|
|
}
|
|
| sizes ACCPAIRS opt_eols NUMBER opt_eols
|
|
{
|
|
result.d->accpair_count = $4;
|
|
result.accpair_count_seen = true;
|
|
}
|
|
| sizes STATES opt_eols NUMBER opt_eols
|
|
{
|
|
result.state_count = $4;
|
|
result.state_count_seen = true;
|
|
}
|
|
| sizes START opt_eols NUMBER opt_eols
|
|
{
|
|
result.start_state = $4;
|
|
result.start_state_seen = true;
|
|
}
|
|
| sizes AP opt_eols NUMBER opt_eols aps
|
|
{
|
|
int announced = $4;
|
|
int given = result.aps.size();
|
|
if (given != announced)
|
|
{
|
|
std::ostringstream str;
|
|
str << announced << " atomic propositions announced but "
|
|
<< given << " given";
|
|
error(@4 + @6, str.str());
|
|
}
|
|
if (given > 31)
|
|
{
|
|
error(@4 + @6,
|
|
"ltl2star does not support more than 31 atomic propositions");
|
|
}
|
|
result.aps_seen = true;
|
|
}
|
|
|
|
opt_name: | STRING opt_eols
|
|
{
|
|
delete $1;
|
|
}
|
|
|
|
state_id: STATE opt_eols NUMBER opt_eols opt_name
|
|
{
|
|
if (result.cur_guard != result.guards.end())
|
|
error(@1, "not enough transitions for previous state");
|
|
if ($3 >= result.state_count)
|
|
{
|
|
std::ostringstream o;
|
|
if (result.state_count > 0)
|
|
{
|
|
o << "state numbers should be in the range [0.."
|
|
<< result.state_count - 1<< "]";
|
|
}
|
|
else
|
|
{
|
|
o << "no states have been declared";
|
|
}
|
|
error(@3, o.str());
|
|
}
|
|
result.cur_guard = result.guards.begin();
|
|
result.dest_map.clear();
|
|
result.cur_state = $3;
|
|
}
|
|
|
|
sign: '+' { $$ = 0; }
|
|
| '-' { $$ = 1; }
|
|
|
|
// Membership to a pair is represented as (+NUM,-NUM)
|
|
accsigs: opt_eols
|
|
| accsigs sign NUMBER opt_eols
|
|
{
|
|
if ((unsigned) result.cur_state >= result.state_count)
|
|
break;
|
|
assert(result.d->accsets);
|
|
if ($3 < result.d->accpair_count)
|
|
{
|
|
result.d->accsets->at(result.cur_state * 2 + $2).set($3);
|
|
}
|
|
else
|
|
{
|
|
std::ostringstream o;
|
|
if (result.d->accpair_count > 0)
|
|
{
|
|
o << "acceptance pairs should be in the range [0.."
|
|
<< result.d->accpair_count - 1<< "]";
|
|
}
|
|
else
|
|
{
|
|
o << "no acceptance pairs have been declared";
|
|
}
|
|
error(@3, o.str());
|
|
}
|
|
}
|
|
|
|
state_accsig: ACCSIG accsigs
|
|
|
|
transitions:
|
|
| transitions NUMBER opt_eols
|
|
{
|
|
std::pair<map_t::iterator, bool> i =
|
|
result.dest_map.emplace($2, *result.cur_guard);
|
|
if (!i.second)
|
|
i.first->second |= *result.cur_guard;
|
|
++result.cur_guard;
|
|
}
|
|
|
|
states:
|
|
| states state_id state_accsig transitions
|
|
{
|
|
for (map_t::const_iterator i = result.dest_map.begin();
|
|
i != result.dest_map.end(); ++i)
|
|
result.d->aut->new_transition(result.cur_state, i->first, i->second);
|
|
}
|
|
%%
|
|
|
|
static void fill_guards(result_& r)
|
|
{
|
|
spot::bdd_dict_ptr d = r.d->aut->get_dict();
|
|
|
|
size_t nap = r.aps.size();
|
|
int* vars = new int[nap];
|
|
|
|
// Get a BDD variable for each atomic proposition
|
|
for (size_t i = 0; i < nap; ++i)
|
|
{
|
|
const spot::ltl::formula* f = r.env->require(r.aps[i]);
|
|
vars[nap - 1 - i] = d->register_proposition(f, r.d->aut);
|
|
f->destroy();
|
|
}
|
|
|
|
// build the 2^nap possible guards
|
|
r.guards.reserve(1U << nap);
|
|
for (size_t i = 0; i < (1U << nap); ++i)
|
|
r.guards.push_back(bdd_ibuildcube(i, nap, vars));
|
|
|
|
delete[] vars;
|
|
r.cur_guard = r.guards.end();
|
|
|
|
r.d->accsets = spot::make_bitvect_array(r.d->accpair_count,
|
|
2 * r.state_count);
|
|
}
|
|
|
|
void
|
|
dstaryy::parser::error(const location_type& location,
|
|
const std::string& message)
|
|
{
|
|
error_list.emplace_back(location, message);
|
|
}
|
|
|
|
namespace spot
|
|
{
|
|
dstar_aut_ptr
|
|
dstar_parse(const std::string& name,
|
|
dstar_parse_error_list& error_list,
|
|
const bdd_dict_ptr& dict,
|
|
ltl::environment& env,
|
|
bool debug)
|
|
{
|
|
if (dstaryyopen(name))
|
|
{
|
|
error_list.emplace_back(spot::location(),
|
|
std::string("Cannot open file ") + name);
|
|
return 0;
|
|
}
|
|
result_ r;
|
|
r.d = std::make_shared<spot::dstar_aut>();
|
|
r.d->aut = make_twa_graph(dict);
|
|
r.d->accsets = 0;
|
|
r.env = &env;
|
|
dstaryy::parser parser(error_list, r);
|
|
parser.set_debug_level(debug);
|
|
parser.parse();
|
|
dstaryyclose();
|
|
|
|
if (!r.d->aut || !r.d->accsets)
|
|
return nullptr;
|
|
return r.d;
|
|
}
|
|
}
|
|
|
|
// Local Variables:
|
|
// mode: c++
|
|
// End:
|