#include <sstream>
#include <fstream>
#include <vector>
+ #include <cstdlib>
#include "action.h"
+ #include "planner.h"
using namespace std;
void yyerror (char const *);
ifstream* input;
+ int line = 1;
vector<Action>* actions;
+ EffectsMap* runlevels;
%}
%%
-input : /* empty */
- | input action
- | input '\n'
-;
+input : runlvls '\n' actions
+ ;
+
+
+runlvls : '\n' runlvls
+ | effects { runlevels = $1; }
+ ;
+
+actions : /* empty */
+ | actions action
+ | actions '\n'
+ ;
+
action : id preconds '\n' exec effects '\n' {
- // Detta vill inte funka för mig!
actions->push_back( Action(*$1,*$2,*$4,*$5) );
//---------------------------------------------
;
/* Preconditions (literals with flag) */
-preconds: preconds ',' preconds {
+preconds: /* empty */ { $$ = new Preconditions(); }
+ | preconds ',' preconds {
$$ = $1;
// $3 will only have on element
(*$$)[$3->begin()->first] =
}
/* Return single char */
- return input->get();
+ int c = input->get();
+ if ( c=='\n' )
+ ++line;
+ return c;
}
void
yyerror (char const *s)
{
- cerr << "Parse error : " << s;
+ cerr << "Line " << line << ": " << s << endl;
}
+vector<string> stringToVector(string str){
+ vector<string> strings;
+
+ istringstream ist(str);
+ while (ist >> str){
+ strings.push_back(str);
+ }
+
+ return strings;
+}
int
main (int argc, char** argv)
if (argc!=4)
{
cout << "Syntax: " << argv[0] <<
- " <file> \"init state\" \"goal state\"" << endl;
+ " <file> <runlevel> \"init state\"" << endl;
return 1;
}
// Set global variables
input = &file;
actions = new vector<Action>();
+ runlevels = new EffectsMap();
yyparse();
+
+ cout << (*runlevels)[2].size() << endl;
+ cout << (*runlevels)[3].size() << endl;
+ cout << (*runlevels)[4].size() << endl;
+ cout << (*runlevels)[5].size() << endl;
+
+ Planner p(*actions, stringToVector(argv[3]), (*runlevels)[atoi(argv[2])]);
+ p.execute();
}