15 void yyerror (char const *);
18 vector<Action>* actions;
24 Preconditions* preconds;
27 string* str; /* STR tokens */
28 int num; /* NUM tokena */
32 %type <preconds> preconds
34 %type <effects> effects
35 %type <literals> literals
48 action : id preconds '\n' exec effects '\n' {
50 // Detta vill inte funka för mig!
51 actions->push_back( Action(*$1,*$2,*$4,*$5) );
53 //---------------------------------------------
55 cout << "id: " << *$1 << endl;
57 // Precondition flags:
58 cout << "a: " << (*$2)["a"] << endl;
59 cout << "b: " << (*$2)["b"] << endl;
60 cout << "c: " << (*$2)["c"] << endl;
61 cout << "d: " << (*$2)["d"] << endl;
62 cout << "e: " << (*$2)["e"] << endl;
64 cout << "exe: " << *$4 << endl;
66 // Print number of effects
67 cout << "1: " << (*$5)[1].size() << endl;
68 cout << "99: " << (*$5)[99].size() << endl;
69 cout << "88: " << (*$5)[88].size() << endl;
72 //----------------------------------------------
79 id : STR '\n' { $$ = $1; }
82 /* Preconditions (literals with flag) */
83 preconds: preconds ',' preconds {
85 // $3 will only have on element
86 (*$$)[$3->begin()->first] =
90 $$ = new Preconditions();
94 $$ = new Preconditions();
100 exec : STR '\n' { $$ = $1; }
104 effects : effects NUM ':' literals '\n' {
108 | NUM ':' literals '\n' {
109 $$ = new EffectsMap();
115 /* List of literals (effects) */
116 literals: literals ',' literals {
118 $$->push_back( *($3->begin()) );
134 // Check for end of file
139 while ( input->peek()==' ' || input->peek()=='\t')
143 while ( input->peek()=='#')
144 while ( input->peek()!='\n' )
151 if ( isdigit(input->peek()) )
153 *input >> yylval.num;
158 if ( isalpha(input->peek()) )
160 string* str = new string();
162 int c = input->peek();
163 while (isalpha(c) || isdigit(c) || c=='_' || c=='.' )
165 *str += input->get();
172 // String with spaces and other special characters
173 if ( input->peek()=='"' )
175 input->get(); // Consume "-character
176 string* str = new string();
177 while (input->peek()!='"')
179 *str += input->get();
181 input->get(); // Consume "-character
187 /* Return single char */
193 yyerror (char const *s)
195 cerr << "Parse error : " << s;
200 main (int argc, char** argv)
205 cout << "Syntax: " << argv[0] <<
206 " <file> \"init state\" \"goal state\"" << endl;
210 ifstream file(argv[1]);
213 cerr << "Unable to open file: " << argv[1] << endl;
217 // Set global variables
219 actions = new vector<Action>();