Commit e48338e8 authored by Damien Lefortier's avatar Damien Lefortier
Browse files

Modify the ELTL parser to be able to support PSL operators. Add a

new keyword in the ELTL format: finish, which applies to an
automaton operator and tells whether it just completed.

* src/eltlparse/eltlparse.yy: Clean it. Add finish.
* src/eltlparse/eltlscan.ll: Add finish.
* src/formula_tree.cc, src/formula_tree.hh: New files. Define a
small AST representing formulae where atomic props are unknown
which is used in the ELTL parser.
* src/ltlast/automatop.cc, ltlast/automatop.hh, ltlast/nfa.cc,
ltlast/nfa.hh: Adjust.
* src/ltlast/unop.cc, src/ltlast/unop.hh: Finish is an unop.
* src/ltlvisit/basicreduce.cc, src/ltlvisit/nenoform.cc,
src/ltlvisit/reduce.cc, src/ltlvisit/syntimpl.cc,
src/ltlvisit/tostring.cc, src/ltlvisit/tunabbrev.cc,
src/tgba/formula2bdd.cc, src/tgbaalgos/ltl2tgba_fm.cc,
src/tgbaalgos/ltl2tgba_lacim.cc: Handle finish in switches.
* src/tgbaalgos/eltl2tgba_lacim.cc: Translate finish.
* src/tgbatest/eltl2tgba.test: More tests.
parent 4de885af
2009-06-05 Damien Lefortier <dam@lrde.epita.fr>
Modify the ELTL parser to be able to support PSL operators. Add a
new keyword in the ELTL format: finish, which applies to an
automaton operator and tells whether it just completed.
* src/eltlparse/eltlparse.yy: Clean it. Add finish.
* src/eltlparse/eltlscan.ll: Add finish.
* src/formula_tree.cc, src/formula_tree.hh: New files. Define a
small AST representing formulae where atomic props are unknown
which is used in the ELTL parser.
* src/ltlast/automatop.cc, ltlast/automatop.hh, ltlast/nfa.cc,
ltlast/nfa.hh: Adjust.
* src/ltlast/unop.cc, src/ltlast/unop.hh: Finish is an unop.
* src/ltlvisit/basicreduce.cc, src/ltlvisit/nenoform.cc,
src/ltlvisit/reduce.cc, src/ltlvisit/syntimpl.cc,
src/ltlvisit/tostring.cc, src/ltlvisit/tunabbrev.cc,
src/tgba/formula2bdd.cc, src/tgbaalgos/ltl2tgba_fm.cc,
src/tgbaalgos/ltl2tgba_lacim.cc: Handle finish in switches.
* src/tgbaalgos/eltl2tgba_lacim.cc: Translate finish.
* src/tgbatest/eltl2tgba.test: More tests.
2009-06-02 Alexandre Duret-Lutz <adl@lrde.epita.fr>
* src/tgbatest/scc.test: Redirect stdout into file `stdout'
......
......@@ -36,53 +36,22 @@
#include <boost/shared_ptr.hpp>
#include "public.hh"
#include "ltlast/allnodes.hh"
#include "ltlast/formula_tree.hh"
#include "ltlvisit/destroy.hh"
#include "ltlvisit/clone.hh"
namespace spot
{
namespace eltl
{
typedef std::map<std::string, nfa::ptr> nfamap;
/// The following parser allows one to define aliases of automaton
/// operators such as: F=U(true,$0). Internally it's handled by
/// creating a small AST associated with each alias in order to
/// instanciate the right automatop after: U(constant(1), AP(f))
/// for the formula F(f).
///
struct alias
{
virtual ~alias() {};
};
/// We use boost::shared_ptr to easily handle deletion.
typedef boost::shared_ptr<alias> alias_ptr;
struct alias_not : alias
{
alias_ptr child;
};
struct alias_binop : alias
{
binop::type op;
alias_ptr lhs;
alias_ptr rhs;
};
struct alias_multop : alias
{
multop::type op;
alias_ptr lhs;
alias_ptr rhs;
};
struct alias_nfa : alias
{
std::vector<alias_ptr> children;
spot::ltl::nfa::ptr nfa;
};
struct alias_arg : alias
{
int i;
};
typedef std::map<std::string, nfa::ptr> nfamap;
typedef std::map<std::string, alias_ptr> aliasmap;
typedef std::map<std::string, formula_tree::node_ptr> aliasmap;
/// Implementation details for error handling.
struct parse_error_list_t
......@@ -91,104 +60,51 @@ namespace spot
std::string file_;
};
/// TODO: maybe implementing a visitor could be better than
/// dynamic casting all the time here.
/// Instanciate the formula corresponding to the given alias.
static formula*
alias2formula(const alias_ptr ap, spot::ltl::automatop::vec* v)
{
if (alias_not* a = dynamic_cast<alias_not*>(ap.get()))
return unop::instance(unop::Not, alias2formula(a->child, v));
if (alias_arg* a = dynamic_cast<alias_arg*>(ap.get()))
return a->i == -1 ? constant::true_instance() :
a->i == -2 ? constant::false_instance() : v->at(a->i);
if (alias_nfa* a = dynamic_cast<alias_nfa*>(ap.get()))
{
automatop::vec* va = new automatop::vec;
std::vector<alias_ptr>::const_iterator i = a->children.begin();
while (i != a->children.end())
va->push_back(alias2formula(*i++, v));
return automatop::instance(a->nfa, va, false);
}
if (alias_binop* a = dynamic_cast<alias_binop*>(ap.get()))
return binop::instance(a->op,
alias2formula(a->lhs, v),
alias2formula(a->rhs, v));
if (alias_multop* a = dynamic_cast<alias_multop*>(ap.get()))
return multop::instance(a->op,
alias2formula(a->lhs, v),
alias2formula(a->rhs, v));
/* Unreachable code. */
assert(0);
}
/// Get the arity of a given alias.
static size_t
arity(const alias_ptr ap)
{
if (alias_not* a = dynamic_cast<alias_not*>(ap.get()))
return arity(a->child);
if (alias_arg* a = dynamic_cast<alias_arg*>(ap.get()))
return std::max(a->i + 1, 0);
if (alias_nfa* a = dynamic_cast<alias_nfa*>(ap.get()))
{
size_t res = 0;
std::vector<alias_ptr>::const_iterator i = a->children.begin();
while (i != a->children.end())
res = std::max(arity(*i++), res);
return res;
}
if (alias_binop* a = dynamic_cast<alias_binop*>(ap.get()))
return std::max(arity(a->lhs), arity(a->rhs));
if (alias_multop* a = dynamic_cast<alias_multop*>(ap.get()))
return std::max(arity(a->lhs), arity(a->rhs));
/* Unreachable code. */
assert(0);
}
using namespace spot::ltl::formula_tree;
/// Alias an existing alias, as in Strong=G(F($0))->G(F($1)),
/// where F is an alias.
///
/// \param ap The original alias.
/// \param v The arguments of the new alias.
static alias_ptr
realias(const alias_ptr ap, std::vector<alias_ptr> v)
static node_ptr
realias(const node_ptr ap, std::vector<node_ptr> v)
{
if (alias_not* a = dynamic_cast<alias_not*>(ap.get()))
if (node_atomic* a = dynamic_cast<node_atomic*>(ap.get())) // Do it.
return a->i < 0 ? ap : v.at(a->i);
// Traverse the tree.
if (node_unop* a = dynamic_cast<node_unop*>(ap.get()))
{
alias_not* res = new alias_not;
node_unop* res = new node_unop;
res->op = a->op;
res->child = realias(a->child, v);
return alias_ptr(res);
return node_ptr(res);
}
if (alias_arg* a = dynamic_cast<alias_arg*>(ap.get())) // Do it.
return a->i < 0 ? ap : v.at(a->i);
if (alias_nfa* a = dynamic_cast<alias_nfa*>(ap.get()))
if (node_nfa* a = dynamic_cast<node_nfa*>(ap.get()))
{
alias_nfa* res = new alias_nfa;
std::vector<alias_ptr>::const_iterator i = a->children.begin();
node_nfa* res = new node_nfa;
std::vector<node_ptr>::const_iterator i = a->children.begin();
while (i != a->children.end())
res->children.push_back(realias(*i++, v));
res->nfa = a->nfa;
return alias_ptr(res);
return node_ptr(res);
}
if (alias_binop* a = dynamic_cast<alias_binop*>(ap.get()))
if (node_binop* a = dynamic_cast<node_binop*>(ap.get()))
{
alias_binop* res = new alias_binop;
node_binop* res = new node_binop;
res->op = a->op;
res->lhs = realias(a->lhs, v);
res->rhs = realias(a->rhs, v);
return alias_ptr(res);
return node_ptr(res);
}
if (alias_multop* a = dynamic_cast<alias_multop*>(ap.get()))
if (node_multop* a = dynamic_cast<node_multop*>(ap.get()))
{
alias_multop* res = new alias_multop;
node_multop* res = new node_multop;
res->op = a->op;
res->lhs = realias(a->lhs, v);
res->rhs = realias(a->rhs, v);
return alias_ptr(res);
return node_ptr(res);
}
/* Unreachable code. */
......@@ -235,6 +151,15 @@ namespace spot
} \
}
#define INSTANCIATE_OP(Name, TypeNode, TypeOp, L, R) \
{ \
TypeNode* res = new TypeNode; \
res->op = TypeOp; \
res->lhs = formula_tree::node_ptr(L); \
res->rhs = formula_tree::node_ptr(R); \
Name = res; \
}
}
%parse-param {spot::eltl::nfamap& nmap}
......@@ -254,8 +179,8 @@ namespace spot
spot::ltl::formula* fval;
/// To handle aliases.
spot::eltl::alias* pval;
spot::eltl::alias_nfa* bval;
spot::ltl::formula_tree::node* pval;
spot::ltl::formula_tree::node_nfa* bval;
}
%code {
......@@ -283,6 +208,7 @@ using namespace spot::ltl;
%token ACC "accept"
EQ "="
FIN "finish"
LPAREN "("
RPAREN ")"
COMMA ","
......@@ -304,10 +230,8 @@ using namespace spot::ltl;
%type <nval> nfa_def
%type <fval> subformula
%type <aval> arg_list
%type <ival> nfa_arg
%type <pval> nfa_alias
%type <pval> nfa_alias_arg
%type <bval> nfa_alias_arg_list
%type <pval> nfa_arg
%type <bval> nfa_arg_list
%destructor { delete $$; } "atomic proposition"
%destructor { spot::ltl::destroy($$); } subformula
......@@ -335,7 +259,7 @@ nfa: IDENT "=" "(" nfa_def ")"
nmap[*$1] = nfa::ptr($4);
delete $1;
}
| IDENT "=" nfa_alias
| IDENT "=" nfa_arg
{
/// Recursivity issues of aliases are handled by a parse error.
aliasmap::iterator i = amap.find(*$1);
......@@ -348,7 +272,7 @@ nfa: IDENT "=" "(" nfa_def ")"
delete $1;
YYERROR;
}
amap[*$1] = alias_ptr($3);
amap.insert(make_pair(*$1, formula_tree::node_ptr($3)));
delete $1;
}
;
......@@ -359,7 +283,7 @@ nfa_def: /* empty */
}
| nfa_def STATE STATE nfa_arg
{
$1->add_transition($2, $3, $4);
$1->add_transition($2, $3, formula_tree::node_ptr($4));
$$ = $1;
}
| nfa_def ACC STATE
......@@ -369,102 +293,108 @@ nfa_def: /* empty */
}
;
nfa_alias: IDENT "(" nfa_alias_arg_list ")"
{
aliasmap::const_iterator i = amap.find(*$1);
if (i != amap.end())
nfa_arg_list: nfa_arg
{
CHECK_ARITY(@1, $1, $3->children.size(), arity(i->second));
// Hack to return the right type without screwing with the
// boost::shared_ptr memory handling by using get for
// example. FIXME: Wait for the next version of boost and
// modify the %union to handle alias_ptr.
alias_not* tmp1 = new alias_not;
tmp1->child = realias(i->second, $3->children);
alias_not* tmp2 = new alias_not;
tmp2->child = alias_ptr(tmp1);
$$ = tmp2;
delete $3;
$$ = new formula_tree::node_nfa;
$$->children.push_back(formula_tree::node_ptr($1));
}
else
| nfa_arg_list "," nfa_arg
{
CHECK_EXISTING_NMAP(@1, $1);
nfa::ptr np = nmap[*$1];
CHECK_ARITY(@1, $1, $3->children.size(), np->arity());
$3->nfa = np;
$$ = $3;
}
delete $1;
$1->children.push_back(formula_tree::node_ptr($3));
$$ = $1;
}
| OP_NOT nfa_alias
;
nfa_arg: ARG
{
alias_not* res = new alias_not;
res->child = alias_ptr($2);
if ($1 == -1)
{
std::string s = "out of range integer";
PARSE_ERROR(@1, s);
YYERROR;
}
formula_tree::node_atomic* res = new formula_tree::node_atomic;
res->i = $1;
$$ = res;
}
| nfa_alias OP_IMPLIES nfa_alias
| CONST_TRUE
{
alias_binop* res = new alias_binop;
res->op = binop::Implies;
res->lhs = alias_ptr($1);
res->rhs = alias_ptr($3);
formula_tree::node_atomic* res = new formula_tree::node_atomic;
res->i = formula_tree::True;
$$ = res;
}
// More TBD here.
nfa_alias_arg: nfa_arg
| CONST_FALSE
{
alias_arg* res = new alias_arg;
res->i = $1;
formula_tree::node_atomic* res = new formula_tree::node_atomic;
res->i = formula_tree::False;
$$ = res;
}
| CONST_FALSE
| OP_NOT nfa_arg
{
alias_arg* res = new alias_arg;
res->i = -2;
formula_tree::node_unop* res = new formula_tree::node_unop;
res->op = unop::Not;
res->child = formula_tree::node_ptr($2);
$$ = res;
}
| OP_NOT nfa_alias_arg
| FIN "(" nfa_arg ")"
{
alias_not* res = new alias_not;
res->child = alias_ptr($2);
formula_tree::node_unop* res = new formula_tree::node_unop;
res->op = unop::Finish;
res->child = formula_tree::node_ptr($3);
$$ = res;
}
// More TBD here.
nfa_alias_arg_list: nfa_alias_arg
| nfa_arg OP_AND nfa_arg
{
$$ = new alias_nfa;
$$->children.push_back(alias_ptr($1));
INSTANCIATE_OP($$, formula_tree::node_multop, multop::And, $1, $3);
}
| nfa_alias // Cannot factorize because <pval> != <bval>.
| nfa_arg OP_OR nfa_arg
{
$$ = new alias_nfa;
$$->children.push_back(alias_ptr($1));
INSTANCIATE_OP($$, formula_tree::node_multop, multop::Or, $1, $3);
}
| nfa_alias_arg_list "," nfa_alias_arg
| nfa_arg OP_XOR nfa_arg
{
$1->children.push_back(alias_ptr($3));
$$ = $1;
INSTANCIATE_OP($$, formula_tree::node_binop, binop::Xor, $1, $3);
}
;
nfa_arg: ARG
| nfa_arg OP_IMPLIES nfa_arg
{
if ($1 == -1)
INSTANCIATE_OP($$, formula_tree::node_binop, binop::Implies, $1, $3);
}
| nfa_arg OP_EQUIV nfa_arg
{
std::string s = "out of range integer";
PARSE_ERROR(@1, s);
YYERROR;
INSTANCIATE_OP($$, formula_tree::node_binop, binop::Equiv, $1, $3);
}
$$ = $1;
| IDENT "(" nfa_arg_list ")"
{
aliasmap::const_iterator i = amap.find(*$1);
if (i != amap.end())
{
int arity = formula_tree::arity(i->second);
CHECK_ARITY(@1, $1, $3->children.size(), arity);
// Hack to return the right type without screwing with the
// boost::shared_ptr memory handling by using get for
// example. FIXME: Wait for the next version of boost and
// modify the %union to handle formula_tree::node_ptr.
formula_tree::node_unop* tmp1 = new formula_tree::node_unop;
tmp1->op = unop::Not;
tmp1->child = realias(i->second, $3->children);
formula_tree::node_unop* tmp2 = new formula_tree::node_unop;
tmp2->op = unop::Not;
tmp2->child = formula_tree::node_ptr(tmp1);
$$ = tmp2;
delete $3;
}
| CONST_TRUE
{ $$ = -1; }
;
else
{
CHECK_EXISTING_NMAP(@1, $1);
nfa::ptr np = nmap[*$1];
CHECK_ARITY(@1, $1, $3->children.size(), np->arity());
$3->nfa = np;
$$ = $3;
}
delete $1;
}
/* Formulae. */
......@@ -490,12 +420,11 @@ subformula: ATOMIC_PROP
aliasmap::iterator i = amap.find(*$2);
if (i != amap.end())
{
CHECK_ARITY(@1, $2, 2, arity(i->second));
automatop::vec* v = new automatop::vec;
v->push_back($1);
v->push_back($3);
$$ = alias2formula(i->second, v);
delete v;
CHECK_ARITY(@1, $2, 2, formula_tree::arity(i->second));
automatop::vec v;
v.push_back($1);
v.push_back($3);
$$ = instanciate(i->second, v);
}
else
{
......@@ -514,8 +443,8 @@ subformula: ATOMIC_PROP
aliasmap::iterator i = amap.find(*$1);
if (i != amap.end())
{
CHECK_ARITY(@1, $1, $3->size(), arity(i->second));
$$ = alias2formula(i->second, $3);
CHECK_ARITY(@1, $1, $3->size(), formula_tree::arity(i->second));
$$ = instanciate(i->second, *$3);
delete $3;
}
else
......
......@@ -101,6 +101,7 @@ eol \n|\r|\n\r|\r\n
<INITIAL>"=" return token::EQ;
<IINTIAL>"accept" return token::ACC;
<IINTIAL>"finish" return token::FIN;
<INITIAL>[tT][rR][uU][eE] {
return token::CONST_TRUE;
......
......@@ -31,6 +31,7 @@ ltlast_HEADERS = \
binop.hh \
constant.hh \
formula.hh \
formula_tree.hh \
multop.hh \
nfa.hh \
predecl.hh \
......@@ -45,6 +46,7 @@ libltlast_la_SOURCES = \
binop.cc \
constant.cc \
formula.cc \
formula_tree.cc \
multop.cc \
nfa.cc \
refformula.cc \
......
......@@ -21,6 +21,7 @@
#include <iostream>
#include "automatop.hh"
#include "nfa.hh"
#include "visitor.hh"
namespace spot
......
......@@ -88,11 +88,11 @@ namespace spot
typedef std::map<triplet, formula*, paircmp> map;
static map instances;
automatop(const nfa::ptr nfa, vec* v, bool negated);
automatop(const nfa::ptr, vec* v, bool negated);
virtual ~automatop();
private:
nfa::ptr nfa_;
const nfa::ptr nfa_;
vec* children_;
bool negated_;
};
......
// Copyright (C) 2009 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
// 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 2 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 Spot; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
#include <cassert>
#include "formula_tree.hh"
#include "allnodes.hh"
#include "ltlvisit/clone.hh"
namespace spot
{
namespace ltl
{
namespace formula_tree
{
formula*
instanciate(const node_ptr np, const std::vector<formula*>& v)
{
if (node_atomic* n = dynamic_cast<node_atomic*>(np.get()))
return n->i == True ? constant::true_instance() :
n->i == False ? constant::false_instance() : clone(v.at(n->i));
if (node_unop* n = dynamic_cast<node_unop*>(np.get()))
return unop::instance(n->op, instanciate(n->child, v));
if (node_nfa* n = dynamic_cast<node_nfa*>(np.get()))
{
automatop::vec* va = new automatop::vec;
std::vector<node_ptr>::const_iterator i = n->children.begin();
while (i != n->children.end())
va->push_back(instanciate(*i++, v));
return automatop::instance(n->nfa, va, false);
}
if (node_binop* n = dynamic_cast<node_binop*>(np.get()))
return binop::instance(n->op,
instanciate(n->lhs, v),
instanciate(n->rhs, v));
if (node_multop* n = dynamic_cast<node_multop*>(np.get()))
return multop::instance(n->op,
instanciate(n->lhs, v),
instanciate(n->rhs, v));
/* Unreachable code. */
assert(0);
}
size_t
arity(const node_ptr np)
{
if (node_atomic* n = dynamic_cast<node_atomic*>(np.get()))
return std::max(n->i + 1, 0);
if (node_unop* n = dynamic_cast<node_unop*>(np.get()))
return arity(n->child);
if (node_nfa* n = dynamic_cast<node_nfa*>(np.get()))
{
size_t res = 0;
std::vector<node_ptr>::const_iterator i = n->children.begin();
while (i != n->children.end())
res = std::max(arity(*i++), res);
return res;
}
if (node_binop* n = dynamic_cast<node_binop*>(np.get()))
return std::max(arity(n->lhs), arity(n->rhs));
if (node_multop* n = dynamic_cast<node_multop*>(np.get()))
return std::max(arity(n->lhs), arity(n->rhs));
/* Unreachable code. */
assert(0);
}
}
}
}
// Copyright (C) 2009 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
// 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 2 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 Spot; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.