Preliminary support for Event-based GBA.

* src/evtgba/Makefile.am, src/evtgba/evtgba.cc,
src/evtgba/evtgba.hh, src/evtgba/evtgbaiter.hh,
src/evtgba/explicit.cc, src/evtgba/explicit.hh,
src/evtgba/product.cc, src/evtgba/product.hh,
src/evtgba/symbol.cc, src/evtgba/symbol.hh,
src/evtgbaalgos/Makefile.am, src/evtgbaalgos/dotty.cc,
src/evtgbaalgos/dotty.hh, src/evtgbaalgos/reachiter.cc,
src/evtgbaalgos/reachiter.hh, src/evtgbaalgos/save.cc,
src/evtgbaalgos/save.hh, src/evtgbaparse/Makefile.am,
src/evtgbaparse/evtgbaparse.yy, src/evtgbaparse/evtgbascan.ll,
src/evtgbaparse/fmterror.cc, src/evtgbaparse/parsedecl.hh,
src/evtgbaparse/public.hh, src/evtgbatest/Makefile.am,
src/evtgbatest/defs.in, src/evtgbatest/explicit.cc,
src/evtgbatest/explicit.test, src/evtgbatest/product.cc,
src/evtgbatest/product.test, src/evtgbatest/readsave.cc,
src/evtgbatest/readsave.test: New files.
* configure.ac: Create the Makefiles in these new subdirectories.
* src/Makefile.am: Recurse them.
This commit is contained in:
Alexandre Duret-Lutz 2004-10-22 16:22:31 +00:00
parent d9b29a0590
commit 73ff928b6f
38 changed files with 3067 additions and 3 deletions

View file

@ -0,0 +1,6 @@
.deps
.libs
*.lo
*.la
Makefile
Makefile.in

View file

@ -0,0 +1,36 @@
## Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
## département Systèmes Répartis Coopératifs (SRC), Université Pierre
## et Marie Curie.
##
## 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 2 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 Spot; see the file COPYING. If not, write to the Free
## Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
## 02111-1307, USA.
AM_CPPFLAGS = -I$(srcdir)/.. $(BUDDY_CPPFLAGS)
AM_CXXFLAGS = $(WARNING_CXXFLAGS)
evtgbaalgosdir = $(pkgincludedir)/evtgbaalgos
evtgbaalgos_HEADERS = \
dotty.hh \
reachiter.hh \
save.hh
noinst_LTLIBRARIES = libevtgbaalgos.la
libevtgbaalgos_la_SOURCES = \
dotty.cc \
reachiter.cc \
save.cc

93
src/evtgbaalgos/dotty.cc Normal file
View file

@ -0,0 +1,93 @@
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
// 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 2 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 Spot; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
#include <ostream>
#include "evtgba/evtgba.hh"
#include "dotty.hh"
#include "reachiter.hh"
#include "misc/escape.hh"
#include "misc/bareword.hh"
namespace spot
{
namespace
{
class dotty_bfs : public evtgba_reachable_iterator_breadth_first
{
public:
dotty_bfs(const evtgba* a, std::ostream& os)
: evtgba_reachable_iterator_breadth_first(a), os_(os)
{
}
void
start(int n)
{
os_ << "digraph G {" << std::endl;
for (int i = 0; i < n;)
{
++i;
os_ << " \"*" << i
<< "\" [label=\"\", style=invis, height=0]" << std::endl;
os_ << " \"*" << i << "\" -> " << i << std::endl;
}
}
void
end()
{
os_ << "}" << std::endl;
}
void
process_state(const state* s, int n, evtgba_iterator*)
{
os_ << " " << n << " [label="
<< quote_unless_bare_word(automata_->format_state(s))
<< "]" << std::endl;
}
void
process_link(int in, int out, const evtgba_iterator* si)
{
os_ << " " << in << " -> " << out << " [label=\"";
escape_str(os_, automata_->format_label(si->current_label()))
<< "\\n";
escape_str(os_, automata_->format_acceptance_conditions
(si->current_acceptance_conditions()))
<< "\"]" << std::endl;
}
private:
std::ostream& os_;
};
}
std::ostream&
dotty_reachable(std::ostream& os, const evtgba* g)
{
dotty_bfs d(g, os);
d.run();
return os;
}
}

34
src/evtgbaalgos/dotty.hh Normal file
View file

