16 void yyerror (char const *);
19 vector<Action>* actions;
25 Preconditions* preconds;
28 string* str; /* STR tokens */
29 int num; /* NUM tokena */
33 %type <preconds> preconds
35 %type <effects> effects
36 %type <literals> literals
49 action : id preconds '\n' exec effects '\n' {
51 // Detta vill inte funka för mig!
52 actions->push_back( Action(*$1,*$2,*$4,*$5) );
54 //---------------------------------------------
56 cout << "id: " << *$1 << endl;
58 // Precondition flags:
59 cout << "a: " << (*$2)["NET"] << endl;
60 cout << "b: " << (*$2)["b"] << endl;
61 cout << "c: " << (*$2)["c"] << endl;
62 cout << "d: " << (*$2)["d"] << endl;
63 cout << "e: " << (*$2)["e"] << endl;
65 cout << "exe: " << *$4 << endl;
67 // Print number of effects
68 cout << "1: " << (*$5)[0].size() << endl;
69 cout << "99: " << (*$5)[99].size() << endl;
70 cout << "88: " << (*$5)[88].size() << endl;
73 //----------------------------------------------
80 id : STR '\n' { $$ = $1; }
83 /* Preconditions (literals with flag) */
84 preconds: preconds ',' preconds {
86 // $3 will only have on element
87 (*$$)[$3->begin()->first] =
91 $$ = new Preconditions();
95 $$ = new Preconditions();
101 exec : STR '\n' { $$ = $1; }
105 effects : effects NUM ':' literals '\n' {
109 | NUM ':' literals '\n' {
110 $$ = new EffectsMap();
116 /* List of literals (effects) */
117 literals: literals ',' literals {
119 $$->push_back( *($3->begin()) );
135 // Check for end of file
140 while ( input->peek()==' ' || input->peek()=='\t')
144 while ( input->peek()=='#')
145 while ( input->peek()!='\n' )
152 if ( isdigit(input->peek()) )
154 *input >> yylval.num;
159 if ( isalpha(input->peek()) )
161 string* str = new string();
163 int c = input->peek();
164 while (isalpha(c) || isdigit(c) || c=='_' || c=='.' )
166 *str += input->get();
173 // String with spaces and other special characters
174 if ( input->peek()=='"' )
176 input->get(); // Consume "-character
177 string* str = new string();
178 while (input->peek()!='"')
180 *str += input->get();
182 input->get(); // Consume "-character
188 /* Return single char */
194 yyerror (char const *s)
196 cerr << "Parse error : " << s;
199 vector<string> stringToVector(string str){
200 vector<string> strings;
202 istringstream ist(str);
204 strings.push_back(str);
211 main (int argc, char** argv)
216 cout << "Syntax: " << argv[0] <<
217 " <file> \"init state\" \"goal state\"" << endl;
221 ifstream file(argv[1]);
224 cerr << "Unable to open file: " << argv[1] << endl;
228 // Set global variables
230 actions = new vector<Action>();
234 Planner p(*actions, stringToVector(argv[2]), stringToVector(argv[3]));