| 41 |  |  | 
| 42 |  | #ifndef SELECTION_SELECTIONCOMPILER_HPP | 
| 43 |  | #define SELECTION_SELECTIONCOMPILER_HPP | 
| 44 | + | #include <iostream> | 
| 45 |  | #include <string> | 
| 46 |  | #include <vector> | 
| 47 | + |  | 
| 48 | + | #include "selection/Token.hpp" | 
| 49 | + | #include "selection/TokenMap.hpp" | 
| 50 |  | namespace oopse { | 
| 51 |  |  | 
| 52 |  |  | 
| 66 |  |  | 
| 67 |  | clausePrimitive  ::= clauseComparator | | 
| 68 |  | clauseWithin | | 
| 69 | < | clauseChemObject | | 
| 69 | > | clauseName | | 
| 70 |  | none | all | | 
| 71 |  | ( clauseOr ) | 
| 72 |  |  | 
| 75 |  | clauseWithin     ::= WITHIN ( clauseDistance , expression ) | 
| 76 |  |  | 
| 77 |  | clauseDistance   ::= integer | decimal | 
| 78 | < |  | 
| 79 | < | clauseChemObject::= {clauseMolecule} | {clauseStuntDouble} | 
| 78 | > |  | 
| 79 | > | clauseName::= *|string{.string{.string}} | 
| 80 |  |  | 
| 77 | – | clauseMolecule ::= {clauseMolName} | {clauseMolIndex} | 
| 81 |  |  | 
| 79 | – | clauseMolName ::= molname clauseName | 
| 80 | – |  | 
| 81 | – | clauseName::= *|string | 
| 82 | – |  | 
| 83 | – | clauseMolIndex ::= molindex clauseIndex | 
| 84 | – |  | 
| 85 | – | clauseIndex ::= integer {- integer } | 
| 86 | – |  | 
| 87 | – | clauseStuntDouble ::= {clauseStuntDoubleName} | {clauseStuntDoubleIndex} | 
| 88 | – |  | 
| 89 | – | clauseStuntDoubleName ::= name clauseName | 
| 90 | – |  | 
| 91 | – | clauseStuntDoubleIndex ::= index clauseIndex | 
| 92 | – |  | 
| 82 |  | * </pre> | 
| 83 |  | */ | 
| 84 |  | class SelectionCompiler{ | 
| 106 |  | strError += filename; | 
| 107 |  | } | 
| 108 |  |  | 
| 120 | – | strError += " line#" + lineCurrent; | 
| 109 |  | return strError; | 
| 110 |  | } | 
| 111 |  |  | 
| 112 |  |  | 
| 113 |  | private: | 
| 114 |  |  | 
| 115 | < | bool internalcompile(); | 
| 115 | > | bool internalCompile(); | 
| 116 |  |  | 
| 117 |  |  | 
| 118 |  | bool lookingAtLeadingWhitespace(); | 
| 119 | < | bool lookingAtComment(); | 
| 119 | > | //bool lookingAtComment(); | 
| 120 |  | bool lookingAtEndOfLine(); | 
| 121 |  | bool lookingAtEndOfStatement(); | 
| 122 |  | bool lookingAtString(); | 
| 123 | + | bool lookingAtDecimal(bool allowNegative); | 
| 124 | + | bool lookingAtInteger(bool allowNegative); | 
| 125 | + | bool lookingAtLookupToken(); | 
| 126 | + | bool lookingAtSpecialString(); | 
| 127 |  |  | 
| 128 | + | std::string getUnescapedStringLiteral(); | 
| 129 | + | int getHexitValue(char ch); | 
| 130 |  |  | 
| 131 | < | bool compileCommand(const std::vector<vector>&); | 
| 131 | > | bool compileCommand(const std::vector<Token>& ltoken); | 
| 132 | > | bool compileExpression(); | 
| 133 | > | bool compileExpression(int itoken); | 
| 134 |  |  | 
| 135 |  | bool clauseOr(); | 
| 136 |  | bool clauseAnd(); | 
| 138 |  | bool clausePrimitive(); | 
| 139 |  | bool clauseWithin(); | 
| 140 |  | bool clauseComparator(); | 
| 141 | < | bool clauseChemObject(); | 
| 146 | < | bool clauseMolecule(); | 
| 147 | < | bool clauseMolName(); | 
| 148 | < | bool clauseMolIndex(); | 
| 149 | < | bool clauseName(); | 
| 141 | > | bool clauseChemObjName(); | 
| 142 |  | bool clauseIndex(); | 
| 143 | < | bool clauseStuntDoubleName(); | 
| 144 | < | bool clauseStuntDoubleIndex(); | 
| 143 | > | Token tokenNext(); | 
| 144 | > | boost::any valuePeek(); | 
| 145 | > | int tokPeek(); | 
| 146 |  |  | 
| 147 | < | bool compileError(const std::string& errorMessage) { | 
| 148 | < | std::cerr << "SelectionCompiler Error: " << errorMessage <<  << std::endl; | 
| 147 | > | bool addTokenToPostfix(const Token& token); | 
| 148 | > | bool isNameValid(const std::string& name); | 
| 149 | > |  | 
| 150 | > | bool compileError(const std::string& errorMsg) { | 
| 151 | > | std::cerr << "SelectionCompiler Error: " << errorMsg << std::endl; | 
| 152 |  | error = true; | 
| 153 | < | this.errorMessage = errorMessage; | 
| 153 | > | this->errorMessage = errorMsg; | 
| 154 |  | return false; | 
| 155 |  | } | 
| 156 |  |  | 
| 187 |  | } | 
| 188 |  |  | 
| 189 |  | bool unrecognizedExpressionToken() { | 
| 190 | < | return compileError("unrecognized expression token:" + valuePeek()); | 
| 190 | > | boost::any tmp = valuePeek(); | 
| 191 | > | std::string tokenStr; | 
| 192 | > |  | 
| 193 | > | try { | 
| 194 | > | tokenStr = boost::any_cast<std::string>(tmp); | 
| 195 | > | } catch(const boost::bad_any_cast &) { | 
| 196 | > | return compileError("any_cast error"); | 
| 197 | > | } | 
| 198 | > |  | 
| 199 | > | return compileError("unrecognized expression token:" + tokenStr); | 
| 200 |  | } | 
| 201 |  |  | 
| 202 |  | bool comparisonOperatorExpected() { | 
| 203 |  | return compileError("comparison operator expected"); | 
| 204 |  | } | 
| 205 |  |  | 
| 206 | < | bool integerExpected() { | 
| 207 | < | return compileError("integer expected"); | 
| 206 | > | bool numberExpected() { | 
| 207 | > | return compileError("number expected"); | 
| 208 |  | } | 
| 209 |  |  | 
| 210 | + | bool numberOrKeywordExpected() { | 
| 211 | + | return compileError("number or keyword expected"); | 
| 212 | + | } | 
| 213 |  |  | 
| 214 |  | std::string filename; | 
| 215 |  | std::string script; |