tgbaparse.yy 4.45 KB
Newer Older
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* Copyright (C) 2003  Laboratoire d'Informatique de Paris 6 (LIP6),
** dpartement Systmes Rpartis Coopratifs (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.
*/
22
23
24
25
26
27
28
29
30
31
32
33
34
35
%{
#include <string>
#include "public.hh"
%}

%parse-param {spot::tgba_parse_error_list &error_list}
%parse-param {spot::ltl::environment &parse_environment}
%parse-param {spot::tgba_explicit* &result}
%debug
%error-verbose
%union
{
  int token;
  std::string* str;
36
37
  std::list<std::pair<bool, spot::ltl::formula*> >* listp;
  std::list<spot::ltl::formula*>* list;
38
39
40
}

%{
41
42
43
#include "ltlast/constant.hh"
#include "ltlvisit/destroy.hh"

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* tgbaparse.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;

/* Ugly hack so that Bison use tgbayylex, not yylex.
   (%name-prefix doesn't work for the lalr1.cc skeleton
   at the time of writing.)  */
#define yylex tgbayylex

typedef std::pair<bool, spot::ltl::formula*> pair;
%}

%token <str> STRING
%token <str> IDENT
%type <str> strident
61
62
63
%type <listp> cond_list
%type <list> acc_list
%token ACC_DEF
64
65

%%
66
67
68
69
tgba: accepting_decl lines | lines;

accepting_decl: ACC_DEF acc_decl ';'

70
71
/* At least one line.  */
lines: line
72
73
74
       | lines line
       ;

75
line: strident ',' strident ',' cond_list ',' acc_list ';'
76
77
78
79
80
81
82
83
84
       {
	 spot::tgba_explicit::transition* t
	   = result->create_transition(*$1, *$3);
	 std::list<pair>::iterator i;
	 for (i = $5->begin(); i != $5->end(); ++i)
	   if (i->first)
	     result->add_neg_condition(t, i->second);
	   else
	     result->add_condition(t, i->second);
85
86
87
	 std::list<formula*>::iterator i2;
	 for (i2 = $7->begin(); i2 != $7->end(); ++i2)
	     result->add_accepting_condition(t, *i2);
88
89
90
91
92
93
94
95
96
	 delete $1;
	 delete $3;
	 delete $5;
	 delete $7;
       }
       ;

strident: STRING | IDENT;

97
cond_list:
98
99
100
       {
	 $$ = new std::list<pair>;
       }
101
       | cond_list strident
102
       {
103
	 if (*$2 != "")
104
105
106
	   {
	     $1->push_back(pair(false, parse_environment.require(*$2)));
	   }
107
108
109
	 delete $2;
	 $$ = $1;
       }
110
       | cond_list '!' strident
111
       {
112
	 if (*$3 != "")
113
114
115
	   {
	     $1->push_back(pair(true, parse_environment.require(*$3)));
	   }
116
117
118
119
120
	 delete $3;
	 $$ = $1;
       }
       ;

121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
acc_list:
       {
	 $$ = new std::list<formula*>;
       }
       | acc_list strident
       {
	 if (*$2 == "true")
	   {
	     $1->push_back(constant::true_instance());
	   }
	 else if (*$2 != "" && *$2 != "false")
	   {
	     formula* f = parse_environment.require(*$2);
	     if (! result->has_accepting_condition(f))
	       {
		 error_list.push_back(spot::tgba_parse_error(@2,
			 "undeclared accepting condition"));
		 destroy(f);
		 delete $2;
		 YYERROR;
	       }
	     $1->push_back(f);
	   }
	 delete $2;
	 $$ = $1;
       }
       ;


acc_decl:
       | acc_decl strident
       {
	 formula* f = parse_environment.require(*$2);
	 result->declare_accepting_condition(f);
	 delete $2;
       }
       ;
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178

%%

void
yy::Parser::print_()
{
  if (looka_ == STRING || looka_ == IDENT)
    YYCDEBUG << " '" << *value.str << "'";
}

void
yy::Parser::error_()
{
  error_list.push_back(spot::tgba_parse_error(location, message));
}

namespace spot
{
  tgba_explicit*
  tgba_parse(const std::string& name,
	     tgba_parse_error_list& error_list,
179
	     bdd_dict* dict,
180
181
182
183
	     environment& env,
	     bool debug)
  {
    if (tgbayyopen(name))
184
185
186
187
188
189
190
191
192
193
194
195
      {
	error_list.push_back
	  (tgba_parse_error(yy::Location(),
			    std::string("Cannot open file ") + name));
	return 0;
      }
    tgba_explicit* result = new tgba_explicit(dict);
    tgbayy::Parser parser(debug, yy::Location(), error_list, env, result);
    parser.parse();
    tgbayyclose();
    return result;
  }
196
197
198
199
200
}

// Local Variables:
// mode: c++
// End: