Commit 847270b4 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

ltlcross: replace %H,%T,%N by %O

Also get rid of the lbt_parser, and fix the LBT support of the HOA
parser.

* doc/org/ltlcross.org, doc/org/ltldo.org: Update.
* src/bin/common_trans.cc, src/bin/common_trans.hh: Add support for
%O, and keep %T,%N,%H as hidden aliases without disabling them.
* src/bin/ltlcross.cc, src/bin/ltldo.cc, src/tgbatest/ltl2tgba.cc:
Call hoa_parse instead of lbt_parse.
* src/hoaparse/hoaparse.yy: Improve error reporting from LBT.
* src/hoaparse/hoascan.ll: Fix typos preventing parsing of
LBT files with more than 10 states.
* src/tgbaalgos/lbtt.cc, src/tgbaalgos/lbtt.hh: Delete the lbt
parser.
* src/tgbatest/lbttparse.test: Adjust the expected error message.
* NEWS: Update.
parent dbd824c5
......@@ -62,11 +62,12 @@ New in spot 1.99a (not yet released)
used in a stream. The parser currently ignore all optional
headers (starting with a lowercase letter).
- The above HOA parser can also parse neverclaims, so the
neverclaim parser has been removed. This implies that
autfilt can input a mix of HOA and neverclaims, and that
ltlcross' %N and %H specifiers (used to indicate whether
a tool produces neverclaims or HOA) are now synonyms.
- The above HOA parser can also parse never claims, and LBTT
automata, so the never claim parser and the LBTT parser have
been removed. This implies that autfilt can input a mix of HOA,
never claims, and LBTT automata. ltlcross also use the same
parser for all these output, and the old %T and %N specifiers
have been deprecated and replaced by %O (for output).
- randomize() is a new algorithm that reorder the states
and transition of an automaton at random. It can be
......
This diff is collapsed.
......@@ -81,7 +81,7 @@ X[]!<>((a && ![]b) || (!a && []b)),4,10
Using =ltldo= the above command can be reduced to this:
#+BEGIN_SRC sh :results verbatim :exports both
ltldo 'ltl3ba -f %s>%N' -F sample.ltl --stats='%f,%s,%t'
ltldo 'ltl3ba -f %s>%O' -F sample.ltl --stats='%f,%s,%t'
#+END_SRC
#+RESULTS:
#+begin_example
......@@ -129,7 +129,7 @@ the [[http://adl.github.io/hoaf/][HOA format]]. Spin has no support for HOA, bu
converts the never claim produced by =spin= into this format.
#+BEGIN_SRC sh :results verbatim :exports both
ltldo -f a -f GFa 'spin -f %s>%N' -H
ltldo -f a -f GFa 'spin -f %s>%O' -H
#+END_SRC
#+RESULTS:
......@@ -184,8 +184,8 @@ ltldo --help | sed -n '/character sequences:/,/^$/p' | sed '1d;$d'
: LBT, or Wring's syntax
: %F,%S,%L,%W the formula as a file in Spot, Spin, LBT, or
: Wring's syntax
: %N,%T,%D,%H the automaton is output as a Never claim, or in
: LBTT's, in LTL2DSTAR's, or in the HOA format
: %O,%D the automaton is output as either (%O) HOA/never
: claim/LBTT, or (%D) in LTL2DSTAR's format
Contrarily to =ltlcross=, it this not mandatory to specify an output
filename using one of the sequence for that last line. For instance
......@@ -209,31 +209,31 @@ executed on each formula in the same order.
A typical use-case is to compare statistics of different tools:
#+BEGIN_SRC sh :results verbatim :exports both
ltldo -F sample.ltl 'spin -f %s>%N' 'ltl3ba -f %s>%N' --stats=%T,%f,%s,%e
ltldo -F sample.ltl 'spin -f %s>%O' 'ltl3ba -f %s>%O' --stats=%T,%f,%s,%e
#+END_SRC
#+RESULTS:
#+begin_example
spin -f %s>%N,1,2,2
ltl3ba -f %s>%N,1,1,1
spin -f %s>%N,1 U a,2,3
ltl3ba -f %s>%N,1 U a,2,3
spin -f %s>%N,!(!((a U Gb) U b) U GFa),23,86
ltl3ba -f %s>%N,!(!((a U Gb) U b) U GFa),2,3
spin -f %s>%N,(b <-> Xc) xor Fb,12,23
ltl3ba -f %s>%N,(b <-> Xc) xor Fb,7,11
spin -f %s>%N,FXb R (a R (1 U b)),28,176
ltl3ba -f %s>%N,FXb R (a R (1 U b)),6,20
spin -f %s>%N,Ga,1,1
ltl3ba -f %s>%N,Ga,1,1
spin -f %s>%N,G(!(c | (a & (a W Gb))) M Xa),15,51
ltl3ba -f %s>%N,G(!(c | (a & (a W Gb))) M Xa),1,0
spin -f %s>%N,GF((b R !a) U (Xc M 1)),12,60
ltl3ba -f %s>%N,GF((b R !a) U (Xc M 1)),2,4
spin -f %s>%N,G(Xb | Gc),4,8
ltl3ba -f %s>%N,G(Xb | Gc),3,5
spin -f %s>%N,XG!F(a xor Gb),8,21
ltl3ba -f %s>%N,XG!F(a xor Gb),4,7
spin -f %s>%O,1,2,2
ltl3ba -f %s>%O,1,1,1
spin -f %s>%O,1 U a,2,3
ltl3ba -f %s>%O,1 U a,2,3
spin -f %s>%O,!(!((a U Gb) U b) U GFa),23,86
ltl3ba -f %s>%O,!(!((a U Gb) U b) U GFa),2,3
spin -f %s>%O,(b <-> Xc) xor Fb,12,23
ltl3ba -f %s>%O,(b <-> Xc) xor Fb,7,11
spin -f %s>%O,FXb R (a R (1 U b)),28,176
ltl3ba -f %s>%O,FXb R (a R (1 U b)),6,20
spin -f %s>%O,Ga,1,1
ltl3ba -f %s>%O,Ga,1,1
spin -f %s>%O,G(!(c | (a & (a W Gb))) M Xa),15,51
ltl3ba -f %s>%O,G(!(c | (a & (a W Gb))) M Xa),1,0
spin -f %s>%O,GF((b R !a) U (Xc M 1)),12,60
ltl3ba -f %s>%O,GF((b R !a) U (Xc M 1)),2,4
spin -f %s>%O,G(Xb | Gc),4,8
ltl3ba -f %s>%O,G(Xb | Gc),3,5
spin -f %s>%O,XG!F(a xor Gb),8,21
ltl3ba -f %s>%O,XG!F(a xor Gb),4,7
#+end_example
Here we used =%T= to output the name of the tool used to translate the
......@@ -247,7 +247,7 @@ using the trick that the command =echo %f= will not be subject to
#+BEGIN_SRC sh :results verbatim :exports both
ltldo -F sample.ltl --stats=%T,%s,%e \
'echo "#" %f' '{spin}spin -f %s>%N' '{ltl3ba}ltl3ba -f %s>%N'
'echo "#" %f' '{spin}spin -f %s>%O' '{ltl3ba}ltl3ba -f %s>%O'
#+END_SRC
#+RESULTS:
......@@ -300,14 +300,14 @@ ltldo --list-shorthands
If a COMMANDFMT does not use any %-sequence, and starts with one of
the following words, then the string on the right is appended.
lbt <%L>%T
ltl2ba -f %s>%N
lbt <%L>%O
ltl2ba -f %s>%O
ltl2dstar %L %D
ltl2tgba -H %f>%H
ltl3ba -f %s>%N
ltl2tgba -H %f>%O
ltl3ba -f %s>%O
ltl3dra -f %f>%D
modella %L %T
spin -f %s>%N
modella %L %O
spin -f %s>%O
#+end_example
So for instance you can type just
......@@ -331,7 +331,7 @@ for the neverclaim produced by =ltl2ba -f a=.
: }
The =ltl2ba= argument passed to =ltldo= was interpreted as if you had
typed ={ltl2ba}ltl2ba -f %s>%N=.
typed ={ltl2ba}ltl2ba -f %s>%O=.
The shorthand is only used if it is the first word of an command
string that does not use any =%= character. This makes it possible to
......@@ -390,7 +390,7 @@ claim was then relabeled by =ltldo= to use =Error= instead of =p0=.
This renaming occurs any time some command uses =%s= or =%S= and the
formula has atomic propositions incompatible with Spin's conventions;
or when some command uses =%l=, =%L=, or =%T=, and the formula has
or when some command uses =%l= or =%L=, and the formula has
atomic propositions incompatible with [[http://www.tcs.hut.fi/Software/maria/tools/lbt/][LBT's conventions]].
......
......@@ -39,14 +39,14 @@ static struct shorthands_t
const char* suffix;
}
shorthands[] = {
{ "lbt", " <%L>%T" },
{ "ltl2ba", " -f %s>%N" },
{ "lbt", " <%L>%O" },
{ "ltl2ba", " -f %s>%O" },
{ "ltl2dstar", " %L %D"},
{ "ltl2tgba", " -H %f>%H" },
{ "ltl3ba", " -f %s>%N" },
{ "ltl2tgba", " -H %f>%O" },
{ "ltl3ba", " -f %s>%O" },
{ "ltl3dra", " -f %f>%D" },
{ "modella", " %L %T" },
{ "spin", " -f %s>%N" },
{ "modella", " %L %O" },
{ "spin", " -f %s>%O" },
};
void show_shorthands()
......@@ -162,14 +162,11 @@ void
printable_result_filename::print(std::ostream& os, const char* pos) const
{
output_format old_format = format;
if (*pos == 'N')
format = Hoa; // The HOA parse also reads neverclaims
else if (*pos == 'T')
format = Lbtt;
// The HOA parser can read LBTT, neverclaims, and HOA.
if (*pos == 'N' || *pos == 'T' || *pos == 'H' || *pos == 'O')
format = Hoa;
else if (*pos == 'D')
format = Dstar;
else if (*pos == 'H')
format = Hoa;
else
SPOT_UNREACHABLE();
......@@ -179,7 +176,7 @@ printable_result_filename::print(std::ostream& os, const char* pos) const
// to mix the formats.
if (format != old_format)
error(2, 0,
"you may not mix %%D, %%H, %%N, and %%T specifiers: %s",
"you may not mix different output specifiers: %s",
translators[translator_num].spec);
}
else
......@@ -209,6 +206,7 @@ translator_runner::translator_runner(spot::bdd_dict_ptr dict,
declare('H', &output);
declare('N', &output);
declare('T', &output);
declare('O', &output);
size_t s = translators.size();
assert(s);
......@@ -225,9 +223,11 @@ translator_runner::translator_runner(spot::bdd_dict_ptr dict,
"one of %%f,%%s,%%l,%%w,%%F,%%S,%%L,%%W to indicate how "
"to pass the formula.", t.spec);
if (!no_output_allowed
&& !(has['D'] || has['N'] || has['T'] || has['H']))
&& !(has['O'] || has['D'] ||
// backward-compatibility
has['N'] || has['T'] || has['H']))
error(2, 0, "no output %%-sequence in '%s'.\n Use one of "
"%%D,%%H,%%N,%%T to indicate where the automaton is saved.",
"%%O or %%D to indicate where and how the automaton is saved.",
t.spec);
// Remember the %-sequences used by all translators.
prime(t.cmd);
......@@ -402,9 +402,9 @@ static const argp_option options[] =
0 },
{ "%F,%S,%L,%W", 0, 0, OPTION_DOC | OPTION_NO_USAGE,
"the formula as a file in Spot, Spin, LBT, or Wring's syntax", 0 },
{ "%N,%T,%D,%H", 0, 0, OPTION_DOC | OPTION_NO_USAGE,
"the automaton is output as a Never claim, or in LBTT's, in LTL2DSTAR's,"
" or in the HOA format", 0 },
{ "%O,%D", 0, 0, OPTION_DOC | OPTION_NO_USAGE,
"the automaton is output as either (%O) HOA/never claim/LBTT, or (%D) "
"in LTL2DSTAR's format", 0 },
{ 0, 0, 0, 0,
"If either %l, %L, or %T are used, any input formula that does "
"not use LBT-style atomic propositions (i.e. p0, p1, ...) will be "
......
......@@ -61,7 +61,7 @@ struct printable_result_filename final:
public spot::printable_value<spot::temporary_file*>
{
unsigned translator_num;
enum output_format { None, Lbtt, Dstar, Hoa };
enum output_format { None, Dstar, Hoa };
mutable output_format format;
printable_result_filename();
......
......@@ -529,35 +529,6 @@ namespace
es = 0;
switch (output.format)
{
case printable_result_filename::Lbtt:
{
std::string error;
std::ifstream f(output.val()->name());
if (!f)
{
status_str = "no output";
problem = true;
es = -1;
global_error() << "Cannot open " << output.val()
<< std::endl;
end_error();
}
else
{
res = spot::lbtt_parse(f, error, dict);
if (!res)
{
status_str = "parse error";
problem = true;
es = -1;
global_error() << ("error: failed to parse output in "
"LBTT format: ")
<< error << std::endl;
end_error();
}
}
break;
}
case printable_result_filename::Dstar:
{
spot::dstar_parse_error_list pel;
......
......@@ -171,29 +171,6 @@ namespace
problem = false;
switch (output.format)
{
case printable_result_filename::Lbtt:
{
std::string error;
std::ifstream f(output.val()->name());
if (!f)
{
problem = true;
std::cerr << "error: could not open " << output.val()
<< " after running \"" << cmd << "\".\n";
}
else
{
res = spot::lbtt_parse(f, error, dict);
if (!res)
{
problem = true;
std::cerr << "error: failed to parse output of \""
<< cmd << "\" in LBTT format:\n"
<< "error: " << error << '\n';
}
}
break;
}
case printable_result_filename::Dstar:
{
spot::dstar_parse_error_list pel;
......@@ -213,8 +190,9 @@ namespace
}
break;
}
case printable_result_filename::Hoa: // Will also read neverclaims
case printable_result_filename::Hoa:
{
// Will also read neverclaims/LBTT
spot::hoa_parse_error_list pel;
std::string filename = output.val()->name();
auto aut = spot::hoa_parse(filename, pel, dict);
......
......@@ -1259,7 +1259,11 @@ lbtt-guard: STRING
spot::ltl::parse_error_list pel;
auto* f = spot::ltl::parse_lbt(*$1, pel, *res.env);
if (!f || !pel.empty())
error(@$, "failed to parse guard");
{
std::string s = "failed to parse guard: ";
s += *$1;
error(@$, s);
}
if (!pel.empty())
for (auto& j: pel)
{
......
......@@ -213,7 +213,7 @@ identifier [[:alpha:]_][[:alnum:]_-]*
"-1" BEGIN(in_LBTT_TRANS); yylloc->step();
}
<in_LBTT_TRANS>{
[0-9+] {
[0-9]+ {
parse_int();
if (lbtt_t)
BEGIN(in_LBTT_T_ACC);
......@@ -235,7 +235,7 @@ identifier [[:alpha:]_][[:alnum:]_-]*
}
}
<in_LBTT_T_ACC>{
[0-9+] parse_int(); return token::ACC;
[0-9]+ parse_int(); return token::ACC;
"-1" BEGIN(in_LBTT_GUARD); yylloc->step();
}
<in_LBTT_GUARD>{
......
// -*- coding: utf-8 -*-
// Copyright (C) 2011, 2012, 2013, 2014 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
// Copyright (C) 2011, 2012, 2013, 2014, 2015 Laboratoire de Recherche
// et Développement de l'Epita (LRDE).
// Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de Paris
// 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
// Université Pierre et Marie Curie.
......@@ -130,139 +130,7 @@ namespace spot
bool sba_format_;
const_tgba_digraph_ptr sba_;
};
static
tgba_digraph_ptr
lbtt_read_tgba(unsigned num_states, unsigned num_acc,
std::istream& is, std::string& error,
const bdd_dict_ptr& dict, ltl::environment& env)
{
auto aut = make_tgba_digraph(dict);
acc_mapper_int acc_b(aut, num_acc);
aut->new_states(num_states);
for (unsigned n = 0; n < num_states; ++n)
{
int src_state = 0;
int initial = 0;
is >> src_state >> initial;
if (initial)
aut->set_init_state(src_state);
// Read the transitions.
for (;;)
{
int dst_state = 0;
is >> dst_state;
if (dst_state == -1)
break;
// Read the acceptance conditions.
acc_cond::mark_t acc = 0U;
for (;;)
{
int acc_n = 0;
is >> acc_n;
if (acc_n == -1)
break;
auto p = acc_b.lookup(acc_n);
if (p.first)
{
acc |= p.second;
}
else
{
error += "more acceptance sets used than declared";
return nullptr;
}
}
std::string guard;
std::getline(is, guard);
ltl::parse_error_list pel;
const ltl::formula* f = parse_lbt(guard, pel, env);
if (!f || !pel.empty())
{
error += "failed to parse guard: " + guard;
if (f)
f->destroy();
return nullptr;
}
bdd cond = formula_to_bdd(f, dict, aut.get());
f->destroy();
aut->new_transition(src_state, dst_state, cond, acc);
}
}
return aut;
}
tgba_digraph_ptr
lbtt_read_gba(unsigned num_states, unsigned num_acc,
std::istream& is, std::string& error,
const bdd_dict_ptr& dict, ltl::environment& env)
{
auto aut = make_tgba_digraph(dict);
acc_mapper_int acc_b(aut, num_acc);
aut->new_states(num_states);
aut->prop_state_based_acc();
for (unsigned n = 0; n < num_states; ++n)
{
int src_state = 0;
int initial = 0;
is >> src_state >> initial;
if (initial)
aut->set_init_state(src_state);
// Read the acceptance conditions.
acc_cond::mark_t acc = 0U;
for (;;)
{
int acc_n = 0;
is >> acc_n;
if (acc_n == -1)
break;
auto p = acc_b.lookup(acc_n);
if (p.first)
{
acc |= p.second;
}
else
{
error += "more acceptance sets used than declared";
return nullptr;
}
}
// Read the transitions.
for (;;)
{
int dst_state = 0;
is >> dst_state;
if (dst_state == -1)
break;
std::string guard;
std::getline(is, guard);
ltl::parse_error_list pel;
const ltl::formula* f = parse_lbt(guard, pel, env);
if (!f || !pel.empty())
{
error += "failed to parse guard: " + guard;
if (f)
f->destroy();
return nullptr;
}
bdd cond = formula_to_bdd(f, dict, aut.get());
f->destroy();
aut->new_transition(src_state, dst_state, cond, acc);
}
}
return aut;
}
} // anonymous
}
std::ostream&
lbtt_reachable(std::ostream& os, const const_tgba_ptr& g, bool sba)
......@@ -271,41 +139,4 @@ namespace spot
b.run();
return os;
}
tgba_digraph_ptr
lbtt_parse(std::istream& is, std::string& error, const bdd_dict_ptr& dict,
ltl::environment& env)
{
is >> std::skipws;
unsigned num_states = 0;
is >> num_states;
if (!is)
{
error += "failed to read the number of states";
return 0;
}
// No states? Read the rest of the line and return an empty automaton.
if (num_states == 0)
{
std::string header;
std::getline(is, header);
return make_tgba_digraph(dict);
}
unsigned num_acc = 0;
is >> num_acc;
int type;
type = is.peek();
if (type == 't' || type == 'T' || type == 's' || type == 'S')
type = is.get();
if (type == 't' || type == 'T')
return lbtt_read_tgba(num_states, num_acc, is, error, dict, env);
else
return lbtt_read_gba(num_states, num_acc, is, error, dict, env);
}
}
......@@ -23,9 +23,8 @@
#ifndef SPOT_TGBAALGOS_LBTT_HH
# define SPOT_TGBAALGOS_LBTT_HH
#include "tgba/tgbagraph.hh"
#include "tgba/tgba.hh"
#include <iosfwd>
#include "ltlenv/defaultenv.hh"
namespace spot
{
......@@ -38,21 +37,6 @@ namespace spot
/// acceptance format (similar to LBT's format).
SPOT_API std::ostream&
lbtt_reachable(std::ostream& os, const const_tgba_ptr& g, bool sba = false);
/// \ingroup tgba_io
/// \brief Read an automaton in LBTT's format
///
/// \param is The stream on which the automaton should be input.
/// \param error A string in which to write any error message.
/// \param dict The dictionary that should register the BDD variables
/// used by the automaton built.
/// \param env The environment of atomic proposition into which parsing
/// should take place.
/// \return the read tgba or 0 on error.
SPOT_API tgba_digraph_ptr
lbtt_parse(std::istream& is, std::string& error,
const bdd_dict_ptr& dict,
ltl::environment& env = ltl::default_environment::instance());
}
#endif // SPOT_TGBAALGOS_LBTT_HH
#!/bin/sh
# -*- coding: utf-8 -*-
# Copyright (C) 2012, 2013, 2014 Laboratoire de Recherche et Développement
# de l'Epita (LRDE).
# Copyright (C) 2012, 2013, 2014, 2015 Laboratoire de Recherche et
# Développement de l'Epita (LRDE).
#
# This file is part of Spot, a model checking library.
#
......@@ -122,7 +122,7 @@ cat > input <<EOF
-1
EOF
cat >expected <<EOF
input:3.5-20: failed to parse guard
input:3.5-20: failed to parse guard: & ! "a" ! "b" !
input:3.20: syntax error, unexpected '!', expecting end of formula
input:3.20: ignoring trailing garbage
EOF
......
......@@ -343,7 +343,7 @@ checked_main(int argc, char** argv)
bool accepting_run = false;
bool accepting_run_replay = false;
bool from_file = false;
enum { ReadLbtt, ReadDstar, ReadHoa } readformat = ReadHoa;
enum { ReadDstar, ReadHoa } readformat = ReadHoa;
bool nra2nba = false;
bool dra2dba = false;
bool scc_filter = false;
......@@ -883,7 +883,7 @@ checked_main(int argc, char** argv)
else if (!strcmp(argv[formula_index], "-XL"))
{
from_file = true;
readformat = ReadLbtt;
readformat = ReadHoa;
}
else if (!strcmp(argv[formula_index], "-XN")) // now synonym for -XH
{
......@@ -967,31 +967,6 @@ checked_main(int argc, char** argv)
{
switch (readformat)
{
case ReadLbtt:
{
std::string error;
std::istream* in = &std::cin;
std::fstream* f = 0;
if (input != "-")
{
in = f = new std::fstream(input.c_str());
if (!*f)
{
std::cerr << "cannot open " << input << std::endl;
return 2;
}
}
tm.start("parsing lbtt");
a = spot::lbtt_parse(*in, error, dict, env);