]> ruin.nu Git - popboot.git/blobdiff - parser.y
some changes
[popboot.git] / parser.y
index d39a88a34e9c01c5d25804c09e9e243c63ade085..c3192e33861130542aa2b74065d1e9c0f9506fcf 100644 (file)
--- a/parser.y
+++ b/parser.y
@@ -6,8 +6,10 @@
     #include <sstream>
     #include <fstream>
     #include <vector>
+       #include <cstdlib>
 
     #include "action.h"
+       #include "planner.h"
 
     using namespace std;
 
@@ -15,7 +17,9 @@
     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) ); 
 
                                //---------------------------------------------
@@ -80,7 +92,8 @@ id    : STR '\n'                  { $$ = $1; }
        ;
 
 /* Preconditions (literals with flag) */
-preconds: preconds ','         preconds    {  
+preconds: /* empty */              {   $$ = new Preconditions(); }
+       | preconds ','  preconds    {  
                                        $$ = $1;
                                        // $3 will only have on element
                                        (*$$)[$3->begin()->first] =
@@ -185,16 +198,29 @@ yylex (void)
     }
 
     /* 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)
@@ -203,7 +229,7 @@ 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;
     }
 
@@ -217,6 +243,15 @@ main (int argc, char** argv)
     // 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();
 }