18 void yyerror (char const *);
22 vector<Action>* actions;
23 EffectsMap* runlevels;
29 Preconditions* preconds;
32 string* str; /* STR tokens */
33 int num; /* NUM tokena */
37 %type <preconds> preconds
39 %type <effects> effects
40 %type <literals> literals
48 input : runlvls '\n' actions
52 runlvls : '\n' runlvls
53 | effects { runlevels = $1; }
62 action : id preconds '\n' exec effects '\n' {
64 actions->push_back( Action(*$1,*$2,*$4,*$5) );
66 //---------------------------------------------
68 /* cerr << "id: " << *$1 << endl;
70 // Precondition flags:
71 cerr << "a: " << (*$2)["a"] << endl;
72 cerr << "b: " << (*$2)["b"] << endl;
73 cerr << "c: " << (*$2)["c"] << endl;
74 cerr << "d: " << (*$2)["d"] << endl;
75 cerr << "e: " << (*$2)["e"] << endl;
77 cerr << "exe: " << *$4 << endl;
79 // Print number of effects
80 cerr << "0: " << (*$5)[0].size() << endl;
81 cerr << "99: " << (*$5)[99].size() << endl;
82 cerr << "88: " << (*$5)[88].size() << endl;
85 */ //----------------------------------------------
92 id : STR '\n' { $$ = $1; }
95 /* Preconditions (literals with flag) */
96 preconds: /* empty */ { $$ = new Preconditions(); }
97 | preconds ',' preconds {
99 // $3 will only have on element
100 (*$$)[$3->begin()->first] =
104 $$ = new Preconditions();
108 $$ = new Preconditions();
114 exec : STR '\n' { $$ = $1; }
118 effects : effects NUM ':' literals '\n' {
122 | NUM ':' literals '\n' {
123 $$ = new EffectsMap();
129 /* List of literals (effects) */
130 literals: literals ',' literals {
132 $$->push_back( *($3->begin()) );
148 // Check for end of file
153 while ( input->peek()==' ' || input->peek()=='\t')
157 while ( input->peek()=='#')
158 while ( input->peek()!='\n' )
165 if ( isdigit(input->peek()) )
167 *input >> yylval.num;
172 if ( isalpha(input->peek()) )
174 string* str = new string();
176 int c = input->peek();
177 while (isalpha(c) || isdigit(c) || c=='_' || c=='.' )
179 *str += input->get();
186 // String with spaces and other special characters
187 if ( input->peek()=='"' )
189 input->get(); // Consume "-character
190 string* str = new string();
191 while (input->peek()!='"')
193 *str += input->get();
195 input->get(); // Consume "-character
201 /* Return single char */
202 int c = input->get();
210 yyerror (char const *s)
212 cerr << "Line " << line << ": " << s << endl;
215 vector<string> stringToVector(string str){
216 vector<string> strings;
218 istringstream ist(str);
220 strings.push_back(str);
227 main (int argc, char** argv)
232 cerr << "Syntax: " << argv[0] <<
233 " <file> <runlevel> \"init state\"" << endl;
237 Literals init = argc >= 4 ? stringToVector(argv[3]) : Literals();
238 ifstream file(argv[1]);
241 cerr << "Unable to open file: " << argv[1] << endl;
245 // Set global variables
247 actions = new vector<Action>();
248 runlevels = new EffectsMap();
252 /* cerr << (*runlevels)[2].size() << endl;
253 cerr << (*runlevels)[3].size() << endl;
254 cerr << (*runlevels)[4].size() << endl;
255 cerr << (*runlevels)[5].size() << endl;
257 Planner p(*actions, init, (*runlevels)[atoi(argv[2])]);