17 void yyerror (char const *);
21 vector<Action>* actions;
22 EffectsMap* runlevels;
28 Preconditions* preconds;
31 string* str; /* STR tokens */
32 int num; /* NUM tokena */
36 %type <preconds> preconds
38 %type <effects> effects
39 %type <literals> literals
47 input : runlvls '\n' actions
51 runlvls : '\n' runlvls
52 | effects { runlevels = $1; }
61 action : id preconds '\n' exec effects '\n' {
63 actions->push_back( Action(*$1,*$2,*$4,*$5) );
65 //---------------------------------------------
67 cerr << "id: " << *$1 << endl;
69 // Precondition flags:
70 cerr << "a: " << (*$2)["a"] << endl;
71 cerr << "b: " << (*$2)["b"] << endl;
72 cerr << "c: " << (*$2)["c"] << endl;
73 cerr << "d: " << (*$2)["d"] << endl;
74 cerr << "e: " << (*$2)["e"] << endl;
76 cerr << "exe: " << *$4 << endl;
78 // Print number of effects
79 cerr << "0: " << (*$5)[0].size() << endl;
80 cerr << "99: " << (*$5)[99].size() << endl;
81 cerr << "88: " << (*$5)[88].size() << endl;
84 //----------------------------------------------
91 id : STR '\n' { $$ = $1; }
94 /* Preconditions (literals with flag) */
95 preconds: /* empty */ { $$ = new Preconditions(); }
96 | preconds ',' preconds {
98 // $3 will only have on element
99 (*$$)[$3->begin()->first] =
103 $$ = new Preconditions();
107 $$ = new Preconditions();
113 exec : STR '\n' { $$ = $1; }
117 effects : effects NUM ':' literals '\n' {
121 | NUM ':' literals '\n' {
122 $$ = new EffectsMap();
128 /* List of literals (effects) */
129 literals: literals ',' literals {
131 $$->push_back( *($3->begin()) );
147 // Check for end of file
152 while ( input->peek()==' ' || input->peek()=='\t')
156 while ( input->peek()=='#')
157 while ( input->peek()!='\n' )
164 if ( isdigit(input->peek()) )
166 *input >> yylval.num;
171 if ( isalpha(input->peek()) )
173 string* str = new string();
175 int c = input->peek();
176 while (isalpha(c) || isdigit(c) || c=='_' || c=='.' )
178 *str += input->get();
185 // String with spaces and other special characters
186 if ( input->peek()=='"' )
188 input->get(); // Consume "-character
189 string* str = new string();
190 while (input->peek()!='"')
192 *str += input->get();
194 input->get(); // Consume "-character
200 /* Return single char */
201 int c = input->get();
209 yyerror (char const *s)
211 cerr << "Line " << line << ": " << s << endl;
214 vector<string> stringToVector(string str){
215 vector<string> strings;
217 istringstream ist(str);
219 strings.push_back(str);
226 main (int argc, char** argv)
231 cerr << "Syntax: " << argv[0] <<
232 " <file> <runlevel> \"init state\"" << endl;
236 Literals init = argc >= 4 ? stringToVector(argv[3]) : Literals();
237 ifstream file(argv[1]);
240 cerr << "Unable to open file: " << argv[1] << endl;
244 // Set global variables
246 actions = new vector<Action>();
247 runlevels = new EffectsMap();
251 cerr << (*runlevels)[2].size() << endl;
252 cerr << (*runlevels)[3].size() << endl;
253 cerr << (*runlevels)[4].size() << endl;
254 cerr << (*runlevels)[5].size() << endl;
256 Planner p(*actions, init, (*runlevels)[atoi(argv[2])]);