--- trunk/OOPSE-3.0/src/selection/SelectionEvaluator.hpp 2005/02/01 22:49:23 1962 +++ trunk/OOPSE-3.0/src/selection/SelectionEvaluator.hpp 2005/02/04 22:39:26 1972 @@ -49,19 +49,30 @@ #include "brains/SimInfo.hpp" #include "selection/Token.hpp" #include "selection/SelectionCompiler.hpp" +#include "selection/NameFinder.hpp" #include "utils/BitSet.hpp" - +#include "primitives/StuntDouble.hpp" namespace oopse { -class Context { - std::string filename; - std::tring script; - std::vector linenumbers; - std::vector lineIndices; - std::vector > aatoken; - int pc; -} +//class Context { +// public: +// +// void clear() { +// linenumbers.clear(); +// lineIndices.clear(); +// aatoken.clear(); +// } +// +// std::string filename; +// std::string script; +// std::vector linenumbers; +// std::vector lineIndices; +// std::vector > aatoken; +// int pc; +//}; + + /** * @class SelectionEvaluator SelectionEvaluator.hpp "selection/SelectionEvaluator" * @brief Evalute the tokens compiled by SelectionCompiler and return a BitSet @@ -69,18 +80,22 @@ class SelectionEvaluator{ class SelectionEvaluator{ public: - SelectionEvaluator(SimInfo* info, const std::string& script); + SelectionEvaluator(SimInfo* info); + bool loadScriptString(const std::string& script); + bool loadScriptFile(const std::string& filename); + BitSet evaluate(); - BitSet evaluate(int frameNo); + //BitSet evaluate(Snapshot* snapshot); /** - * Tests if the result from evaluation of script is static. - * @return true if the result keeps the same even the frame change, otherwise return false + * Tests if the result from evaluation of script is dynamic. */ - bool isStatic(); + bool isDynamic() { + return isDynamic_; + } bool hadRuntimeError() const{ return error; @@ -98,8 +113,8 @@ class SelectionEvaluator{ std::string getLine() { int ichBegin = lineIndices[pc]; int ichEnd; - if ((ichEnd = script.find('\r', ichBegin)) == std::string:npos && - (ichEnd = script.find('\n', ichBegin)) == std::string:npos) { + if ((ichEnd = script.find('\r', ichBegin)) == std::string::npos && + (ichEnd = script.find('\n', ichBegin)) == std::string::npos) { ichEnd = script.size(); } return script.substr(ichBegin, ichEnd); @@ -111,28 +126,55 @@ class SelectionEvaluator{ bool loadScript(const std::string& filename, const std::string& script); - bool loadScriptString(const std::string& script); - bool loadScriptFileInternal(const std::string& filename); + void clearDefinitionsAndLoadPredefined(); void define(); - - void predefine(); + void select(BitSet& bs); + void predefine(const std::string& script); - void instructionDispatchLoop(); + void instructionDispatchLoop(BitSet& bs); - withinInstruction(Token instruction, BitSet , BitSet); + void withinInstruction(const Token& instruction, BitSet& bs); + + BitSet comparatorInstruction(const Token& instruction); + void compareProperty(StuntDouble* sd, BitSet& bs, int property, int comparator, float comparisonValue); + BitSet nameInstruction(const std::string& name); - BitSet expression(std::vector& tokens, int pc); + BitSet expression(const std::vector& tokens, int pc); + BitSet lookupValue(const std::string& variable); + + void evalError(const std::string& message) { + std::cerr << "SelectionEvaulator Error: " << message << std::endl; + } + + void unrecognizedCommand(const Token& token) { + evalError("unrecognized command:" + boost::any_cast(token.value)); + } + + void unrecognizedExpression() { + evalError("unrecognized expression"); + } + + void unrecognizedAtomProperty(int property){ + evalError("unrecognized atom property"); + } + + void unrecognizedIdentifier(const std::string& identifier) { + evalError("unrecognized identifier:" + identifier); + } + + bool containDynamicToken(const std::vector& tokens); + SelectionCompiler compiler; - const static int scriptLevelMax = 10; - int scriptLevel; + //const static int scriptLevelMax = 10; + //int scriptLevel; - Context stack[scriptLevelMax]; + //Context stack[scriptLevelMax]; std::string filename; std::string script; @@ -141,18 +183,20 @@ class SelectionEvaluator{ std::vector > aatoken; int pc; // program counter - boolean error; + bool error; std::string errorMessage; std::vector statement; int statementLength; - SimInfo* info_; + SimInfo* info; + NameFinder finder; + int nStuntDouble; //natoms + nrigidbodies + std::map variables; - std::map > variables_; - std::string script_; - - Hashtable variables = new Hashtable(); + bool isDynamic_; + bool isLoaded_; + }; }