Enable parsing stand-alone rational expressions with the LTL parser.
* src/ltlparse/ltlparse.yy (parse_ratexp): New function. (START_LTL, START_RATEXP): Add these new tokens. (result): Parse and LTL formula or a rational expression depending on the start symbol. * src/ltlparse/public.hh (parse_ratexp): New function. * src/ltlparse/parsedecl.hh (flex_set_buffer): Add a new argument to set the starting rule. * src/ltlparse/ltlscan.ll (flex_set_buffer): Adjust. (start_token): New global variable. Return this as first token if it is set.
This commit is contained in:
parent
c6dd811b08
commit
9aebb80e08
4 changed files with 92 additions and 19 deletions
|
|
@ -74,6 +74,8 @@ using namespace spot::ltl;
|
|||
|
||||
/* All tokens. */
|
||||
|
||||
%token START_LTL "LTL start marker"
|
||||
%token START_RATEXP "RATEXP start marker"
|
||||
%token PAR_OPEN "opening parenthesis" PAR_CLOSE "closing parenthesis"
|
||||
%token BRACE_OPEN "opening brace" BRACE_CLOSE "closing brace"
|
||||
%token OP_OR "or operator" OP_XOR "xor operator" OP_AND "and operator"
|
||||
|
|
@ -124,27 +126,50 @@ using namespace spot::ltl;
|
|||
%printer { debug_stream() << *$$; } <str>
|
||||
|
||||
%%
|
||||
result: subformula END_OF_INPUT
|
||||
{ result = $1;
|
||||
result: START_LTL subformula END_OF_INPUT
|
||||
{ result = $2;
|
||||
YYACCEPT;
|
||||
}
|
||||
| error END_OF_INPUT
|
||||
{ error_list.push_back(parse_error(@1,
|
||||
"could not parse anything sensible"));
|
||||
| START_LTL enderror
|
||||
{
|
||||
result = 0;
|
||||
YYABORT;
|
||||
}
|
||||
| subformula error END_OF_INPUT
|
||||
{ error_list.push_back(parse_error(@2,
|
||||
"ignoring trailing garbage"));
|
||||
result = $1;
|
||||
| START_LTL subformula enderror
|
||||
{
|
||||
result = $2;
|
||||
YYACCEPT;
|
||||
}
|
||||
| END_OF_INPUT
|
||||
{ error_list.push_back(parse_error(@$, "empty input"));
|
||||
| START_LTL emptyinput
|
||||
{ YYABORT; }
|
||||
| START_RATEXP rationalexp END_OF_INPUT
|
||||
{ result = $2;
|
||||
YYACCEPT;
|
||||
}
|
||||
| START_RATEXP enderror
|
||||
{
|
||||
result = 0;
|
||||
YYABORT;
|
||||
}
|
||||
| START_RATEXP rationalexp enderror
|
||||
{
|
||||
result = $2;
|
||||
YYACCEPT;
|
||||
}
|
||||
| START_RATEXP emptyinput
|
||||
{ YYABORT; }
|
||||
|
||||
emptyinput: END_OF_INPUT
|
||||
{
|
||||
error_list.push_back(parse_error(@$, "empty input"));
|
||||
result = 0;
|
||||
}
|
||||
|
||||
enderror: error END_OF_INPUT
|
||||
{
|
||||
error_list.push_back(parse_error(@1,
|
||||
"ignoring trailing garbage"));
|
||||
}
|
||||
|
||||
/* The reason we use `constant::false_instance()' for error recovery
|
||||
is that it isn't reference counted. (Hence it can't leak references.) */
|
||||
|
|
@ -361,12 +386,29 @@ namespace spot
|
|||
bool debug)
|
||||
{
|
||||
formula* result = 0;
|
||||
flex_set_buffer(ltl_string.c_str());
|
||||
flex_set_buffer(ltl_string.c_str(),
|
||||
ltlyy::parser::token::START_LTL);
|
||||
ltlyy::parser parser(error_list, env, result);
|
||||
parser.set_debug_level(debug);
|
||||
parser.parse();
|
||||
return result;
|
||||
}
|
||||
|
||||
formula*
|
||||
parse_ratexp(const std::string& ratexp_string,
|
||||
parse_error_list& error_list,
|
||||
environment& env,
|
||||
bool debug)
|
||||
{
|
||||
formula* result = 0;
|
||||
flex_set_buffer(ratexp_string.c_str(),
|
||||
ltlyy::parser::token::START_RATEXP);
|
||||
ltlyy::parser parser(error_list, env, result);
|
||||
parser.set_debug_level(debug);
|
||||
parser.parse();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue