hoa: preliminary implementation of a parser

* src/hoaparse/Makefile.am, src/hoaparse/fmterror.cc,
src/hoaparse/hoaparse.yy, src/hoaparse/hoascan.ll,
src/hoaparse/parsedecl.hh, src/hoaparse/public.hh: New files.
* src/Makefile.am, configure.ac, README: Adjust.
* src/tgbatest/ltl2tgba.cc: Add a -XH option.
* src/tgbatest/hoaparse.test: New file.
* src/tgbatest/Makefile.am: Adjust.
* buddy/src/bddx.h: Add a bdd_from_int() function.
This commit is contained in:
Alexandre Duret-Lutz 2014-11-18 18:48:36 +01:00
parent e1d4522ca9
commit e55bcd95aa
14 changed files with 1138 additions and 3 deletions

1
README
View file

@ -142,6 +142,7 @@ src/ Sources for libspot.
dstarparse/ Parser for the output of ltl2dstar.
graph/ Graph representations.
graphtest/ Graph representations.
hoaparse/ Parser for the HOA format.
kripke/ Kripke Structure interface.
kripkeparse/ Parser for explicit Kripke.
kripketest/ Tests for kripke explicit.

View file

@ -573,6 +573,7 @@ protected:
friend bdd bdd_makesetpp(int *, int);
friend int bdd_setbddpair(bddPair*, int, const bdd &);
friend int bdd_setbddpairs(bddPair*, int*, const bdd *, int);
friend bdd bdd_from_int(int i);
friend bdd bdd_buildcube(int, int, const bdd *);
friend bdd bdd_ibuildcubepp(int, int, int *);
friend bdd bdd_not(const bdd &);
@ -715,6 +716,9 @@ inline bdd bdd_makesetpp(int *v, int n)
inline int bdd_setbddpair(bddPair *p, int ov, const bdd &nv)
{ return bdd_setbddpair(p,ov,nv.root); }
inline bdd bdd_from_int(int i)
{ return i; }
/* In bddop.c */
inline bdd bdd_replace(const bdd &r, bddPair *p)

View file

