Add support the bounded star operator [*i..j].

* src/ltlast/bunop.hh, src/ltlast/bunop.cc: New files for
bounded unary operators.
* src/ltlast/Makefile.am, src/ltlast/allnodes.hh: Add them.
* src/ltlast/predecl.hh (bunop): Declare.
* src/ltlast/unop.hh, src/ltlast/unop.cc (Star): Remove
declaration of Star and associated code.
* src/ltlast/visitor.hh: Add visit(bunop* node) methods.
* src/ltlparse/ltlparse.yy, src/ltlparse/ltlscan.ll: Add parse
rules for LTL.  This required passing the parse_error list
to the lexer, so it can report scanning errors when it reads
a number that does not fit in an unsigned int.
* src/ltlparse/parsedecl.hh (YY_DECL): Take error_list
as third argument.
* src/ltltest/consterm.test, src/ltltest/tostring.test,
src/ltltest/equals.test, src/tgbatest/ltl2tgba.test: More tests.
* src/ltlvisit/basicreduce.cc, src/ltlvisit/clone.cc,
src/ltlvisit/clone.hh, src/ltlvisit/consterm.cc,
src/ltlvisit/dotty.cc, src/ltlvisit/mark.cc,
src/ltlvisit/nenoform.cc, src/ltlvisit/postfix.cc,
src/ltlvisit/postfix.hh, src/ltlvisit/reduce.cc,
src/ltlvisit/syntimpl.cc, src/ltlvisit/tostring.cc,
src/ltlvisit/tunabbrev.cc, src/tgba/formula2bdd.cc,
src/tgbaalgos/eltl2tgba_lacim.cc, src/tgbaalgos/ltl2taa.cc,
src/tgbaalgos/ltl2tgba_lacim.cc: Adjust syntax to use
"bunop::Star" instead of "unop::Star".
* src/tgbaalgos/ltl2tgba_fm.cc: Likewise, but also adjust
the code to handle the bounds of the operator.
This commit is contained in:
Alexandre Duret-Lutz 2010-05-12 19:09:20 +02:00
parent 47b2bea865
commit 126b724a98
33 changed files with 678 additions and 115 deletions

View file

@ -28,12 +28,15 @@
%debug
%error-verbose
%expect 0
%lex-param { spot::ltl::parse_error_list& error_list }
%code requires
{
#include <string>
#include "public.hh"
#include "ltlast/allnodes.hh"
struct minmax_t { unsigned min, max; };
}
%parse-param {spot::ltl::parse_error_list &error_list}
@ -43,6 +46,8 @@
{
std::string* str;
spot::ltl::formula* ltl;
unsigned num;
minmax_t minmax;
}
%code {
@ -85,6 +90,10 @@ using namespace spot::ltl;
%token OP_W "weak until operator" OP_M "strong release operator"
%token OP_F "sometimes operator" OP_G "always operator"
%token OP_X "next operator" OP_NOT "not operator" OP_STAR "star operator"
%token OP_STAR_OPEN "opening bracket for star operator"
%token OP_STAR_CLOSE "closing bracket for star operator"
%token <num> OP_STAR_NUM "number for star operator"
%token OP_STAR_SEP "separator for star operator"
%token OP_UCONCAT "universal concat operator"
%token OP_ECONCAT "existential concat operator"
%token OP_UCONCAT_NONO "universal non-overlapping concat operator"
@ -92,7 +101,7 @@ using namespace spot::ltl;
%token <str> ATOMIC_PROP "atomic proposition"
%token OP_CONCAT "concat operator" OP_FUSION "fusion operator"
%token CONST_TRUE "constant true" CONST_FALSE "constant false"
%token END_OF_INPUT "end of formula" CONST_EMPTYWORD "empty word"
%token END_OF_INPUT "end of formula"
%token OP_POST_NEG "negative suffix" OP_POST_POS "positive suffix"
/* Priorities. */
@ -114,7 +123,7 @@ using namespace spot::ltl;
%nonassoc OP_X
/* High priority regex operator. */
%nonassoc OP_STAR
%nonassoc OP_STAR OP_STAR_OPEN
/* Not has the most important priority after Wring's `=0' and `=1'. */
%nonassoc OP_NOT
@ -123,6 +132,7 @@ using namespace spot::ltl;
%type <ltl> subformula booleanatom rationalexp
%type <ltl> bracedrationalexp parenthesedsubformula
%type <minmax> starargs
%destructor { delete $$; } <str>
%destructor { $$->destroy(); } <ltl>
@ -175,6 +185,32 @@ enderror: error END_OF_INPUT
"ignoring trailing garbage"));
}
OP_STAR_SEP_opt: | OP_STAR_SEP
error_opt: | error
starargs: OP_STAR
{ $$.min = 0U; $$.max = bunop::unbounded; }
| OP_STAR_OPEN OP_STAR_NUM OP_STAR_SEP OP_STAR_NUM OP_STAR_CLOSE
{ $$.min = $2; $$.max = $4; }
| OP_STAR_OPEN OP_STAR_NUM OP_STAR_SEP OP_STAR_CLOSE
{ $$.min = $2; $$.max = bunop::unbounded; }
| OP_STAR_OPEN OP_STAR_SEP OP_STAR_NUM OP_STAR_CLOSE
{ $$.min = 0U; $$.max = $3; }
| OP_STAR_OPEN OP_STAR_SEP_opt OP_STAR_CLOSE
{ $$.min = 0U; $$.max = bunop::unbounded; }
| OP_STAR_OPEN OP_STAR_NUM OP_STAR_CLOSE
{ $$.min = $2; $$.max = $2; }
| OP_STAR_OPEN error OP_STAR_CLOSE
{ error_list.push_back(parse_error(@$,
"treating this star block as [*]"));
$$.min = 0U; $$.max = bunop::unbounded; }
| OP_STAR_OPEN error_opt END_OF_INPUT
{ error_list.push_back(parse_error(@$,
"missing closing bracket for star"));
$$.min = $$.max = 0U; }
/* The reason we use `constant::false_instance()' for error recovery
is that it isn't reference counted. (Hence it can't leak references.) */
@ -239,8 +275,6 @@ rationalexp: booleanatom
| OP_NOT booleanatom
{ $$ = unop::instance(unop::Not, $2); }
| bracedrationalexp
| CONST_EMPTYWORD
{ $$ = constant::empty_word_instance(); }
| PAR_OPEN rationalexp PAR_CLOSE
{ $$ = $2; }
| PAR_OPEN error PAR_CLOSE
@ -281,10 +315,11 @@ rationalexp: booleanatom
{ $$ = multop::instance(multop::Fusion, $1, $3); }
| rationalexp OP_FUSION error
{ missing_right_binop($$, $1, @2, "fusion operator"); }
| rationalexp OP_STAR
{ $$ = unop::instance(unop::Star, $1); }
| OP_STAR
{ $$ = unop::instance(unop::Star, constant::true_instance()); }
| rationalexp starargs
{ $$ = bunop::instance(bunop::Star, $1, $2.min, $2.max); }
| starargs
{ $$ = bunop::instance(bunop::Star, constant::true_instance(),
$1.min, $1.max); }
bracedrationalexp: BRACE_OPEN rationalexp BRACE_CLOSE
{ $$ = $2; }

