* HACKING, Makefile.am, configure.ac, m4/gccwarn.m4,
src/Makefile.am, src/ltlast/Makefile.am, src/ltlast/allnodes.hh, src/ltlast/atomic_prop.cc, src/ltlast/atomic_prop.hh, src/ltlast/binop.cc, src/ltlast/binop.hh, src/ltlast/constant.cc, src/ltlast/constant.hh, src/ltlast/formulae.hh, src/ltlast/multop.cc, src/ltlast/multop.hh, src/ltlast/predecl.hh, src/ltlast/unop.cc, src/ltlast/unop.hh, src/ltlast/visitor.hh, src/ltlparse/Makefile.am, src/ltlparse/ltlparse.yy, src/ltlparse/ltlscan.ll, src/ltlparse/parsedecl.hh, src/ltlparse/public.hh, src/ltlvisit/Makefile.am, src/ltlvisit/dotty.cc, src/ltlvisit/dotty.hh, src/ltlvisit/dump.cc, src/ltlvisit/dump.hh, src/ltlvisit/rewrite.cc, src/ltlvisit/rewrite.hh, src/ltltest/Makefile.am, src/ltltest/defs.in, src/ltltest/readltl.cc, src/ltltest/parse.test, src/ltltest/parseerr.test, src/misc/Makefile.am, src/misc/const_sel.hh: New files.
This commit is contained in:
parent
ababb9ff93
commit
f0a8d0aeb3
46 changed files with 1818 additions and 0 deletions
11
src/ltlparse/.cvsignore
Normal file
11
src/ltlparse/.cvsignore
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
.deps
|
||||
Makefile
|
||||
Makefile.in
|
||||
location.hh
|
||||
ltlparse.cc
|
||||
ltlparse.hh
|
||||
ltlparse.output
|
||||
ltlscan.cc
|
||||
position.hh
|
||||
readltl
|
||||
stack.hh
|
||||
27
src/ltlparse/Makefile.am
Normal file
27
src/ltlparse/Makefile.am
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
AM_CPPFLAGS = -I$(srcdir)/..
|
||||
|
||||
lib_LIBRARIES = libltlparse.a
|
||||
|
||||
LTLPARSE_YY = ltlparse.yy
|
||||
FROM_LTLPARSE_YY_MAIN = ltlparse.cc
|
||||
FROM_LTLPARSE_YY_OTHERS = \
|
||||
stack.hh \
|
||||
position.hh \
|
||||
location.hh \
|
||||
ltlparse.hh
|
||||
FROM_LTLPARSE_YY = $(FROM_LTLPARSE_YY_MAIN) $(FROM_LTLPARSE_YY_OTHERS)
|
||||
|
||||
BUILT_SOURCES = $(FROM_LTLPARSE_YY)
|
||||
MAINTAINERCLEANFILES = $(FROM_LTLPARSE_YY)
|
||||
|
||||
$(FROM_LTLPARSE_YY_MAIN): $(srcdir)/$(LTLPARSE_YY)
|
||||
bison --defines --locations --skeleton=lalr1.cc --report=all \
|
||||
$(srcdir)/$(LTLPARSE_YY) -o $@
|
||||
$(FROM_LTLPARSE_YY_OTHERS): $(LTLPARSE_YY)
|
||||
@test -f $@ || $(MAKE) $(AM_MAKEFLAGS) $(FROM_LTLPARSE_YY_MAIN)
|
||||
|
||||
libltlparse_a_SOURCES = \
|
||||
$(FROM_LTLPARSE_YY) \
|
||||
ltlscan.ll \
|
||||
parsedecl.hh \
|
||||
public.hh
|
||||
183
src/ltlparse/ltlparse.yy
Normal file
183
src/ltlparse/ltlparse.yy
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
%{
|
||||
#include <string>
|
||||
#include "public.hh"
|
||||
#include "ltlast/allnodes.hh"
|
||||
|
||||
extern spot::ltl::formulae* result;
|
||||
|
||||
%}
|
||||
|
||||
%debug
|
||||
%error-verbose
|
||||
%union
|
||||
{
|
||||
int token;
|
||||
std::string* str;
|
||||
spot::ltl::formulae* ltl;
|
||||
}
|
||||
|
||||
%{
|
||||
/* Spotparse.hh and parsedecl.hh include each other recursively.
|
||||
We mut ensure that YYSTYPE is declared (by the above %union)
|
||||
before parsedecl.hh uses it. */
|
||||
#include "parsedecl.hh"
|
||||
using namespace spot::ltl;
|
||||
|
||||
// At the time of writing C++ support in Bison is quite
|
||||
// new and there is still no way to pass error_list to
|
||||
// the parser. We use a global variable instead.
|
||||
namespace spot
|
||||
{
|
||||
namespace ltl
|
||||
{
|
||||
extern parse_error_list* error_list;
|
||||
}
|
||||
}
|
||||
%}
|
||||
|
||||
/* Logical operators. */
|
||||
%left <token> OP_AND OP_XOR OP_OR
|
||||
%left <token> OP_IMPLIES OP_EQUIV
|
||||
|
||||
/* LTL operators. */
|
||||
%left <token> OP_U OP_R
|
||||
%nonassoc <token> OP_F OP_G
|
||||
%nonassoc <token> OP_X
|
||||
|
||||
/* Not has the most important priority. */
|
||||
%nonassoc <token> OP_NOT
|
||||
|
||||
/* Grouping (parentheses). */
|
||||
%token <token> PAR_OPEN PAR_CLOSE
|
||||
|
||||
/* Atomic proposition. */
|
||||
%token <str> ATOMIC_PROP
|
||||
|
||||
/* Constants */
|
||||
%token CONST_TRUE
|
||||
%token CONST_FALSE
|
||||
%token END_OF_INPUT
|
||||
|
||||
%type <ltl> result ltl_formulae subformulae
|
||||
|
||||
%%
|
||||
result: ltl_formulae END_OF_INPUT
|
||||
{ result = $$ = $1;
|
||||
YYACCEPT;
|
||||
}
|
||||
| many_errors END_OF_INPUT
|
||||
{ error_list->push_back(parse_error(@1,
|
||||
"couldn't parse anything sensible"));
|
||||
result = $$ = 0;
|
||||
YYABORT;
|
||||
}
|
||||
| END_OF_INPUT
|
||||
{ error_list->push_back(parse_error(@1,
|
||||
"empty input"));
|
||||
result = $$ = 0;
|
||||
YYABORT;
|
||||
}
|
||||
|
||||
many_errors_diagnosed : many_errors
|
||||
{ error_list->push_back(parse_error(@1,
|
||||
"unexpected input ignored")); }
|
||||
|
||||
ltl_formulae: subformulae
|
||||
{ $$ = $1; }
|
||||
| many_errors_diagnosed subformulae
|
||||
{ $$ = $2; }
|
||||
| ltl_formulae many_errors_diagnosed
|
||||
{ $$ = $1; }
|
||||
|
||||
many_errors: error
|
||||
| many_errors error
|
||||
|
||||
subformulae: ATOMIC_PROP
|
||||
{ $$ = new atomic_prop(*$1); delete $1; }
|
||||
| CONST_TRUE
|
||||
{ $$ = new constant(constant::True); }
|
||||
| CONST_FALSE
|
||||
{ $$ = new constant(constant::False); }
|
||||
| PAR_OPEN subformulae PAR_CLOSE
|
||||
{ $$ = $2; }
|
||||
| PAR_OPEN error PAR_CLOSE
|
||||
{ error_list->push_back(parse_error(@$,
|
||||
"treating this parenthetical block as false"));
|
||||
$$ = new constant(constant::False);
|
||||
}
|
||||
| PAR_OPEN subformulae many_errors PAR_CLOSE
|
||||
{ error_list->push_back(parse_error(@3,
|
||||
"unexpected input ignored"));
|
||||
$$ = $2;
|
||||
}
|
||||
| OP_NOT subformulae
|
||||
{ $$ = new unop(unop::Not, $2); }
|
||||
| subformulae OP_AND subformulae
|
||||
{ $$ = new multop(multop::And, $1, $3); }
|
||||
| subformulae OP_OR subformulae
|
||||
{ $$ = new multop(multop::Or, $1, $3); }
|
||||
| subformulae OP_XOR subformulae
|
||||
{ $$ = new binop(binop::Xor, $1, $3); }
|
||||
| subformulae OP_IMPLIES subformulae
|
||||
{ $$ = new binop(binop::Implies, $1, $3); }
|
||||
| subformulae OP_EQUIV subformulae
|
||||
{ $$ = new binop(binop::Equiv, $1, $3); }
|
||||
| subformulae OP_U subformulae
|
||||
{ $$ = new binop(binop::U, $1, $3); }
|
||||
| subformulae OP_R subformulae
|
||||
{ $$ = new binop(binop::R, $1, $3); }
|
||||
| OP_F subformulae
|
||||
{ $$ = new unop(unop::F, $2); }
|
||||
| OP_G subformulae
|
||||
{ $$ = new unop(unop::G, $2); }
|
||||
| OP_X subformulae
|
||||
{ $$ = new unop(unop::X, $2); }
|
||||
// | subformulae many_errors
|
||||
// { error_list->push_back(parse_error(@2,
|
||||
// "ignoring these unexpected trailing tokens"));
|
||||
// $$ = $1;
|
||||
// }
|
||||
|
||||
;
|
||||
|
||||
%%
|
||||
|
||||
void
|
||||
yy::Parser::print_()
|
||||
{
|
||||
if (looka_ == ATOMIC_PROP)
|
||||
YYCDEBUG << " '" << *value.str << "'";
|
||||
}
|
||||
|
||||
void
|
||||
yy::Parser::error_()
|
||||
{
|
||||
error_list->push_back(parse_error(location, message));
|
||||
}
|
||||
|
||||
formulae* result = 0;
|
||||
|
||||
namespace spot
|
||||
{
|
||||
namespace ltl
|
||||
{
|
||||
parse_error_list* error_list;
|
||||
|
||||
formulae*
|
||||
parse(const std::string& ltl_string,
|
||||
parse_error_list& error_list,
|
||||
bool debug)
|
||||
{
|
||||
result = 0;
|
||||
ltl::error_list = &error_list;
|
||||
flex_set_buffer(ltl_string.c_str());
|
||||
yy::Parser parser(debug, yy::Location());
|
||||
parser.parse();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
// mode: c++
|
||||
// End:
|
||||
71
src/ltlparse/ltlscan.ll
Normal file
71
src/ltlparse/ltlscan.ll
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
%option noyywrap
|
||||
|
||||
%{
|
||||
#include <string>
|
||||
#include "parsedecl.hh"
|
||||
|
||||
/* Hack Flex so we read from a string instead of reading from a file. */
|
||||
# define YY_INPUT(buf, result, max_size) \
|
||||
do { \
|
||||
result = (max_size < to_parse_size) ? max_size : to_parse_size; \
|
||||
memcpy(buf, to_parse, result); \
|
||||
to_parse_size -= result; \
|
||||
to_parse += result; \
|
||||
} while (0);
|
||||
|
||||
#define YY_USER_ACTION \
|
||||
yylloc->columns (yyleng);
|
||||
|
||||
static const char *to_parse = 0;
|
||||
static int to_parse_size = 0;
|
||||
|
||||
void
|
||||
flex_set_buffer(const char *buf)
|
||||
{
|
||||
to_parse = buf;
|
||||
to_parse_size = strlen(to_parse);
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%%
|
||||
|
||||
%{
|
||||
yylloc->step ();
|
||||
%}
|
||||
|
||||
"(" return PAR_OPEN;
|
||||
")" return PAR_CLOSE;
|
||||
|
||||
"!" return OP_NOT;
|
||||
"|"|"+" return OP_OR;
|
||||
"&"|"."|"*" return OP_AND;
|
||||
"^" return OP_XOR;
|
||||
"=>"|"->" return OP_IMPLIES;
|
||||
"<=>"|"<->" return OP_EQUIV;
|
||||
|
||||
/* <>, [], and () are used in Spin. */
|
||||
"F"|"<>" return OP_F;
|
||||
"G"|"[]" return OP_G;
|
||||
"U" return OP_U;
|
||||
"R"|"V" return OP_R;
|
||||
"X"|"()" return OP_X;
|
||||
|
||||
"1"|"true" return CONST_TRUE;
|
||||
"0"|"false" return CONST_FALSE;
|
||||
|
||||
[ \t\n]+ yylloc->step (); /* discard whitespace */
|
||||
|
||||
/* An Atomic propisition cannot start with the letter
|
||||
used by a unary operator (F,G,X), unless this
|
||||
letter is followed by a digit in which case we assume
|
||||
it's an ATOMIC_PROP (even though F0 could be seen as Ffalse). */
|
||||
[a-zA-EH-WYZ_][a-zA-Z0-9_]* |
|
||||
[FGX][0-9_][a-zA-Z0-9_]* {
|
||||
yylval->str = new std::string(yytext);
|
||||
return ATOMIC_PROP;
|
||||
}
|
||||
|
||||
. return *yytext;
|
||||
|
||||
<<EOF>> return END_OF_INPUT;
|
||||
14
src/ltlparse/parsedecl.hh
Normal file
14
src/ltlparse/parsedecl.hh
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef SPOT_LTLPARSE_PARSEDECL_HH
|
||||
# define SPOT_LTLPARSE_PARSEDECL_HH
|
||||
|
||||
#include "ltlparse.hh"
|
||||
#include "location.hh"
|
||||
|
||||
# define YY_DECL \
|
||||
int yylex (yystype *yylval, yy::Location *yylloc)
|
||||
YY_DECL;
|
||||
|
||||
void flex_set_buffer(const char *buf);
|
||||
|
||||
#endif // SPOT_LTLPARSE_PARSEDECL_HH
|
||||
|
||||
24
src/ltlparse/public.hh
Normal file
24
src/ltlparse/public.hh
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#ifndef SPOT_LTLPARSE_PUBLIC_HH
|
||||
# define SPOT_LTLPARSE_PUBLIC_HH
|
||||
|
||||
# include <string>
|
||||
# include "ltlast/formulae.hh"
|
||||
# include "location.hh"
|
||||
# include <list>
|
||||
# include <utility>
|
||||
|
||||
namespace spot
|
||||
{
|
||||
namespace ltl
|
||||
{
|
||||
typedef std::pair<yy::Location, std::string> parse_error;
|
||||
typedef std::list<parse_error> parse_error_list;
|
||||
|
||||
// Beware: this function is *not* reentrant.
|
||||
formulae* parse(const std::string& ltl_string,
|
||||
parse_error_list& error_list,
|
||||
bool debug = false);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SPOT_LTLPARSE_PUBLIC_HH
|
||||
Loading…
Add table
Add a link
Reference in a new issue