From 41efed0d6ee664fb79ea21a0e7239edcf51926d8 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Thu, 19 May 2005 10:26:49 +0000 Subject: [PATCH] some changes --- input.txt | 10 +++++++++- parser.y | 48 ++++++++++++++++++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/input.txt b/input.txt index 26792d3..9b54b4c 100644 --- 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 diff --git a/parser.y b/parser.y index e286054..c3192e3 100644 --- a/parser.y +++ b/parser.y @@ -6,6 +6,7 @@ #include #include #include + #include #include "action.h" #include "planner.h" @@ -16,7 +17,9 @@ void yyerror (char const *); ifstream* input; + int line = 1; vector* actions; + EffectsMap* runlevels; %} @@ -41,14 +44,22 @@ %% -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 stringToVector(string str){ @@ -201,7 +216,6 @@ vector 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] << - " \"init state\" \"goal state\"" << endl; + " \"init state\"" << endl; return 1; } @@ -229,9 +243,15 @@ main (int argc, char** argv) // Set global variables input = &file; actions = new vector(); + 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(); } -- 2.39.2