@ -0,0 +1,34 @@
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
// 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 2 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 Spot; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
#ifndef SPOT_EVTGBAALGOS_DOTTY_HH
# define SPOT_EVTGBAALGOS_DOTTY_HH
#include "evtgba/evtgba.hh"
#include <iosfwd>
namespace spot
{
/// \brief Print reachable states in dot format.
std::ostream& dotty_reachable(std::ostream& os, const evtgba* g);
}
#endif // SPOT_EVTGBAALGOS_DOTTY_HH

View file

@ -0,0 +1,160 @@
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
// 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 2 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 Spot; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
#include <cassert>
#include "reachiter.hh"
namespace spot
{
// evtgba_reachable_iterator
//////////////////////////////////////////////////////////////////////
evtgba_reachable_iterator::evtgba_reachable_iterator(const evtgba* a)
: automata_(a)
{
}
evtgba_reachable_iterator::~evtgba_reachable_iterator()
{
seen_map::const_iterator s = seen.begin();
while (s != seen.end())
{
// Advance the iterator before deleting the "key" pointer.
const state* ptr = s->first;
++s;
delete ptr;
}
}
void
evtgba_reachable_iterator::run()
{
int n = 0;
evtgba_iterator* i = automata_->init_iter();
for (i->first(); !i->done(); i->next())
{
const state* dest = i->current_state();
add_state(dest);
seen[dest] = ++n;
}
delete i;
start(n);
const state* t;
while ((t = next_state()))
{
assert(seen.find(t) != seen.end());
int tn = seen[t];
evtgba_iterator* si = automata_->succ_iter(t);
process_state(t, tn, si);
for (si->first(); !si->done(); si->next())
{
const state* current = si->current_state();
seen_map::const_iterator s = seen.find(current);
if (s == seen.end())
{
seen[current] = ++n;
add_state(current);
process_link(tn, n, si);
}
else
{
process_link(tn, s->second, si);
delete current;
}
}
delete si;
}
end();
}
void
evtgba_reachable_iterator::start(int)
{
}
void
evtgba_reachable_iterator::end()
{
}
void
evtgba_reachable_iterator::process_state(const state*, int, evtgba_iterator*)
{
}
void
evtgba_reachable_iterator::process_link(int, int, const evtgba_iterator*)
{
}
// evtgba_reachable_iterator_depth_first
//////////////////////////////////////////////////////////////////////
evtgba_reachable_iterator_depth_first::
evtgba_reachable_iterator_depth_first(const evtgba* a)
: evtgba_reachable_iterator(a)
{
}
void
evtgba_reachable_iterator_depth_first::add_state(const state* s)
{
todo.push(s);
}
const state*
evtgba_reachable_iterator_depth_first::next_state()
{
if (todo.empty())
return 0;
const state* s = todo.top();
todo.pop();
return s;
}
// evtgba_reachable_iterator_breadth_first
//////////////////////////////////////////////////////////////////////
evtgba_reachable_iterator_breadth_first::
evtgba_reachable_iterator_breadth_first(const evtgba* a)
: evtgba_reachable_iterator(a)
{
}
void
evtgba_reachable_iterator_breadth_first::add_state(const state* s)
{
todo.push_back(s);
}
const state*
evtgba_reachable_iterator_breadth_first::next_state()
{
if (todo.empty())
return 0;
const state* s = todo.front();
todo.pop_front();
return s;
}
}

View file

