--- trunk/src/selection/SelectionCompiler.hpp 2005/02/01 22:49:23 278 +++ trunk/src/selection/SelectionCompiler.hpp 2005/02/07 19:13:18 295 @@ -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{ @@ -124,17 +113,25 @@ class SelectionCompiler{ 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 +139,20 @@ class SelectionCompiler{ bool clausePrimitive(); bool clauseWithin(); bool clauseComparator(); - bool clauseChemObject(); - bool clauseMolecule(); - bool clauseMolName(); - bool clauseMolIndex(); - bool clauseName(); + bool clauseChemObjName(); + bool clauseName(std::string& name); bool clauseIndex(); - bool clauseStuntDoubleName(); - bool clauseStuntDoubleIndex(); + Token tokenNext(); + boost::any valuePeek(); + int tokPeek(); + bool addTokenToPostfix(const Token& token); + + bool compileError(const std::string& errorMessage) { - std::cerr << "SelectionCompiler Error: " << errorMessage << << std::endl; + std::cerr << "SelectionCompiler Error: " << errorMessage << std::endl; error = true; - this.errorMessage = errorMessage; + this->errorMessage = errorMessage; return false; } @@ -191,17 +189,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;