]> ruin.nu Git - popboot.git/commitdiff
some changes
authorMichael Andreen <harv@ruin.nu>
Thu, 19 May 2005 10:26:49 +0000 (10:26 +0000)
committerMichael Andreen <harv@ruin.nu>
Thu, 19 May 2005 10:26:49 +0000 (10:26 +0000)
input.txt
parser.y

index 26792d30e02b1c4f65260ddcb6a1dde6622d261b..9b54b4c27d8deb34bb33ba0cf1986db018255aee 100644 (file)
--- a/input.txt
+++ b/input.txt
@@ -1,3 +1,11 @@
+#
+# Runlevel 2-5
+#
+#2 : a
+3 : NET 
+4 : HTTPD
+5 : HTTPD
+
 # kommenatar
 apache
 NET
@@ -9,7 +17,7 @@ httpd.sh
 #32 
 #dasdssad
 eth0
-A # test 
+ # no preconditions 
 "ifconfig up eth0"
 0: NET # kommentar
 
index e286054cb2fd1319ac0657f541f8d8f2fe21f95a..c3192e33861130542aa2b74065d1e9c0f9506fcf 100644 (file)
--- a/parser.y
+++ b/parser.y
@@ -6,6 +6,7 @@
     #include <sstream>
     #include <fstream>
     #include <vector>
+       #include <cstdlib>
 
     #include "action.h"
        #include "planner.h"
@@ -16,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) ); 
 
                                //---------------------------------------------
@@ -56,7 +67,7 @@ action        : id preconds '\n' exec effects '\n' {
                                cout << "id:  " << *$1 << endl;
 
                                // Precondition flags:
-                               cout << "a: " << (*$2)["NET"] << endl;
+                               cout << "a: " << (*$2)["a"] << endl;
                                cout << "b: " << (*$2)["b"] << endl;
                                cout << "c: " << (*$2)["c"] << endl;
                                cout << "d: " << (*$2)["d"] << endl;
@@ -65,7 +76,7 @@ action        : id preconds '\n' exec effects '\n' {
                                cout << "exe: " << *$4 << endl;
 
                                // Print number of effects
-                               cout << "1: " << (*$5)[0].size() << endl;
+                               cout << "1: " << (*$5)[1].size() << endl;
                                cout << "99: " << (*$5)[99].size() << endl;
                                cout << "88: " << (*$5)[88].size() << endl;
 
@@ -81,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] =
@@ -186,14 +198,17 @@ 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){
@@ -201,7 +216,6 @@ vector<string> stringToVector(string str){
 
        istringstream ist(str);
        while (ist >> str){
-               cout << str << endl;
                strings.push_back(str);
        }
 
@@ -215,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;
     }
 
@@ -229,9 +243,15 @@ main (int argc, char** argv)
     // Set global variables
     input = &file;
     actions = new vector<Action>();
+    runlevels = new EffectsMap();
 
     yyparse();
 
-       Planner p(*actions, stringToVector(argv[2]), stringToVector(argv[3]));
-       p.execute();
+    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();
 }