@ -0,0 +1,121 @@
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
// 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 2 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 Spot; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
#ifndef SPOT_EVTGBAALGOS_REACHITER_HH
# define SPOT_EVTGBAALGOS_REACHITER_HH
#include "misc/hash.hh"
#include "evtgba/evtgba.hh"
#include <stack>
#include <deque>
namespace spot
{
/// \brief Iterate over all reachable states of a spot::evtgba.
class evtgba_reachable_iterator
{
public:
evtgba_reachable_iterator(const evtgba* a);
virtual ~evtgba_reachable_iterator();
/// \brief Iterate over all reachable states of a spot::evtgba.
///
/// This is a template method that will call add_state(), next_state(),
/// start(), end(), process_state(), and process_link(), while it
/// iterate over state.
void run();
/// \name Todo list management.
///
/// spot::evtgba_reachable_iterator_depth_first and
/// spot::evtgba_reachable_iterator_breadth_first offer two precanned
/// implementations for these functions.
/// \{
/// \brief Called by run() to register newly discovered states.
virtual void add_state(const state* s) = 0;
/// \brief Called by run() to obtain the
virtual const state* next_state() = 0;
/// \}
/// \brief Called by run() before starting its iteration.
///
/// \param n The number of initial states.
virtual void start(int n);
/// Called by run() once all states have been explored.
virtual void end();
/// Called by run() to process a state.
///
/// \param s The current state.
/// \param n An unique number assigned to \a s.
/// \param si The spot::evtgba_iterator for \a s.
virtual void process_state(const state* s, int n, evtgba_iterator* si);
/// Called by run() to process a transition.
///
/// \param in The source state number.
/// \param out The destination state number.
/// \param si The spot::evtgba_iterator positionned on the current
/// transition.
virtual void process_link(int in, int out, const evtgba_iterator* si);
protected:
const evtgba* automata_; ///< The spot::evtgba to explore.
typedef Sgi::hash_map<const state*, int,
state_ptr_hash, state_ptr_equal> seen_map;
seen_map seen; ///< States already seen.
};
/// \brief An implementation of spot::evtgba_reachable_iterator that browses
/// states depth first.
class evtgba_reachable_iterator_depth_first:
public evtgba_reachable_iterator
{
public:
evtgba_reachable_iterator_depth_first(const evtgba* a);
virtual void add_state(const state* s);
virtual const state* next_state();
protected:
std::stack<const state*> todo; ///< A stack of states yet to explore.
};
/// \brief An implementation of spot::evtgba_reachable_iterator that browses
/// states breadth first.
class evtgba_reachable_iterator_breadth_first:
public evtgba_reachable_iterator
{
public:
evtgba_reachable_iterator_breadth_first(const evtgba* a);
virtual void add_state(const state* s);
virtual const state* next_state();
protected:
std::deque<const state*> todo; ///< A queue of states yet to explore.
};
}
#endif // SPOT_EVTGBAALGOS_REACHITER_HH

98
src/evtgbaalgos/save.cc Normal file
View file

@ -0,0 +1,98 @@
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
// 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 2 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 Spot; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
#include <ostream>
#include "save.hh"
#include "reachiter.hh"
#include "misc/bareword.hh"
namespace spot
{
namespace
{
class save_bfs: public evtgba_reachable_iterator_breadth_first
{
public:
save_bfs(const evtgba* a, std::ostream& os)
: evtgba_reachable_iterator_breadth_first(a), os_(os)
{
}
void
start(int)
{
os_ << "acc =";
output_acc_set(automata_->all_acceptance_conditions());
os_ << ";" << std::endl;
os_ << "init =";
evtgba_iterator* i = automata_->init_iter();
for (i->first(); !i->done(); i->next())
{
const state* s = i->current_state();
os_ << " " << quote_unless_bare_word(automata_->format_state(s));
delete s;
}
os_ << ";" << std::endl;
delete i;
}
void
process_state(const state* s, int, evtgba_iterator* si)
{
std::string cur = quote_unless_bare_word(automata_->format_state(s));
for (si->first(); !si->done(); si->next())
{
const state* dest = si->current_state();
os_ << cur << ", "
<< quote_unless_bare_word(automata_->format_state(dest))
<< ", "
<< quote_unless_bare_word(automata_
->format_label(si->current_label()))
<< ",";
output_acc_set(si->current_acceptance_conditions());
os_ << ";" << std::endl;
delete dest;
}
}
private:
std::ostream& os_;
void
output_acc_set(const symbol_set& ss) const
{
for (symbol_set::const_iterator i = ss.begin(); i != ss.end(); ++i)
os_ << " "
<< quote_unless_bare_word(automata_
->format_acceptance_condition(*i));
}
};
}
std::ostream&
evtgba_save_reachable(std::ostream& os, const evtgba* g)
{
save_bfs b(g, os);
b.run();
return os;
}
}

34
src/evtgbaalgos/save.hh Normal file
View file

@ -0,0 +1,34 @@
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
// 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 2 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 Spot; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
#ifndef SPOT_EVTGBAALGOS_SAVE_HH
# define SPOT_EVTGBAALGOS_SAVE_HH
#include "evtgba/evtgba.hh"
#include <iosfwd>
namespace spot
{
/// \brief Save reachable states in text format.
std::ostream& evtgba_save_reachable(std::ostream& os, const evtgba* g);
}
#endif // SPOT_EVTGBAALGOS_SAVE_HH