--- trunk/OOPSE-4/src/selection/SelectionCompiler.hpp 2005/02/01 06:55:00 1961 +++ trunk/OOPSE-4/src/selection/SelectionCompiler.hpp 2005/02/01 22:49:23 1962 @@ -41,7 +41,7 @@ #ifndef SELECTION_SELECTIONCOMPILER_HPP #define SELECTION_SELECTIONCOMPILER_HPP - +#include #include namespace oopse { @@ -49,6 +49,7 @@ namespace oopse { /** * @class SelectionCompiler SelectionCompiler.hpp "selection/SelectionCompiler.hpp" * @brief compile a selection script to tokens + * @todo document *
 
     expression       :: = clauseOr
@@ -61,7 +62,7 @@ namespace oopse {
 
     clausePrimitive  ::= clauseComparator |
                          clauseWithin |
-                         clauseResidueSpec |
+                         clauseChemObject |
                          none | all |
                          ( clauseOr )
 
@@ -70,58 +71,165 @@ namespace oopse {
     clauseWithin     ::= WITHIN ( clauseDistance , expression )
 
     clauseDistance   ::= integer | decimal
-
     
+    clauseChemObject::= {clauseMolecule} | {clauseStuntDouble}
 
+    clauseMolecule ::= {clauseMolName} | {clauseMolIndex}
 
-    clauseResidueSpec::= { clauseResNameSpec }
-                         { clauseResNumSpec }
-                         { chainSpec }
-                         { clauseAtomSpec }
-                         { modelSpec }
+    clauseMolName ::= molname clauseName
+    
+    clauseName::= *|string
 
-    clauseResNameSpec::= * | [ resNamePattern ] | resNamePattern
+    clauseMolIndex ::= molindex clauseIndex
+    
+    clauseIndex ::= integer {- integer }
+    
+    clauseStuntDouble ::= {clauseStuntDoubleName} | {clauseStuntDoubleIndex}
 
-    // question marks are part of identifiers
-    // they get split up and dealt with as wildcards at runtime
-    // and the integers which are residue number chains get bundled
-    // in with the identifier and also split out at runtime
-    // iff a variable of that name does not exist
+    clauseStuntDoubleName ::= name clauseName
 
-    resNamePattern   ::= up to 3 alphanumeric chars with * and ?
+    clauseStuntDoubleIndex ::= index clauseIndex
 
-    clauseResNumSpec ::= * | clauseSequenceRange
+ * 
+ */ +class SelectionCompiler{ + public: + bool compile(const std::string& filename, const std::string& script ); + - clauseSequenceRange ::= clauseSequenceCode { - clauseSequenceCode } + std::vector getLineNumbers() { + return lineNumbers; + } - clauseSequenceCode ::= seqcode | {-} integer + std::vector getLineIndices() { + return lineIndices; + } - clauseChainSpec ::= {:} * | identifier | integer + std::vector > getAatokenCompiled() { + return aatokenCompiled; + } - clauseAtomSpec ::= . * | . identifier {*} // note that this * is *not* a wildcard + std::string getErrorMessage() { + std::string strError = errorMessage; + strError += " : " + errorLine + "\n"; - clauseModelSpec ::= {:|/} * | integer - - * - */ -class SelectionCompiler{ - public: - bool compile(); + if (!filename.empty()) { + strError += filename; + } - std::vector getCompiledTokens(); + strError += " line#" + lineCurrent; + return strError; + } + + private: + bool internalcompile(); + + + bool lookingAtLeadingWhitespace(); + bool lookingAtComment(); + bool lookingAtEndOfLine(); + bool lookingAtEndOfStatement(); + bool lookingAtString(); + + + bool compileCommand(const std::vector&); + bool clauseOr(); bool clauseAnd(); bool clauseNot(); bool clausePrimitive(); bool clauseWithin(); bool clauseComparator(); + bool clauseChemObject(); + bool clauseMolecule(); + bool clauseMolName(); + bool clauseMolIndex(); + bool clauseName(); + bool clauseIndex(); + bool clauseStuntDoubleName(); + bool clauseStuntDoubleIndex(); + + bool compileError(const std::string& errorMessage) { + std::cerr << "SelectionCompiler Error: " << errorMessage << << std::endl; + error = true; + this.errorMessage = errorMessage; + return false; + } - internalCompile(); + bool commandExpected() { + return compileError("command expected"); + } - std::vector compiledTokens_; + bool invalidExpressionToken(const std::string& ident) { + return compileError("invalid expression token:" + ident); + } + + bool unrecognizedToken() { + return compileError("unrecognized token"); + } + + bool badArgumentCount() { + return compileError("bad argument count"); + } + + bool endOfExpressionExpected() { + return compileError("end of expression expected"); + } + + bool leftParenthesisExpected() { + return compileError("left parenthesis expected"); + } + + bool rightParenthesisExpected() { + return compileError("right parenthesis expected"); + } + + bool commaExpected() { + return compileError("comma expected"); + } + + bool unrecognizedExpressionToken() { + return compileError("unrecognized expression token:" + valuePeek()); + } + + bool comparisonOperatorExpected() { + return compileError("comparison operator expected"); + } + + bool integerExpected() { + return compileError("integer expected"); + } + + + std::string filename; + std::string script; + + std::vector lineNumbers; + std::vector lineIndices; + std::vector >aatokenCompiled; + + bool error; + std::string errorMessage; + std::string errorLine; + + int cchScript; + short lineCurrent; + + int ichToken; + int cchToken; + std::vector atokenCommand; + + int ichCurrentCommand; + + std::vector ltokenPostfix; + std::vector atokenInfix; + int itokenInfix; + + //std::vector compiledTokens_; }; } #endif +