ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/selection/SelectionCompiler.hpp
(Generate patch)

Comparing:
trunk/src/selection/SelectionCompiler.hpp (file contents), Revision 494 by tim, Wed Apr 13 22:43:43 2005 UTC vs.
branches/development/src/selection/SelectionCompiler.hpp (file contents), Revision 1850 by gezelter, Wed Feb 20 15:39:39 2013 UTC

# Line 6 | Line 6
6   * redistribute this software in source and binary code form, provided
7   * that the following conditions are met:
8   *
9 < * 1. Acknowledgement of the program authors must be made in any
10 < *    publication of scientific results based in part on use of the
11 < *    program.  An acceptable form of acknowledgement is citation of
12 < *    the article in which the program was described (Matthew
13 < *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 < *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 < *    Parallel Simulation Engine for Molecular Dynamics,"
16 < *    J. Comput. Chem. 26, pp. 252-271 (2005))
17 < *
18 < * 2. Redistributions of source code must retain the above copyright
9 > * 1. Redistributions of source code must retain the above copyright
10   *    notice, this list of conditions and the following disclaimer.
11   *
12 < * 3. Redistributions in binary form must reproduce the above copyright
12 > * 2. Redistributions in binary form must reproduce the above copyright
13   *    notice, this list of conditions and the following disclaimer in the
14   *    documentation and/or other materials provided with the
15   *    distribution.
# Line 37 | Line 28
28   * arising out of the use of or inability to use software, even if the
29   * University of Notre Dame has been advised of the possibility of
30   * such damages.
31 + *
32 + * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your
33 + * research, please cite the appropriate papers when you publish your
34 + * work.  Good starting points are:
35 + *                                                                      
36 + * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).            
37 + * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).          
38 + * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).          
39 + * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010).
40 + * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41   */
42  
43   #ifndef SELECTION_SELECTIONCOMPILER_HPP
# Line 45 | Line 46
46   #include <string>
47   #include <vector>
48  
49 < #include "selection/Token.hpp"
49 > #include "selection/SelectionToken.hpp"
50   #include "selection/TokenMap.hpp"
51 < namespace oopse {
51 > #include "brains/SimInfo.hpp"
52  
53 + namespace OpenMD {
54  
53 /**
54 * @class SelectionCompiler SelectionCompiler.hpp "selection/SelectionCompiler.hpp"
55 * @brief compile a selection script to tokens
56 * @todo document
57 * <pre>
55  
56 <    expression       :: = clauseOr
56 >  /**
57 >   * @class SelectionCompiler SelectionCompiler.hpp "selection/SelectionCompiler.hpp"
58 >   * @brief compile a selection script to tokens
59 >   * @todo document
60 >   * <pre>
61  
62 <    clauseOr         ::= clauseAnd {OR clauseAnd}*
62 >   expression       :: = clauseOr
63  
64 <    clauseAnd        ::= clauseNot {AND clauseNot}*
64 >   clauseOr         ::= clauseAnd {OR clauseAnd}*
65  
66 <    clauseNot        ::= NOT clauseNot | clausePrimitive
66 >   clauseAnd        ::= clauseNot {AND clauseNot}*
67  
68 <    clausePrimitive  ::= clauseComparator |
68 <                         clauseWithin |
69 <                         clauseName |
70 <                         none | all |
71 <                         ( clauseOr )
68 >   clauseNot        ::= NOT clauseNot | clausePrimitive
69  
70 <    clauseComparator ::= atomproperty comparatorop integer
70 >   clausePrimitive  ::= clauseComparator |
71 >   clauseWithin |
72 >   clauseName |
73 >   none | all |
74 >   ( clauseOr )
75  
76 <    clauseWithin     ::= WITHIN ( clauseDistance , expression )
76 >   clauseComparator ::= atomproperty comparatorop integer
77  
78 <    clauseDistance   ::= integer | decimal
78 >   clauseWithin     ::= WITHIN ( clauseDistance , expression )
79 >
80 >   clauseDistance   ::= integer | decimal
81          
82 <    clauseName::= *|string{.string{.string}}
82 >   clauseName::= *|string{.string{.string}}
83  
84  
85 < * </pre>
86 < */
87 < class SelectionCompiler{
88 <    public:
89 <        bool compile(const std::string& filename, const std::string& script );
85 >   * </pre>
86 >   */
87 >  class SelectionCompiler{
88 >  public:
89 >    bool compile(const std::string& filename, const std::string& script );
90          
91  
92 <        std::vector<int> getLineNumbers() {
93 <            return lineNumbers;
94 <        }
92 >    std::vector<int> getLineNumbers() {
93 >      return lineNumbers;
94 >    }
95  
96 <        std::vector<int> getLineIndices() {
97 <            return lineIndices;
98 <        }
96 >    std::vector<int> getLineIndices() {
97 >      return lineIndices;
98 >    }
99  
100 <        std::vector<std::vector<Token> > getAatokenCompiled() {
101 <            return aatokenCompiled;
102 <        }
100 >    std::vector<std::vector<Token> > getAatokenCompiled() {
101 >      return aatokenCompiled;
102 >    }
103  
104 <        std::string getErrorMessage() {
105 <            std::string strError = errorMessage;
106 <            strError += " : " + errorLine + "\n";
104 >    std::string getErrorMessage() {
105 >      std::string strError = errorMessage;
106 >      strError += " : " + errorLine + "\n";
107  
108 <            if (!filename.empty()) {
109 <                strError += filename;
110 <            }
108 >      if (!filename.empty()) {
109 >        strError += filename;
110 >      }
111  
112 <            return strError;
113 <        }
112 >      return strError;
113 >    }
114  
115          
116 <    private:
116 >  private:
117  
118 <        bool internalCompile();
118 >    bool internalCompile();
119  
120  
121 <        bool lookingAtLeadingWhitespace();
122 <        //bool lookingAtComment();
123 <        bool lookingAtEndOfLine();
124 <        bool lookingAtEndOfStatement();
125 <        bool lookingAtString();
126 <        bool lookingAtDecimal(bool allowNegative);
127 <        bool lookingAtInteger(bool allowNegative);
128 <        bool lookingAtLookupToken();
129 <        bool lookingAtSpecialString();
121 >    bool lookingAtLeadingWhitespace();
122 >    //bool lookingAtComment();
123 >    bool lookingAtEndOfLine();
124 >    bool lookingAtEndOfStatement();
125 >    bool lookingAtString();
126 >    bool lookingAtDecimal(bool allowNegative);
127 >    bool lookingAtInteger(bool allowNegative);
128 >    bool lookingAtLookupToken();
129 >    bool lookingAtSpecialString();
130  
131 <        std::string getUnescapedStringLiteral();
132 <        int getHexitValue(char ch);        
131 >    std::string getUnescapedStringLiteral();
132 >    int getHexitValue(char ch);        
133  
134 <        bool compileCommand(const std::vector<Token>& ltoken);
135 <        bool compileExpression();        
136 <        bool compileExpression(int itoken);        
134 >    bool compileCommand(const std::vector<Token>& ltoken);
135 >    bool compileExpression();        
136 >    bool compileExpression(int itoken);        
137          
138 <        bool clauseOr();
139 <        bool clauseAnd();
140 <        bool clauseNot();
141 <        bool clausePrimitive();
142 <        bool clauseWithin();
143 <        bool clauseComparator();
144 <        bool clauseChemObjName();        
145 <        bool clauseIndex();
146 <        Token tokenNext();
147 <        boost::any valuePeek();
148 <        int tokPeek();
138 >    bool clauseOr();
139 >    bool clauseAnd();
140 >    bool clauseNot();
141 >    bool clausePrimitive();
142 >    bool clauseWithin();
143 >    bool clauseComparator();
144 >    bool clauseChemObjName();        
145 >    bool clauseIndex();
146 >    Token tokenNext();
147 >    boost::any valuePeek();
148 >    int tokPeek();
149  
150 <        bool addTokenToPostfix(const Token& token);
151 <        bool isNameValid(const std::string& name);
150 >    bool addTokenToPostfix(const Token& token);
151 >    bool isNameValid(const std::string& name);
152  
153 <        bool compileError(const std::string& errorMsg) {
154 <            std::cerr << "SelectionCompiler Error: " << errorMsg << std::endl;
155 <            error = true;
156 <            this->errorMessage = errorMsg;
157 <            return false;
158 <        }
153 >    bool compileError(const std::string& errorMsg) {
154 >
155 >      sprintf( painCave.errMsg,
156 >               "SelectionCompiler Error: %s\n", errorMsg.c_str());
157 >      painCave.severity = OPENMD_ERROR;
158 >      painCave.isFatal = 1;
159 >      simError();
160 >
161 >      error = true;
162 >      this->errorMessage = errorMsg;
163 >      return false;
164 >    }
165          
166 <        bool commandExpected() {
167 <            return compileError("command expected");
168 <        }
166 >    bool commandExpected() {
167 >      return compileError("command expected");
168 >    }
169  
170 <        bool invalidExpressionToken(const std::string& ident) {
171 <            return compileError("invalid expression token:" + ident);
172 <        }
170 >    bool invalidExpressionToken(const std::string& ident) {
171 >      return compileError("invalid expression token:" + ident);
172 >    }
173  
174 <        bool unrecognizedToken() {
175 <            return compileError("unrecognized token");
176 <        }
174 >    bool unrecognizedToken() {
175 >      return compileError("unrecognized token");
176 >    }
177  
178 <        bool badArgumentCount() {
179 <            return compileError("bad argument count");
180 <        }
178 >    bool badArgumentCount() {
179 >      return compileError("bad argument count");
180 >    }
181  
182 <        bool endOfExpressionExpected() {
183 <            return compileError("end of expression expected");
184 <        }
182 >    bool endOfExpressionExpected() {
183 >      return compileError("end of expression expected");
184 >    }
185  
186 <        bool leftParenthesisExpected() {
187 <            return compileError("left parenthesis expected");
188 <        }
186 >    bool leftParenthesisExpected() {
187 >      return compileError("left parenthesis expected");
188 >    }
189  
190 <        bool rightParenthesisExpected() {
191 <            return compileError("right parenthesis expected");
192 <        }
190 >    bool rightParenthesisExpected() {
191 >      return compileError("right parenthesis expected");
192 >    }
193  
194 <        bool commaExpected() {
195 <            return compileError("comma expected");
196 <        }
194 >    bool commaExpected() {
195 >      return compileError("comma expected");
196 >    }
197  
198 <        bool unrecognizedExpressionToken() {
199 <            boost::any tmp = valuePeek();
200 <            std::string tokenStr;
198 >    bool unrecognizedExpressionToken() {
199 >      boost::any tmp = valuePeek();
200 >      std::string tokenStr;
201  
202 <            try {
203 <                tokenStr = boost::any_cast<std::string>(tmp);                
204 <            } catch(const boost::bad_any_cast &) {
205 <                return compileError("any_cast error");
206 <            }
202 >      try {
203 >        tokenStr = boost::any_cast<std::string>(tmp);                
204 >      } catch(const boost::bad_any_cast &) {
205 >        return compileError("any_cast error");
206 >      }
207              
208 <            return compileError("unrecognized expression token:" + tokenStr);
209 <        }
208 >      return compileError("unrecognized expression token:" + tokenStr);
209 >    }
210  
211 <        bool comparisonOperatorExpected() {
212 <            return compileError("comparison operator expected");
213 <        }
211 >    bool comparisonOperatorExpected() {
212 >      return compileError("comparison operator expected");
213 >    }
214  
215 <        bool numberExpected() {
216 <            return compileError("number expected");
217 <        }        
215 >    bool numberExpected() {
216 >      return compileError("number expected");
217 >    }        
218          
219 <        bool numberOrKeywordExpected() {
220 <            return compileError("number or keyword expected");
221 <        }        
219 >    bool numberOrKeywordExpected() {
220 >      return compileError("number or keyword expected");
221 >    }        
222          
223 <        std::string filename;
224 <        std::string script;
223 >    std::string filename;
224 >    std::string script;
225  
226 <        std::vector<int> lineNumbers;
227 <        std::vector<int> lineIndices;
228 <        std::vector<std::vector<Token> >aatokenCompiled;
226 >    std::vector<int> lineNumbers;
227 >    std::vector<int> lineIndices;
228 >    std::vector<std::vector<Token> >aatokenCompiled;
229  
230 <        bool error;
231 <        std::string errorMessage;
232 <        std::string errorLine;
230 >    bool error;
231 >    std::string errorMessage;
232 >    std::string errorLine;
233  
234 <        int cchScript;
235 <        short lineCurrent;
234 >    int cchScript;
235 >    short lineCurrent;
236  
237 <        int ichToken;
238 <        int cchToken;
239 <        std::vector<Token> atokenCommand;
237 >    int ichToken;
238 >    int cchToken;
239 >    std::vector<Token> atokenCommand;
240  
241 <        int ichCurrentCommand;
241 >    int ichCurrentCommand;
242  
243 <        std::vector<Token> ltokenPostfix;
244 <        std::vector<Token> atokenInfix;
245 <        int itokenInfix;
243 >    std::vector<Token> ltokenPostfix;
244 >    std::vector<Token> atokenInfix;
245 >    int itokenInfix;
246  
247 <        //std::vector<Token> compiledTokens_;
248 < };
247 >    //std::vector<Token> compiledTokens_;
248 >  };
249  
250   }
251   #endif

Comparing:
trunk/src/selection/SelectionCompiler.hpp (property svn:keywords), Revision 494 by tim, Wed Apr 13 22:43:43 2005 UTC vs.
branches/development/src/selection/SelectionCompiler.hpp (property svn:keywords), Revision 1850 by gezelter, Wed Feb 20 15:39:39 2013 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines