PH Logo
Logo intepreter modeled after UCB Logo.
/Users/paul/Documents/phlogo/core/Func.cpp
00001 /*
00002  *  Func.cpp
00003  *
00004  *  Author: Paul Hamilton
00005  *      Date: 6 Jun 2011
00006  *
00007  */
00008 
00009 #include "Func.h"
00010 
00011 #include "World.h"
00012 #include "Verbs.h"
00013 #include "Interpreter.h"
00014 #include "Console.h"
00015 #include "Exceptions.h"
00016 #include "StringTokenStream.h"
00017 
00018 using namespace std;
00019 
00020 namespace phlogo {
00021 
00022 void Func::addWords(const std::string &sentence) {
00023         _words = sentence;
00024 }
00025 
00026 void Func::execute(Interpreter *itp, World *world, TokenStream *ts) {
00027         
00028         wList args = itp->sentence2words(_args);
00029         
00030         StringTokenStream *sts = static_cast<StringTokenStream *>(ts);
00031         
00032         // take all the args from the data.
00033         wListIter i = args.begin();
00034         for (; i != args.end() && sts->hasMore(); i++) {
00035 
00036                 string val = sts->nextWord();
00037                 
00038                 // the variables are named with : or nothing.
00039                 if (Verbs::isVariable(*i))
00040                         world->setThing(Verbs::getVariable(*i), itp->varOrLiteral(world, val), true);
00041                 else
00042                         world->setThing(*i, itp->varOrLiteral(world, val), true);
00043                 
00044         }
00045         
00046         // and run against our internal words;
00047         StringTokenStream ts2(_words);
00048     while (ts2.hasMore())
00049         itp->getVerbs()->run(&ts2);
00050 
00051 }
00052 
00053 }
 All Classes Functions