--- trunk/src/selection/SelectionCompiler.hpp 2005/02/01 22:49:23 278 +++ trunk/src/selection/SelectionCompiler.hpp 2005/04/13 22:43:43 494 @@ -41,8 +41,12 @@ #ifndef SELECTION_SELECTIONCOMPILER_HPP #define SELECTION_SELECTIONCOMPILER_HPP +#include #include #include + +#include "selection/Token.hpp" +#include "selection/TokenMap.hpp" namespace oopse { @@ -62,7 +66,7 @@ namespace oopse { clausePrimitive ::= clauseComparator | clauseWithin | - clauseChemObject | + clauseName | none | all | ( clauseOr ) @@ -71,25 +75,10 @@ namespace oopse { clauseWithin ::= WITHIN ( clauseDistance , expression ) clauseDistance ::= integer | decimal - - clauseChemObject::= {clauseMolecule} | {clauseStuntDouble} + + clauseName::= *|string{.string{.string}} - clauseMolecule ::= {clauseMolName} | {clauseMolIndex} - clauseMolName ::= molname clauseName - - clauseName::= *|string - - clauseMolIndex ::= molindex clauseIndex - - clauseIndex ::= integer {- integer } - - clauseStuntDouble ::= {clauseStuntDoubleName} | {clauseStuntDoubleIndex} - - clauseStuntDoubleName ::= name clauseName - - clauseStuntDoubleIndex ::= index clauseIndex - * */ class SelectionCompiler{ @@ -117,24 +106,31 @@ class SelectionCompiler{ strError += filename; } - strError += " line#" + lineCurrent; return strError; } private: - bool internalcompile(); + bool internalCompile(); bool lookingAtLeadingWhitespace(); - bool lookingAtComment(); + //bool lookingAtComment(); bool lookingAtEndOfLine(); bool lookingAtEndOfStatement(); bool lookingAtString(); + bool lookingAtDecimal(bool allowNegative); + bool lookingAtInteger(bool allowNegative); + bool lookingAtLookupToken(); + bool lookingAtSpecialString(); + std::string getUnescapedStringLiteral(); + int getHexitValue(char ch); - bool compileCommand(const std::vector&); + bool compileCommand(const std::vector& ltoken); + bool compileExpression(); + bool compileExpression(int itoken); bool clauseOr(); bool clauseAnd(); @@ -142,19 +138,19 @@ class SelectionCompiler{ bool clausePrimitive(); bool clauseWithin(); bool clauseComparator(); - bool clauseChemObject(); - bool clauseMolecule(); - bool clauseMolName(); - bool clauseMolIndex(); - bool clauseName(); + bool clauseChemObjName(); bool clauseIndex(); - bool clauseStuntDoubleName(); - bool clauseStuntDoubleIndex(); + Token tokenNext(); + boost::any valuePeek(); + int tokPeek(); - bool compileError(const std::string& errorMessage) { - std::cerr << "SelectionCompiler Error: " << errorMessage << << std::endl; + bool addTokenToPostfix(const Token& token); + bool isNameValid(const std::string& name); + + bool compileError(const std::string& errorMsg) { + std::cerr << "SelectionCompiler Error: " << errorMsg << std::endl; error = true; - this.errorMessage = errorMessage; + this->errorMessage = errorMsg; return false; } @@ -191,17 +187,29 @@ class SelectionCompiler{ } bool unrecognizedExpressionToken() { - return compileError("unrecognized expression token:" + valuePeek()); + boost::any tmp = valuePeek(); + std::string tokenStr; + + try { + tokenStr = boost::any_cast(tmp); + } catch(const boost::bad_any_cast &) { + return compileError("any_cast error"); + } + + return compileError("unrecognized expression token:" + tokenStr); } bool comparisonOperatorExpected() { return compileError("comparison operator expected"); } - bool integerExpected() { - return compileError("integer expected"); + bool numberExpected() { + return compileError("number expected"); } + bool numberOrKeywordExpected() { + return compileError("number or keyword expected"); + } std::string filename; std::string script;