@ -180,6 +180,7 @@ AC_CONFIG_FILES([
src/graph/Makefile
src/graphtest/Makefile
src/graphtest/defs
src/hoaparse/Makefile
src/ltlast/Makefile
src/ltlenv/Makefile
src/ltlparse/Makefile

View file

@ -27,14 +27,15 @@ AUTOMAKE_OPTIONS = subdir-objects
# libspot.la needed by the tests)
SUBDIRS = misc priv ltlenv ltlast ltlvisit ltlparse graph tgba \
tgbaalgos tgbaparse ta taalgos kripke neverparse \
kripkeparse dstarparse . bin ltltest graphtest tgbatest \
kripketest sanity
kripkeparse dstarparse hoaparse . bin ltltest graphtest \
tgbatest kripketest sanity
lib_LTLIBRARIES = libspot.la
libspot_la_SOURCES =
libspot_la_LDFLAGS = $(BUDDY_LDFLAGS) -no-undefined
libspot_la_LIBADD = \
dstarparse/libdstarparse.la \
hoaparse/libhoaparse.la \
kripke/libkripke.la \
kripkeparse/libkripkeparse.la \
ltlast/libltlast.la \

7
src/hoaparse/.gitignore vendored Normal file
View file

@ -0,0 +1,7 @@
position.hh
hoaparse.cc
hoaparse.output
hoaparse.hh
hoascan.cc
stack.hh
location.hh

57
src/hoaparse/Makefile.am Normal file
View file

@ -0,0 +1,57 @@
## -*- coding: utf-8 -*-
## Copyright (C) 2013, 2014 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=)
hoaparsedir = $(pkgincludedir)/hoaparse
hoaparse_HEADERS = public.hh
noinst_LTLIBRARIES = libhoaparse.la
HOAPARSE_YY = hoaparse.yy
FROM_HOAPARSE_YY_MAIN = hoaparse.cc
FROM_HOAPARSE_YY_OTHERS = \
stack.hh \
hoaparse.hh
FROM_HOAPARSE_YY = $(FROM_HOAPARSE_YY_MAIN) $(FROM_HOAPARSE_YY_OTHERS)
BUILT_SOURCES = $(FROM_HOAPARSE_YY)
MAINTAINERCLEANFILES = $(FROM_HOAPARSE_YY)
$(FROM_HOAPARSE_YY_MAIN): $(srcdir)/$(HOAPARSE_YY)
## We must cd into $(srcdir) first because if we tell bison to read
## $(srcdir)/$(HOAPARSE_YY), it will also use the value of $(srcdir)/
## in the generated include statements.
cd $(srcdir) && \
$(BISON) -Wall -Werror --report=all $(BISON_EXTRA_FLAGS) \
$(HOAPARSE_YY) -o $(FROM_HOAPARSE_YY_MAIN)
$(FROM_HOAPARSE_YY_OTHERS): $(HOAPARSE_YY)
@test -f $@ || $(MAKE) $(AM_MAKEFLAGS) $(FROM_HOAPARSE_YY_MAIN)
EXTRA_DIST = $(HOAPARSE_YY)
libhoaparse_la_SOURCES = \
fmterror.cc \
$(FROM_HOAPARSE_YY) \
hoascan.ll \
parsedecl.hh

42
src/hoaparse/fmterror.cc Normal file
View file

@ -0,0 +1,42 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2013, 2014 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/>.
#include <ostream>
#include "public.hh"
namespace spot
{
bool
format_hoa_parse_errors(std::ostream& os,
const std::string& filename,
hoa_parse_error_list& error_list)
{
bool printed = false;
spot::hoa_parse_error_list::iterator it;
for (it = error_list.begin(); it != error_list.end(); ++it)
{
if (filename != "-")
os << filename << ':';
os << it->first << ": ";
os << it->second << std::endl;
printed = true;
}
return printed;
}
}

506
src/hoaparse/hoaparse.yy Normal file
View file

@ -0,0 +1,506 @@
/* -*- coding: utf-8 -*-
** Copyright (C) 2014 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 "hoayy"
%debug
%error-verbose
%lex-param { spot::hoa_parse_error_list& error_list }
%define api.location.type "spot::location"
%code requires
{
#include <string>
#include <cstring>
#include <sstream>
#include "ltlast/constant.hh"
#include "public.hh"
struct result_
{
spot::hoa_aut_ptr h;
spot::ltl::environment* env;
std::vector<int> ap;
spot::location states_loc;
spot::location ap_loc;
spot::location state_label_loc;
spot::location start_loc;
spot::location accset_loc;
unsigned cur_state;
int start = -1;
int states = -1;
int ap_count = -1;
int accset = -1;
bdd state_label;
bdd cur_label;
bool has_state_label = false;
bool has_trans_label = false;
spot::acc_cond::mark_t acc_state;
};
}
%parse-param {spot::hoa_parse_error_list& error_list}
%parse-param {result_& res}
%union
{
std::string* str;
unsigned int num;
int b;
spot::acc_cond::mark_t mark;
}
%code
{
#include <sstream>
/* hoaparse.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"
}
%token HOA "HOA:"
%token STATES "States:"
%token START "Start:"
%token AP "AP:"
%token ALIAS "Alias:"
%token ACCEPTANCE "Acceptance:"
%token ACCNAME "acc-name:"
%token TOOL "tool:"
%token NAME "name:"
%token PROPERTIES "properties:"
%token BODY "--BODY--"
%token END "--END--"
%token STATE "State:";
%token <str> IDENTIFIER "identifier";
%token <str> HEADERNAME "header name";
%token <str> ANAME "alias name";
%token <str> STRING "string";
%token <num> INT "integer";
%left '|'
%left '&'
%nonassoc '!'
%type <num> state-num acc-set
%type <b> label-expr
%type <mark> acc-sig_opt acc-sets
%destructor { delete $$; } <str>
%destructor { bdd_delref($$); } <b>
%printer {
if ($$)
debug_stream() << *$$;
else
debug_stream() << "\"\""; } <str>
%printer { debug_stream() << $$; } <num>
%%
hoa: header "--BODY--" body "--END--"
string_opt: | STRING
BOOLEAN: 't' | 'f'
header: format-version header-items
{
if (res.accset < 0)
{
error(@$, "missing 'Acceptance:' header");
YYABORT;
}
}
format-version: "HOA:" IDENTIFIER
{
if (*$2 != "v1")
error(@$, "unsupported version of the HOA format");
delete $2;
}
header-items: | header-items header-item
header-item: "States:" INT
{
if (res.states >= 0)
{
error(@$, "redefinition of the number of states...");
error(res.states_loc, "... previously defined here.");
}
else
{
res.states_loc = @$;
}
if (((int) $2) < 0)
{
error(@$, "too many states for this implementation");
YYABORT;
}
res.states = std::max(res.states, (int) $2);
if (res.states <= res.start)
{
error(res.start_loc,
"initial state number is larger than state count...");
error(@$, "... declared here.");
YYABORT;
}
int missing = res.states - res.h->aut->num_states();
assert(missing >= 0);
res.h->aut->new_states(missing);
}
| "Start:" state-conj-2
{
res.start_loc = @$;
error(@2, "alternation is not yet supported");
YYABORT;
}
| "Start:" state-num
{
if (res.start >= 0)
{
error(@$, "multiple initial states are not yet supported");
YYABORT;
}
res.start = $2;
res.start_loc = @$;
}
| "AP:" INT {
if (res.ap_count != -1)
{
error(@1, "redeclaration of APs...");
error(res.ap_loc, "... previously defined here.");
YYABORT;
}
res.ap_count = $2; res.ap.reserve($2);
}
ap-names
{
res.ap_loc = @1 + @2;
if ((int) res.ap.size() != res.ap_count)
{
std::ostringstream out;
out << "found " << res.ap.size()
<< " atomic propositions instead of the "
<< res.ap_count << " announced";
error(@$, out.str());
}
}
| "Alias:" ANAME label-expr
{
delete $2;
bdd_delref($3);
}
| "Acceptance:" INT
{
if (res.accset >= 0)
{
error(@1 + @2, "redefinition of the acceptance condition...");
error(res.accset_loc, "... previously defined here.");
YYABORT;
}
else if ($2 > 8 * sizeof(spot::acc_cond::mark_t::value_t))
{
error(@1 + @2,
"this implementation cannot support such a large "
"number of acceptance sets");
YYABORT;
}
else
{
res.h->aut->acc().add_sets($2);
res.accset = $2;
res.accset_loc = @1 + @2;
}
}
acceptance-cond
| "acc-name:" IDENTIFIER acc-spec
{
delete $2;
}
| "tool:" STRING string_opt
{
delete $2;
}
| "name:" STRING
{
delete $2;
}
| "properties:" properties
| HEADERNAME header-spec
ap-names: | ap-names ap-name
ap-name: STRING
{
auto f = res.env->require(*$1);
if (f == nullptr)
{
std::ostringstream out;
out << "unknown atomic proposition \"" << *$1 << "\"";
delete $1;
error(@1, out.str());
YYABORT;
}
delete $1;
auto b =
res.h->aut->get_dict()->register_proposition(f, res.h->aut);
f->destroy();
res.ap.push_back(b);
}
acc-spec: | acc-spec BOOLEAN
| acc-spec INT
| acc-spec IDENTIFIER
{
delete $2;
}
properties: | properties IDENTIFIER
{
delete $2;
}
header-spec: | header-spec BOOLEAN
| header-spec INT
| header-spec STRING
{
delete $2;
}
| header-spec IDENTIFIER
{
delete $2;
}
state-conj-2: state-num '&' state-num | state-conj-2 '&' state-num
label-expr: 't'
{
$$ = bddtrue.id();
}
| 'f'
{
$$ = bddfalse.id();
}
| INT
{
if ($1 >= res.ap.size())
{
error(@1, "AP number is larger than the number of APs...");
error(res.ap_loc, "... declared here");
$$ = bddtrue.id();
}
else
{
$$ = bdd_ithvar(res.ap[$1]).id();
bdd_addref($$);
}
}
| ANAME
{
delete $1;
error(@1, "aliases are not yet supported");
YYABORT;
$$ = 0;
}
| '!' label-expr
{
$$ = bdd_not($2);
bdd_delref($2);
bdd_addref($$);
}
| label-expr '&' label-expr
{
$$ = bdd_and($1, $3);
bdd_delref($1);
bdd_delref($3);
bdd_addref($$);
}
| label-expr '|' label-expr
{
$$ = bdd_or($1, $3);
bdd_delref($1);
bdd_delref($3);
bdd_addref($$);
}
acc-set: INT
{
if ((int) $1 >= res.accset)
{
error(@1, "number is larger than the count "
"of acceptance sets...");
error(res.accset_loc, "... declared here.");
YYABORT;
}
$$ = $1;
}
acceptance-cond: IDENTIFIER '(' acc-set ')'
{
if (*$1 != "Inf")
error(@1, "this implementation only supports "
"'Inf' acceptance");
delete $1;
}
| IDENTIFIER '(' '!' acc-set ')'
{
error(@1, "this implementation does not support "
"negated sets");
delete $1;
}
| '(' acceptance-cond ')'
| acceptance-cond '&' acceptance-cond
| acceptance-cond '|' acceptance-cond
{
error(@1, "this implementation does not support "
"disjunction in acceptance conditions");
}
| BOOLEAN
body: states
state-num: INT
{
if (((int) $1) < 0)
{
error(@1, "state number is too large for this implementation");
YYABORT;
}
if ((int) $1 >= res.states)
{
if (res.states >= 0)
{
error(@1, "state number is larger than state count...");
error(res.states_loc, "... declared here.");
}
int missing = ((int) $1) - res.h->aut->num_states() + 1;
if (missing >= 0)
res.h->aut->new_states(missing);
}
$$ = $1;
}
states: | states state
state: state-name edges
state-name: "State:" state-label_opt state-num string_opt acc-sig_opt
{
res.cur_state = $3;
res.acc_state = $5;
}
label: '[' label-expr ']'
{
res.cur_label = bdd_from_int($2);
bdd_delref($2);
}
state-label_opt: { res.has_state_label = false; }
| label { res.has_state_label = true;
res.state_label_loc = @1;
res.state_label = res.cur_label; }
trans-label_opt: { res.has_trans_label = false; }
| label
{
if (res.has_state_label)
{
error(@1, "cannot label this transition because...");
error(res.state_label_loc,
"... the state is already labeled.");
res.has_trans_label = false;
}
else
{
res.has_trans_label = true;
}
}
acc-sig_opt: { $$ = spot::acc_cond::mark_t(0U); }
| '{' acc-sets '}' { $$ = $2; }
acc-sets: { $$ = spot::acc_cond::mark_t(0U); }
| acc-sets acc-set
{
$$ = $1 | res.h->aut->acc().mark($2);
}
edges: | edges edge
edge: trans-label_opt state-num acc-sig_opt
{
bdd cond = bddfalse;
if (res.has_state_label)
cond = res.state_label;
else if (res.has_trans_label)
cond = res.cur_label;
else
error(@$, "unlabeled transitions are not yet supported");
res.h->aut->new_transition(res.cur_state, $2, cond,
$3 | res.acc_state);
}
| trans-label_opt state-conj-2 acc-sig_opt
{
error(@2, "alternation is not yet supported");
YYABORT;
}
%%
void
hoayy::parser::error(const location_type& location,
const std::string& message)
{
error_list.emplace_back(location, message);
}
namespace spot
{
hoa_aut_ptr
hoa_parse(const std::string& name,
hoa_parse_error_list& error_list,
const bdd_dict_ptr& dict,
ltl::environment& env,
bool debug)
{
if (hoayyopen(name))
{
error_list.emplace_back(spot::location(),
std::string("Cannot open file ") + name);
return 0;
}
result_ r;
r.h = std::make_shared<spot::hoa_aut>();
r.h->aut = make_tgba_digraph(dict);
r.env = &env;
hoayy::parser parser(error_list, r);
parser.set_debug_level(debug);
if (parser.parse())
r.h->aut = nullptr;
hoayyclose();
if (!r.h->aut)
return nullptr;
if (r.start != -1)
r.h->aut->set_init_state(r.start);
else
{
// If no initial state has been declared, add one, because
// Spot will not work without one.
r.h->aut->set_init_state(r.h->aut->new_state());
}
return r.h;
}
}
// Local Variables:
// mode: c++
// End:

165
src/hoaparse/hoascan.ll Normal file
View file

@ -0,0 +1,165 @@
/* -*- coding: utf-8 -*-
** Copyright (C) 2014 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/>.
*/
%option noyywrap
%option prefix="hoayy"
%option outfile="lex.yy.c"
/* %option debug */
%{
#include <string>
#include "hoaparse/parsedecl.hh"
#define YY_USER_ACTION yylloc->columns(yyleng);
#define YY_NEVER_INTERACTIVE 1
typedef hoayy::parser::token token;
%}
eol \n+|\r+
eol2 (\n\r)+|(\r\n)+
identifier [[:alpha:]_][[:alnum:]_-]*
%x in_COMMENT in_STRING
%%
%{
std::string s;
yylloc->step();
%}
/* skip blanks and comments */
{eol} yylloc->lines(yyleng); yylloc->step();
{eol2} yylloc->lines(yyleng / 2); yylloc->step();
[ \t\v\f]+ yylloc->step();
"/*" BEGIN(in_COMMENT);
"//".* continue;
"\"" BEGIN(in_STRING);
"HOA:" return token::HOA;
"States:" return token::STATES;
"Start:" return token::START;
"AP:" return token::AP;
"Alias:" return token::ALIAS;
"Acceptance:" return token::ACCEPTANCE;
"acc-name:" return token::ACCNAME;
"tool:" return token::TOOL;
"name:" return token::NAME;
"properties:" return token::PROPERTIES;
"--BODY--" return token::BODY;
"--END--" return token::END;
"State:" return token::STATE;
[tf{}()\[\]&|!] return *yytext;
{identifier} {
yylval->str = new std::string(yytext, yyleng);
return token::IDENTIFIER;
}
{identifier}":" {
yylval->str = new std::string(yytext, yyleng - 1);
return token::HEADERNAME;
}
"@"[[:alnum:]_-]+ {
yylval->str = new std::string(yytext + 1, yyleng - 1);
return token::ANAME;
}
[0-9]+ {
errno = 0;
unsigned long n = strtoul(yytext, 0, 10);
yylval->num = n;
if (errno || yylval->num != n)
{
error_list.push_back(
spot::hoa_parse_error(*yylloc,
"value too large"));
yylval->num = 0;
}
return token::INT;
}
<in_COMMENT>{
[^*\n]* continue;
"*"+[^*/\n]* continue;
"\n"+ yylloc->end.column = 1; yylloc->lines(yyleng);
"*"+"/" BEGIN(INITIAL);
<<EOF>> {
error_list.push_back(
spot::hoa_parse_error(*yylloc,
"unclosed comment"));
return 0;
}
}
<in_STRING>{
\" {
BEGIN(INITIAL);
yylval->str = new std::string(s);
return token::STRING;
}
\\\" s += '"';
\\. s += yytext[1];
[^\\\"]+ s.append(yytext, yyleng);
<<EOF>> {
error_list.push_back(
spot::hoa_parse_error(*yylloc,
"unclosed string"));
return 0;
}
}
. return *yytext;
%{
/* Dummy use of yyunput to shut up a gcc warning. */
(void) &yyunput;
%}
%%
namespace spot
{
int
hoayyopen(const std::string &name)
{
// yy_flex_debug = 1;
if (name == "-")
{
yyin = stdin;
}
else
{
yyin = fopen(name.c_str(), "r");
if (!yyin)
return 1;
}
// Reset the lexer in case a previous parse
// ended badly.
YY_NEW_FILE;
BEGIN(INITIAL);
return 0;
}
void
hoayyclose()
{
fclose(yyin);
}
}

39
src/hoaparse/parsedecl.hh Normal file
View file

@ -0,0 +1,39 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2014 Laboratoire de Recherche et Développement
// de l'EPITA.
//
// 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/>.
#ifndef SPOT_HOAPARSE_PARSEDECL_HH
# define SPOT_HOAPARSE_PARSEDECL_HH
#include <string>
#include "hoaparse.hh"
#include "misc/location.hh"
# define YY_DECL \
int hoayylex(hoayy::parser::semantic_type *yylval, \
spot::location *yylloc, \
spot::hoa_parse_error_list& error_list)
YY_DECL;
namespace spot
{
int hoayyopen(const std::string& name);
void hoayyclose();
}
#endif // SPOT_HOAPARSE_PARSEDECL_HH

92
src/hoaparse/public.hh Normal file
View file

@ -0,0 +1,92 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2013, 2014 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/>.
#ifndef SPOT_HOAPARSE_PUBLIC_HH
# define SPOT_HOAPARSE_PUBLIC_HH
# include "tgba/tgbagraph.hh"
# include "misc/location.hh"
# include "ltlenv/defaultenv.hh"
# include <string>
# include <list>
# include <utility>
# include <iosfwd>
# include <misc/bitvect.hh>
namespace spot
{
/// \addtogroup tgba_io
/// @{
/// \brief A parse diagnostic with its location.
typedef std::pair<spot::location, std::string> hoa_parse_error;
/// \brief A list of parser diagnostics, as filled by parse.
typedef std::list<hoa_parse_error> hoa_parse_error_list;
/// \brief Temporary encoding of an omega automaton produced by
/// ltl2hoa.
struct SPOT_API hoa_aut
{
// Transition structure of the automaton.
// This is encoded as a TGBA without acceptance condition.
tgba_digraph_ptr aut;
};
typedef std::shared_ptr<hoa_aut> hoa_aut_ptr;
typedef std::shared_ptr<const hoa_aut> const_hoa_aut_ptr;
/// \brief Build a spot::tgba_digraph from ltl2hoa's output.
/// \param filename The name of the file to parse.
/// \param error_list A list that will be filled with
/// parse errors that occured during parsing.
/// \param dict The BDD dictionary where to use.
/// \param env The environment of atomic proposition into which parsing
/// should take place.
/// \param debug When true, causes the parser to trace its execution.
/// \return A pointer to the tgba built from \a filename, or
/// 0 if the file could not be opened.
///
/// Note that the parser usually tries to recover from errors. It can
/// return an non zero value even if it encountered error during the
/// parsing of \a filename. If you want to make sure \a filename
/// was parsed succesfully, check \a error_list for emptiness.
///
/// \warning This function is not reentrant.
SPOT_API hoa_aut_ptr
hoa_parse(const std::string& filename,
hoa_parse_error_list& error_list,
const bdd_dict_ptr& dict,
ltl::environment& env = ltl::default_environment::instance(),
bool debug = false);
/// \brief Format diagnostics produced by spot::hoa_parse.
/// \param os Where diagnostics should be output.
/// \param filename The filename that should appear in the diagnostics.
/// \param error_list The error list filled by spot::ltl::parse while
/// parsing \a ltl_string.
/// \return \c true iff any diagnostic was output.
SPOT_API bool
format_hoa_parse_errors(std::ostream& os,
const std::string& filename,
hoa_parse_error_list& error_list);
/// @}
}
#endif // SPOT_HOAPARSE_PUBLIC_HH

View file

@ -84,6 +84,7 @@ TESTS = \
nondet.test \
det.test \
neverclaimread.test \
hoaparse.test \
dstar.test \
readsave.test \
maskacc.test \

198
src/tgbatest/hoaparse.test Executable file
View file

@ -0,0 +1,198 @@
#!/bin/sh
# -*- coding: utf-8 -*-
# Copyright (C) 2014 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/>.
. ./defs
set -e
expecterr()
{
cat >$1.exp
../ltl2tgba -XH $1 2>$1.err && exit 1
test $? = 2
cat $1.err
diff $1.err $1.exp
}
cat >input <<EOF
HOA: v1
States: 1
Start: 0
AP: 1 "a"
States: 2
Acceptance: 1 Inf(0)
--BODY--
State: 0 {0}
[0] 1
State: 1 {0}
[t] 1
--END--
EOF
expecterr input <<EOF
input:5.1-9: redefinition of the number of states...
input:2.1-9: ... previously defined here.
EOF
cat >input <<EOF
HOA: v1
States: 1
Start: 0
AP: 1 "a"
Acceptance: 1 Inf(0)
--BODY--
State: 0 {0}
[0] 1
State: 1 {0}
[t] 1
--END--
EOF
expecterr input <<EOF
input:8.5: state number is larger than state count...
input:2.1-9: ... declared here.
input:9.8: state number is larger than state count...
input:2.1-9: ... declared here.
input:10.5: state number is larger than state count...
input:2.1-9: ... declared here.
EOF
cat >input <<EOF
HOA: v1
States: 0
AP: 1 "a" "b"
Acceptance: 0 t
--BODY--
--END--
EOF
expecterr input <<EOF
input:3.1-13: found 2 atomic propositions instead of the 1 announced
EOF
cat >input <<EOF
HOA: v1
AP: 1 "a"
States: 0
AP: 2 "a" "b"
Acceptance: 0 t
--BODY--
--END--
EOF
expecterr input <<EOF
input:4.1-3: redeclaration of APs...
input:2.1-5: ... previously defined here.
EOF
cat >input <<EOF
HOA: v1
AP: 1 "a"
States: 0
Start: 1
--BODY--
--END--
EOF
expecterr input <<EOF
input:4.8: state number is larger than state count...
input:3.1-9: ... declared here.
input:1.1-4.8: missing 'Acceptance:' header
EOF
cat >input <<EOF
HOA: v1
AP: 1 "a"
Start: 0
States: 0
--BODY--
--END--
EOF
expecterr input <<EOF
input:3.1-8: initial state number is larger than state count...
input:4.1-9: ... declared here.
EOF
cat >input <<EOF
HOA: v1
Acceptance: 1 Inf(0)
Start: 0
States: 1
Acceptance: 1 Inf(0)
--BODY--
--END--
EOF
expecterr input <<EOF
input:5.1-13: redefinition of the acceptance condition...
input:2.1-13: ... previously defined here.
EOF
cat >input <<EOF
HOA: v1
Start: 0
AP: 1 "a"
States: 2
Acceptance: 1 Inf(0)
--BODY--
State: 0 {0}
[0] 1
State: 1 {1}
[t] 1
--END--
EOF
expecterr input <<EOF
input:9.11: number is larger than the count of acceptance sets...
input:5.1-13: ... declared here.
EOF
cat >input <<EOF
HOA: v1
Start: 0
AP: 1 "a"
States: 2
Acceptance: 1 Inf(2)
--BODY--
State: 0 {0}
[0] 1
State: 1 {0}
[t] 1
--END--
EOF
expecterr input <<EOF
input:5.19: number is larger than the count of acceptance sets...
input:5.1-13: ... declared here.
EOF
cat >input <<EOF
HOA: v2
--BODY--
--END--
EOF
expecterr input <<EOF
input:1.1-7: unsupported version of the HOA format
input:1.1-7: missing 'Acceptance:' header
EOF

View file

@ -43,6 +43,7 @@
#include "tgbaparse/public.hh"
#include "neverparse/public.hh"
#include "dstarparse/public.hh"
#include "hoaparse/public.hh"
#include "tgbaalgos/dupexp.hh"
#include "tgbaalgos/minimize.hh"
#include "taalgos/minimize.hh"
@ -128,6 +129,8 @@ syntax(char* prog)
<< "TGBA" << std::endl
<< " -XDD read the from an ltl2dstar file and convert it to "
<< "TGBA,\n keeping it deterministic when possible\n"
<< " -XH do not compute an automaton, read it from a"
<< " HOA file\n"
<< " -XL do not compute an automaton, read it from an"
<< " LBTT file" << std::endl
<< " -XN do not compute an automaton, read it from a"
@ -355,7 +358,8 @@ checked_main(int argc, char** argv)
bool accepting_run = false;
bool accepting_run_replay = false;
bool from_file = false;
enum { ReadSpot, ReadLbtt, ReadNeverclaim, ReadDstar } readformat = ReadSpot;
enum { ReadSpot, ReadLbtt, ReadNeverclaim, ReadDstar, ReadHoa } readformat
= ReadSpot;
bool nra2nba = false;
bool dra2dba = false;
bool scc_filter = false;
@ -923,6 +927,11 @@ checked_main(int argc, char** argv)
nra2nba = true;
dra2dba = true;
}
else if (!strcmp(argv[formula_index], "-XH"))
{
from_file = true;
readformat = ReadHoa;
}
else if (!strcmp(argv[formula_index], "-XL"))
{
from_file = true;
@ -1097,6 +1106,18 @@ checked_main(int argc, char** argv)
tm.stop("dstar2tgba");
}
break;
case ReadHoa:
{
spot::dstar_parse_error_list pel;
tm.start("parsing hoa");
auto daut = spot::hoa_parse(input, pel, dict, env, debug_opt);
tm.stop("parsing hoa");
if (spot::format_hoa_parse_errors(std::cerr, input, pel))
return 2;
a = daut->aut;
assume_sba = false;
}
break;
}
}
else