* src/ltlvisit/tostring.hh (to_spin_string): New function.

Convert a formula into a string parsable by Spin.
* src/tgbaalgos/neverclaim.hh, src/tgbaalgos/neverclaim.cc: New files.
Print the never claim in Spin format of a degeneralized TGBA.
* src/tgbaalgos/Makefile.am: Add them.
* src/tgbatest/ltl2tgba.cc: Add the option -N which outputs the
never claim in Spin format of a degeneralized TGBA.
* src/tgbatest/ltl2neverclaim.test: New file.
* src/tgbatest/Makefile.am: Add it.
This commit is contained in:
Alexandre Duret-Lutz 2004-04-21 15:18:07 +00:00
parent 4d73490a49
commit 8d8af2e53a
11 changed files with 437 additions and 5 deletions

View file

@ -11,7 +11,7 @@
//
// 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
// 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
@ -35,7 +35,7 @@ namespace spot
{
public:
to_string_visitor(std::ostream& os = std::cout)
: os_(os)
: os_(os)
{
}
@ -147,7 +147,7 @@ namespace spot
}
os_ << ")";
}
private:
protected:
std::ostream& os_;
};
@ -166,5 +166,139 @@ namespace spot
to_string(f, os);
return os.str();
}
class to_spin_string_visitor : public to_string_visitor
{
public:
to_spin_string_visitor(std::ostream& os = std::cout)
: to_string_visitor(os)
{
}
virtual
~to_spin_string_visitor()
{
}
void
visit(const binop* bo)
{
os_ << "(";
switch(bo->op())
{
case binop::Xor:
os_ << "(!";
bo->first()->accept(*this);
os_ << " && ";
bo->second()->accept(*this);
os_ << ") || (";
bo->first()->accept(*this);
os_ << " && !";
bo->second()->accept(*this);
os_ << ")";
break;
case binop::Implies:
os_ << "!";
bo->first()->accept(*this);
os_ << " || ";
bo->second()->accept(*this);
break;
case binop::Equiv:
os_ << "(";
bo->first()->accept(*this);
os_ << " && ";
bo->second()->accept(*this);
os_ << ") || (!";
bo->first()->accept(*this);
os_ << " && !";
bo->second()->accept(*this);
os_ << ")";
case binop::U:
bo->first()->accept(*this);
os_ << " U ";
bo->second()->accept(*this);
break;
case binop::R:
bo->first()->accept(*this);
os_ << " V ";
bo->second()->accept(*this);
break;
}
os_ << ")";
}
void
visit(const unop* uo)
{
// The parser treats X0, and X1 as atomic propositions. So
// make sure we output X(0) and X(1).
bool need_parent = false;
switch(uo->op())
{
case unop::Not:
os_ << "!";
break;
case unop::X:
need_parent = !! dynamic_cast<const constant*>(uo->child());
os_ << "X";
break;
case unop::F:
os_ << "<>";
break;
case unop::G:
os_ << "[]";
break;
}
if (need_parent)
os_ << "(";
uo->child()->accept(*this);
if (need_parent)
os_ << ")";
}
void
visit(const multop* mo)
{
os_ << "(";
unsigned max = mo->size();
mo->nth(0)->accept(*this);
const char* ch = " ";
switch (mo->op())
{
case multop::Or:
ch = " || ";
break;
case multop::And:
ch = " && ";
break;
}
for (unsigned n = 1; n < max; ++n)
{
os_ << ch;
mo->nth(n)->accept(*this);
}
os_ << ")";
}
};
std::ostream&
to_spin_string(const formula* f, std::ostream& os)
{
to_spin_string_visitor v(os);
f->accept(v);
return os;
}
std::string
to_spin_string(const formula* f)
{
std::ostringstream os;
to_spin_string(f, os);
return os.str();
}
}
}

View file

@ -37,6 +37,15 @@ namespace spot
/// \brief Convert a formula into a (parsable) string.
/// \param f The formula to translate.
std::string to_string(const formula* f);
/// \brief Output a formula as a (parsable by Spin) string.
/// \param f The formula to translate.
/// \param os The stream where it should be output.
std::ostream& to_spin_string(const formula* f, std::ostream& os);
/// \brief Convert a formula into a (parsable by Spin) string.
/// \param f The formula to translate.
std::string to_spin_string(const formula* f);
}
}