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.
This commit is contained in:
Alexandre Duret-Lutz 2015-02-01 01:54:39 +01:00
parent dbd824c539
commit 847270b480
13 changed files with 264 additions and 540 deletions

View file

@ -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 "

View file

@ -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();

View file

@ -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;

View file

@ -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);

View file

@ -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)
{

View file

@ -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>{

View file

@ -1,6 +1,6 @@
// -*- 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);
}
}

View file

@ -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

View file

@ -1,7 +1,7 @@
#!/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

View file

@ -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);
tm.stop("parsing lbtt");
delete f;
if (!a)
{
std::cerr << error << std::endl;
return 2;
}
}
break;
case ReadDstar:
{
spot::dstar_parse_error_list pel;