View file

@ -27,6 +27,7 @@
%{
#include <string>
#include <boost/lexical_cast.hpp>
#include "ltlparse/parsedecl.hh"
/* Hack Flex so we read from a string instead of reading from a file. */
@ -58,6 +59,7 @@ flex_set_buffer(const char* buf, int start_tok)
%}
%s not_prop
%x star
%%
@ -86,14 +88,33 @@ flex_set_buffer(const char* buf, int start_tok)
"!"|"~" BEGIN(0); return token::OP_NOT;
/* PSL operators */
"[*0]" BEGIN(0); return token::CONST_EMPTYWORD;
"[]->"|"|->" BEGIN(0); return token::OP_UCONCAT;
"<>->" BEGIN(0); return token::OP_ECONCAT;
"[]=>"|"|=>" BEGIN(0); return token::OP_UCONCAT_NONO;
"<>=>" BEGIN(0); return token::OP_ECONCAT_NONO;
"*"|"[*]" BEGIN(0); return token::OP_STAR;
";" BEGIN(0); return token::OP_CONCAT;
":" BEGIN(0); return token::OP_FUSION;
"*"|"[*]" BEGIN(0); return token::OP_STAR;
"[*" BEGIN(star); return token::OP_STAR_OPEN;
<star>"]" BEGIN(0); return token::OP_STAR_CLOSE;
<star>[0-9]+ {
unsigned num = 0;
try {
num = boost::lexical_cast<unsigned>(yytext);
yylval->num = num;
return token::OP_STAR_NUM;
}
catch (boost::bad_lexical_cast &)
{
error_list.push_back(
spot::ltl::parse_error(*yylloc,
"value too large ignored"));
// Skip this number and read next token
yylloc->step();
}
}
<star>","|".." return token::OP_STAR_SEP;
/* & and | come from Spin. && and || from LTL2BA.
/\, \/, and xor are from LBTT.
@ -122,7 +143,7 @@ flex_set_buffer(const char* buf, int start_tok)
"=0" return token::OP_POST_NEG;
"=1" return token::OP_POST_POS;
[ \t\n]+ /* discard whitespace */ yylloc->step ();
<*>[ \t\n]+ /* discard whitespace */ yylloc->step ();
/* An Atomic proposition cannot start with the letter
used by a unary operator (F,G,X), unless this
@ -142,7 +163,7 @@ flex_set_buffer(const char* buf, int start_tok)
condition we will not consider `Uq' as an atomic proposition but as
a `U' operator followed by a `q' atomic proposition.
We also disable atomic proposition that may look a combination
We also disable atomic proposition that may look like a combination
of a binary operator followed by several unary operators.
E.g. UFXp. This way, `p=0UFXp=1' will be parsed as `(p=0)U(F(X(p=1)))'.
*/
@ -161,7 +182,7 @@ flex_set_buffer(const char* buf, int start_tok)
return token::ATOMIC_PROP;
}
. return *yytext;
<*>. return *yytext;
<<EOF>> return token::END_OF_INPUT;

View file

@ -28,7 +28,9 @@
#include "location.hh"
# define YY_DECL \
int ltlyylex (ltlyy::parser::semantic_type *yylval, ltlyy::location *yylloc)
int ltlyylex (ltlyy::parser::semantic_type *yylval, \
ltlyy::location *yylloc, \
spot::ltl::parse_error_list& error_list)
YY_DECL;
void flex_set_buffer(const char *buf, int start_tok);