Commit 209e89a9 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz

parseaut: swallow the dstarparser

Note that the parser is still not able to reader multiple dstar
automata.

* src/dstarparse/: Delete.
* configure.ac, src/Makefile.am, README: Adjust.
* src/parseaut/parseaut.yy, src/parseaut/scanaut.ll: Merge in the
dstarparser rules.
* src/bin/common_trans.cc, src/bin/common_trans.hh,
src/bin/dstar2tgba.cc, src/bin/ltlcross.cc, src/bin/ltldo.cc,
src/tests/ikwiad.cc: Adjust usage.
* src/tests/parseaut.test: Adjust expected output.
parent e7ecab93
......@@ -137,7 +137,6 @@ Core directories
src/ Sources for libspot.
bin/ User tools built using the Spot library.
man/ Man pages for the above tools.
dstarparse/ Parser for the output of ltl2dstar.
graph/ Graph representations.
kripke/ Kripke Structure interface.
kripkeparse/ Parser for explicit Kripke.
......@@ -146,7 +145,7 @@ src/ Sources for libspot.
ltlparse/ Parser for LTL formulae.
ltlvisit/ Visitors of LTL formulae.
misc/ Miscellaneous support files.
parseaut/ Parser for HOA automata and Spin's never claims.
parseaut/ Parser for automata in multiple formats.
priv/ Private algorithms, used internally but not exported.
ta/ TA objects and cousins (TGTA).
taalgos/ Algorithms on TA/TGTA.
......
......@@ -200,7 +200,6 @@ AC_CONFIG_FILES([
lib/Makefile
src/bin/Makefile
src/bin/man/Makefile
src/dstarparse/Makefile
src/kripke/Makefile
src/graph/Makefile
src/parseaut/Makefile
......
......@@ -26,14 +26,13 @@ AUTOMAKE_OPTIONS = subdir-objects
# end, after building '.' (since the current directory contains
# libspot.la needed by the tests)
SUBDIRS = misc priv ltlenv ltlast ltlvisit ltlparse graph twa \
twaalgos ta taalgos kripke kripkeparse dstarparse parseaut \
. bin tests sanity
twaalgos ta taalgos kripke kripkeparse parseaut . bin tests \
sanity
lib_LTLIBRARIES = libspot.la
libspot_la_SOURCES =
libspot_la_LDFLAGS = $(BUDDY_LDFLAGS) -no-undefined
libspot_la_LIBADD = \
dstarparse/libdstarparse.la \
parseaut/libparseaut.la \
kripke/libkripke.la \
kripkeparse/libkripkeparse.la \
......
......@@ -194,7 +194,6 @@ printable_result_filename::~printable_result_filename()
void printable_result_filename::reset(unsigned n)
{
translator_num = n;
format = None;
}
void printable_result_filename::cleanup()
......@@ -204,33 +203,12 @@ void printable_result_filename::cleanup()
}
void
printable_result_filename::print(std::ostream& os, const char* pos) const
printable_result_filename::print(std::ostream& os, const char*) const
{
output_format old_format = format;
// 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
SPOT_UNREACHABLE();
if (val_)
{
// It's OK to use a specifier multiple time, but it's not OK
// to mix the formats.
if (format != old_format)
error(2, 0,
"you may not mix different output specifiers: %s",
translators[translator_num].spec);
}
else
{
char prefix[30];
snprintf(prefix, sizeof prefix, "lcr-o%u-", translator_num);
const_cast<printable_result_filename*>(this)->val_
= spot::create_tmpfile(prefix);
}
char prefix[30];
snprintf(prefix, sizeof prefix, "lcr-o%u-", translator_num);
const_cast<printable_result_filename*>(this)->val_ =
spot::create_tmpfile(prefix);
quote_shell_string(os, val()->name());
}
......@@ -268,11 +246,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['O'] || has['D'] ||
&& !(has['O'] ||
// backward-compatibility
has['N'] || has['T'] || has['H']))
error(2, 0, "no output %%-sequence in '%s'.\n Use one of "
"%%O or %%D to indicate where and how the automaton is saved.",
has['D'] || has['N'] || has['T'] || has['H']))
error(2, 0, "no output %%-sequence in '%s'.\n Use "
"%%O to indicate where the automaton is output.",
t.spec);
// Remember the %-sequences used by all translators.
prime(t.cmd);
......
......@@ -60,8 +60,6 @@ struct printable_result_filename final:
public spot::printable_value<spot::temporary_file*>
{
unsigned translator_num;
enum output_format { None, Dstar, Hoa };
mutable output_format format;
printable_result_filename();
~printable_result_filename();
......
......@@ -42,7 +42,7 @@
#include "twa/bddprint.hh"
#include "misc/optionmap.hh"
#include "misc/timer.hh"
#include "dstarparse/public.hh"
#include "parseaut/public.hh"
#include "twaalgos/sccinfo.hh"
static const char argp_program_doc[] ="\
......@@ -148,7 +148,7 @@ namespace
process_file(const char* filename)
{
spot::parse_aut_error_list pel;
auto daut = spot::dstar_parse(filename, pel, spot::make_bdd_dict());
auto daut = spot::parse_aut(filename, pel, spot::make_bdd_dict());
if (spot::format_parse_aut_errors(std::cerr, filename, pel))
return 2;
if (!daut)
......
......@@ -38,7 +38,6 @@
#include "common_trans.hh"
#include "common_file.hh"
#include "common_finput.hh"
#include "dstarparse/public.hh"
#include "parseaut/public.hh"
#include "ltlast/unop.hh"
#include "ltlvisit/print.hh"
......@@ -493,8 +492,6 @@ namespace
std::ostringstream command;
format(command, translators[translator_num].cmd);
assert(output.format != printable_result_filename::None);
std::string cmd = command.str();
std::cerr << "Running [" << l << translator_num << "]: "
<< cmd << std::endl;
......@@ -548,73 +545,42 @@ namespace
status_str = "ok";
problem = false;
es = 0;
switch (output.format)
spot::parse_aut_error_list pel;
std::string filename = output.val()->name();
auto aut = spot::parse_aut(filename, pel, dict);
if (!pel.empty())
{
case printable_result_filename::Dstar:
{
spot::parse_aut_error_list pel;
std::string filename = output.val()->name();
auto aut = spot::dstar_parse(filename, pel, dict);
if (!pel.empty())
{
status_str = "parse error";
problem = true;
es = -1;
std::ostream& err = global_error();
err << "error: failed to parse the produced DSTAR"
" output.\n";
spot::format_parse_aut_errors(err, filename, pel);
end_error();
res = nullptr;
}
else
{
res = aut->aut;
}
break;
}
case printable_result_filename::Hoa: // Will also read neverclaims
{
spot::parse_aut_error_list pel;
std::string filename = output.val()->name();
auto aut = spot::parse_aut(filename, pel, dict);
if (!pel.empty())
{
status_str = "parse error";
problem = true;
es = -1;
std::ostream& err = global_error();
err << "error: failed to parse the produced automaton.\n";
spot::format_parse_aut_errors(err, filename, pel);
end_error();
res = nullptr;
}
else if (!aut)
{
status_str = "empty output";
problem = true;
es = -1;
global_error() << "error: empty output.\n";
end_error();
res = nullptr;
}
else if (aut->aborted)
{
status_str = "aborted";
problem = true;
es = -1;
global_error() << "error: aborted HOA file.\n";
end_error();
res = nullptr;
}
else
{
res = aut->aut;
}
break;
}
case printable_result_filename::None:
SPOT_UNREACHABLE();
status_str = "parse error";
problem = true;
es = -1;
std::ostream& err = global_error();
err << "error: failed to parse the produced automaton.\n";
spot::format_parse_aut_errors(err, filename, pel);
end_error();
res = nullptr;
}
else if (!aut)
{
status_str = "empty output";
problem = true;
es = -1;
global_error() << "error: empty output.\n";
end_error();
res = nullptr;
}
else if (aut->aborted)
{
status_str = "aborted";
problem = true;
es = -1;
global_error() << "error: aborted HOA file.\n";
end_error();
res = nullptr;
}
else
{
res = aut->aut;
}
}
......
......@@ -42,7 +42,6 @@
#include "twaalgos/relabel.hh"
#include "twaalgos/totgba.hh"
#include "parseaut/public.hh"
#include "dstarparse/public.hh"
const char argp_program_doc[] ="\
Run LTL/PSL formulas through another program, performing conversion\n\
......@@ -134,8 +133,6 @@ namespace
std::ostringstream command;
format(command, translators[translator_num].cmd);
//assert(output.format != printable_result_filename::None);
std::string cmd = command.str();
//std::cerr << "Running [" << l << translator_num << "]: "
// << cmd << std::endl;
......@@ -166,69 +163,44 @@ namespace
std::cerr << "error: execution of command \"" << cmd
<< "\" returned exit code " << es << ".\n";
}
else
else if (output.val())
{
problem = false;
switch (output.format)
spot::parse_aut_error_list pel;
std::string filename = output.val()->name();
auto aut = spot::parse_aut(filename, pel, dict);
if (!pel.empty())
{
case printable_result_filename::Dstar:
{
spot::parse_aut_error_list pel;
std::string filename = output.val()->name();
auto aut = spot::dstar_parse(filename, pel, dict);
if (!pel.empty())
{
problem = true;
std::cerr << "error: failed to parse the output of \""
<< cmd << "\" as a DSTAR automaton.\n";
spot::format_parse_aut_errors(std::cerr, filename, pel);
res = nullptr;
}
else
{
res = aut->aut;
}
break;
}
case printable_result_filename::Hoa:
{
// Will also read neverclaims/LBTT
spot::parse_aut_error_list pel;
std::string filename = output.val()->name();
auto aut = spot::parse_aut(filename, pel, dict);
if (!pel.empty())
{
problem = true;
std::cerr << "error: failed to parse the automaton "
"produced by \"" << cmd << "\".\n";
spot::format_parse_aut_errors(std::cerr, filename, pel);
res = nullptr;
}
else if (!aut)
{
problem = true;
std::cerr << "error: command \"" << cmd
<< "\" produced an empty output.\n";
res = nullptr;
}
else if (aut->aborted)
{
problem = true;
std::cerr << "error: command \"" << cmd
<< "\" aborted its output.\n";
res = nullptr;
}
else
{
res = aut->aut;
}
}
break;
case printable_result_filename::None:
problem = false;
problem = true;
std::cerr << "error: failed to parse the automaton "
"produced by \"" << cmd << "\".\n";
spot::format_parse_aut_errors(std::cerr, filename, pel);
res = nullptr;
break;
}
else if (!aut)
{
problem = true;
std::cerr << "error: command \"" << cmd
<< "\" produced an empty output.\n";
res = nullptr;
}
else if (aut->aborted)
{
problem = true;
std::cerr << "error: command \"" << cmd
<< "\" aborted its output.\n";
res = nullptr;
}
else
{
res = aut->aut;
}
}
else // No automaton output
{
problem = false;
res = nullptr;
}
output.cleanup();
......
position.hh
dstarparse.cc
dstarparse.output
dstarparse.hh
dstarscan.cc
stack.hh
location.hh
## -*- coding: utf-8 -*-
## Copyright (C) 2013, 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/>.
AM_CPPFLAGS = -I$(srcdir)/.. -I.. $(BUDDY_CPPFLAGS) -DYY_NO_INPUT
# Disable -Werror because too many versions of flex yield warnings.
AM_CXXFLAGS = $(WARNING_CXXFLAGS:-Werror=)
dstarparsedir = $(pkgincludedir)/dstarparse
dstarparse_HEADERS = public.hh
noinst_LTLIBRARIES = libdstarparse.la
DSTARPARSE_YY = dstarparse.yy
FROM_DSTARPARSE_YY_MAIN = dstarparse.cc
FROM_DSTARPARSE_YY_OTHERS = \
stack.hh \
dstarparse.hh
FROM_DSTARPARSE_YY = $(FROM_DSTARPARSE_YY_MAIN) $(FROM_DSTARPARSE_YY_OTHERS)
BUILT_SOURCES = $(FROM_DSTARPARSE_YY)
MAINTAINERCLEANFILES = $(FROM_DSTARPARSE_YY)
$(FROM_DSTARPARSE_YY_MAIN): $(srcdir)/$(DSTARPARSE_YY)
## We must cd into $(srcdir) first because if we tell bison to read
## $(srcdir)/$(DSTARPARSE_YY), it will also use the value of $(srcdir)/
## in the generated include statements.
cd $(srcdir) && \
$(BISON) -Wall -Werror --report=all $(BISON_EXTRA_FLAGS) \
$(DSTARPARSE_YY) -o $(FROM_DSTARPARSE_YY_MAIN)
$(FROM_DSTARPARSE_YY_OTHERS): $(DSTARPARSE_YY)
@test -f $@ || $(MAKE) $(AM_MAKEFLAGS) $(FROM_DSTARPARSE_YY_MAIN)
EXTRA_DIST = $(DSTARPARSE_YY)
libdstarparse_la_SOURCES = \
$(FROM_DSTARPARSE_YY) \
dstarscan.ll \
parsedecl.hh
/* -*- 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::parse_aut_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::parsed_aut_ptr h;
spot::ltl::environment* env;
std::vector<bdd> guards;
std::vector<bdd>::const_iterator cur_guard;
map_t dest_map;
unsigned int cur_state;
int plus;
int minus;
int states = -1;
unsigned start_state = 0U;
unsigned accpair_count = 0U;
std::vector<int> ap;
std::set<int> ap_set;
bool accpair_count_seen:1;
bool start_state_seen:1;
bool ignore_more_ap:1;
result_():
accpair_count_seen(false),
start_state_seen(false),
ignore_more_ap(false)
{
}
};
}
}
%parse-param {spot::parse_aut_error_list& error_list}
%parse-param {result_& res}
%union
{
std::string* str;
unsigned int num;
spot::acc_cond::mark_t mark;
}
%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
%type <mark> dstar_accsigs dstar_state_accsig
%destructor { delete $$; } <str>
%printer {
if ($$)
debug_stream() << *$$;
else
debug_stream() << "\"\""; } <str>
%printer { debug_stream() << $$; } <num>
%%
dstar: dstar_header ENDOFHEADER eols dstar_states
{ res.h->loc = @$; }
eols : EOL | eols EOL
opt_eols: | opt_eols EOL
dstar_type: DRA
{
res.h->type = spot::parsed_aut_type::DRA;
res.plus = 1;
res.minus = 0;
}
| DSA
{
res.h->type = spot::parsed_aut_type::DSA;
res.plus = 0;
res.minus = 1;
}
dstar_header: dstar_type opt_eols V2 opt_eols EXPLICIT opt_eols dstar_sizes
{
bool err = false;
if (res.states < 0)
{
error(@5, "missing state count");
err = true;
}
if (!res.accpair_count_seen)
{
error(@5, "missing acceptance-pair count");
err = true;
}
if (!res.start_state_seen)
{
error(@5, "missing start-state number");
err = true;
}
if (!res.ignore_more_ap)
{
error(@5, "missing atomic proposition definition");
err = true;
}
if (err)
{
res.h->aut = nullptr;
YYABORT;
}
res.h->aut->new_states(res.states);;
res.h->aut->set_init_state(res.start_state);
fill_guards(res);
res.cur_guard = res.guards.end();
}
aps:
| aps STRING opt_eols
{
if (!res.ignore_more_ap)
{
auto f = res.env->require(*$2);
auto d = res.h->aut->get_dict();
int b = 0;
if (f == nullptr)
{
std::ostringstream out;
out << "unknown atomic proposition \"" << *$2 << "\"";
error(@1, out.str());
f = spot::ltl::default_environment::instance()
.require("$unknown$");