--- trunk/src/selection/SelectionCompiler.hpp 2005/02/07 19:13:18 295 +++ trunk/src/selection/SelectionCompiler.hpp 2009/11/25 20:02:06 1390 @@ -6,19 +6,10 @@ * redistribute this software in source and binary code form, provided * that the following conditions are met: * - * 1. Acknowledgement of the program authors must be made in any - * publication of scientific results based in part on use of the - * program. An acceptable form of acknowledgement is citation of - * the article in which the program was described (Matthew - * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher - * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented - * Parallel Simulation Engine for Molecular Dynamics," - * J. Comput. Chem. 26, pp. 252-271 (2005)) - * - * 2. Redistributions of source code must retain the above copyright + * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - * 3. Redistributions in binary form must reproduce the above copyright + * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. @@ -37,6 +28,15 @@ * arising out of the use of or inability to use software, even if the * University of Notre Dame has been advised of the possibility of * such damages. + * + * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your + * research, please cite the appropriate papers when you publish your + * work. Good starting points are: + * + * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). + * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). + * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). + * [4] Vardeman & Gezelter, in progress (2009). */ #ifndef SELECTION_SELECTIONCOMPILER_HPP @@ -45,200 +45,206 @@ #include #include -#include "selection/Token.hpp" +#include "selection/SelectionToken.hpp" #include "selection/TokenMap.hpp" -namespace oopse { +#include "brains/SimInfo.hpp" +namespace OpenMD { -/** - * @class SelectionCompiler SelectionCompiler.hpp "selection/SelectionCompiler.hpp" - * @brief compile a selection script to tokens - * @todo document - *
 
-    expression       :: = clauseOr
+  /**
+   * @class SelectionCompiler SelectionCompiler.hpp "selection/SelectionCompiler.hpp"
+   * @brief compile a selection script to tokens
+   * @todo document
+   * 
 
-    clauseOr         ::= clauseAnd {OR clauseAnd}*
+   expression       :: = clauseOr
 
-    clauseAnd        ::= clauseNot {AND clauseNot}*
+   clauseOr         ::= clauseAnd {OR clauseAnd}*
 
-    clauseNot        ::= NOT clauseNot | clausePrimitive
+   clauseAnd        ::= clauseNot {AND clauseNot}*
 
-    clausePrimitive  ::= clauseComparator |
-                         clauseWithin |
-                         clauseName |
-                         none | all |
-                         ( clauseOr )
+   clauseNot        ::= NOT clauseNot | clausePrimitive
 
-    clauseComparator ::= atomproperty comparatorop integer
+   clausePrimitive  ::= clauseComparator |
+   clauseWithin |
+   clauseName |
+   none | all |
+   ( clauseOr )
 
-    clauseWithin     ::= WITHIN ( clauseDistance , expression )
+   clauseComparator ::= atomproperty comparatorop integer
 
-    clauseDistance   ::= integer | decimal
+   clauseWithin     ::= WITHIN ( clauseDistance , expression )
+
+   clauseDistance   ::= integer | decimal
         
-    clauseName::= *|string{.string{.string}}
+   clauseName::= *|string{.string{.string}}
 
 
- * 
- */ -class SelectionCompiler{ - public: - bool compile(const std::string& filename, const std::string& script ); + *
+ */ + class SelectionCompiler{ + public: + bool compile(const std::string& filename, const std::string& script ); - std::vector getLineNumbers() { - return lineNumbers; - } + std::vector getLineNumbers() { + return lineNumbers; + } - std::vector getLineIndices() { - return lineIndices; - } + std::vector getLineIndices() { + return lineIndices; + } - std::vector > getAatokenCompiled() { - return aatokenCompiled; - } + std::vector > getAatokenCompiled() { + return aatokenCompiled; + } - std::string getErrorMessage() { - std::string strError = errorMessage; - strError += " : " + errorLine + "\n"; + std::string getErrorMessage() { + std::string strError = errorMessage; + strError += " : " + errorLine + "\n"; - if (!filename.empty()) { - strError += filename; - } + if (!filename.empty()) { + strError += filename; + } - strError += " line#" + lineCurrent; - return strError; - } + return strError; + } - private: + private: - bool internalCompile(); + bool internalCompile(); - bool lookingAtLeadingWhitespace(); - //bool lookingAtComment(); - bool lookingAtEndOfLine(); - bool lookingAtEndOfStatement(); - bool lookingAtString(); - bool lookingAtDecimal(bool allowNegative); - bool lookingAtInteger(bool allowNegative); - bool lookingAtLookupToken(); - bool lookingAtSpecialString(); + bool lookingAtLeadingWhitespace(); + //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); + std::string getUnescapedStringLiteral(); + int getHexitValue(char ch); - bool compileCommand(const std::vector& ltoken); - bool compileExpression(); - bool compileExpression(int itoken); + bool compileCommand(const std::vector& ltoken); + bool compileExpression(); + bool compileExpression(int itoken); - bool clauseOr(); - bool clauseAnd(); - bool clauseNot(); - bool clausePrimitive(); - bool clauseWithin(); - bool clauseComparator(); - bool clauseChemObjName(); - bool clauseName(std::string& name); - bool clauseIndex(); - Token tokenNext(); - boost::any valuePeek(); - int tokPeek(); + bool clauseOr(); + bool clauseAnd(); + bool clauseNot(); + bool clausePrimitive(); + bool clauseWithin(); + bool clauseComparator(); + bool clauseChemObjName(); + bool clauseIndex(); + Token tokenNext(); + boost::any valuePeek(); + int tokPeek(); - bool addTokenToPostfix(const Token& token); + bool addTokenToPostfix(const Token& token); + bool isNameValid(const std::string& name); + bool compileError(const std::string& errorMsg) { - bool compileError(const std::string& errorMessage) { - std::cerr << "SelectionCompiler Error: " << errorMessage << std::endl; - error = true; - this->errorMessage = errorMessage; - return false; - } + sprintf( painCave.errMsg, + "SelectionCompiler Error: %s\n", errorMsg.c_str()); + painCave.severity = OPENMD_ERROR; + painCave.isFatal = 1; + simError(); + + error = true; + this->errorMessage = errorMsg; + return false; + } - bool commandExpected() { - return compileError("command expected"); - } + bool commandExpected() { + return compileError("command expected"); + } - bool invalidExpressionToken(const std::string& ident) { - return compileError("invalid expression token:" + ident); - } + bool invalidExpressionToken(const std::string& ident) { + return compileError("invalid expression token:" + ident); + } - bool unrecognizedToken() { - return compileError("unrecognized token"); - } + bool unrecognizedToken() { + return compileError("unrecognized token"); + } - bool badArgumentCount() { - return compileError("bad argument count"); - } + bool badArgumentCount() { + return compileError("bad argument count"); + } - bool endOfExpressionExpected() { - return compileError("end of expression expected"); - } + bool endOfExpressionExpected() { + return compileError("end of expression expected"); + } - bool leftParenthesisExpected() { - return compileError("left parenthesis expected"); - } + bool leftParenthesisExpected() { + return compileError("left parenthesis expected"); + } - bool rightParenthesisExpected() { - return compileError("right parenthesis expected"); - } + bool rightParenthesisExpected() { + return compileError("right parenthesis expected"); + } - bool commaExpected() { - return compileError("comma expected"); - } + bool commaExpected() { + return compileError("comma expected"); + } - bool unrecognizedExpressionToken() { - boost::any tmp = valuePeek(); - std::string tokenStr; + bool unrecognizedExpressionToken() { + boost::any tmp = valuePeek(); + std::string tokenStr; - try { - tokenStr = boost::any_cast(tmp); - } catch(const boost::bad_any_cast &) { - return compileError("any_cast error"); - } + try { + tokenStr = boost::any_cast(tmp); + } catch(const boost::bad_any_cast &) { + return compileError("any_cast error"); + } - return compileError("unrecognized expression token:" + tokenStr); - } + return compileError("unrecognized expression token:" + tokenStr); + } - bool comparisonOperatorExpected() { - return compileError("comparison operator expected"); - } + bool comparisonOperatorExpected() { + return compileError("comparison operator expected"); + } - bool numberExpected() { - return compileError("number expected"); - } + bool numberExpected() { + return compileError("number expected"); + } - bool numberOrKeywordExpected() { - return compileError("number or keyword expected"); - } + bool numberOrKeywordExpected() { + return compileError("number or keyword expected"); + } - std::string filename; - std::string script; + std::string filename; + std::string script; - std::vector lineNumbers; - std::vector lineIndices; - std::vector >aatokenCompiled; + std::vector lineNumbers; + std::vector lineIndices; + std::vector >aatokenCompiled; - bool error; - std::string errorMessage; - std::string errorLine; + bool error; + std::string errorMessage; + std::string errorLine; - int cchScript; - short lineCurrent; + int cchScript; + short lineCurrent; - int ichToken; - int cchToken; - std::vector atokenCommand; + int ichToken; + int cchToken; + std::vector atokenCommand; - int ichCurrentCommand; + int ichCurrentCommand; - std::vector ltokenPostfix; - std::vector atokenInfix; - int itokenInfix; + std::vector ltokenPostfix; + std::vector atokenInfix; + int itokenInfix; - //std::vector compiledTokens_; -}; + //std::vector compiledTokens_; + }; } #endif