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

Comparing trunk/src/selection/SelectionCompiler.hpp (file contents):
Revision 278 by tim, Tue Feb 1 22:49:23 2005 UTC vs.
Revision 1879 by gezelter, Sun Jun 16 15:15:42 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
44   #define SELECTION_SELECTIONCOMPILER_HPP
45 + #include <iostream>
46   #include <string>
47   #include <vector>
46 namespace oopse {
48  
49 + #include "selection/SelectionToken.hpp"
50 + #include "selection/TokenMap.hpp"
51 + #include "brains/SimInfo.hpp"
52  
53 < /**
50 < * @class SelectionCompiler SelectionCompiler.hpp "selection/SelectionCompiler.hpp"
51 < * @brief compile a selection script to tokens
52 < * @todo document
53 < * <pre>
53 > namespace OpenMD {
54  
55    expression       :: = clauseOr
55  
56 <    clauseOr         ::= clauseAnd {OR clauseAnd}*
56 >  /**
57 >   * @class SelectionCompiler SelectionCompiler.hpp "selection/SelectionCompiler.hpp"
58 >   * @brief compile a selection script to tokens
59 >   * @todo document
60 >   * <pre>
61  
62 <    clauseAnd        ::= clauseNot {AND clauseNot}*
62 >   expression       :: = clauseOr
63  
64 <    clauseNot        ::= NOT clauseNot | clausePrimitive
64 >   clauseOr         ::= clauseAnd {OR clauseAnd}*
65  
66 <    clausePrimitive  ::= clauseComparator |
64 <                         clauseWithin |
65 <                         clauseChemObject |
66 <                         none | all |
67 <                         ( clauseOr )
66 >   clauseAnd        ::= clauseNot {AND clauseNot}*
67  
68 <    clauseComparator ::= atomproperty comparatorop integer
68 >   clauseNot        ::= NOT clauseNot | clausePrimitive
69  
70 <    clauseWithin     ::= WITHIN ( clauseDistance , expression )
70 >   clausePrimitive  ::= clauseComparator |
71 >   clauseWithin |
72 >   clauseName |
73 >   none | all |
74 >   ( clauseOr )
75  
76 <    clauseDistance   ::= integer | decimal
74 <    
75 <    clauseChemObject::= {clauseMolecule} | {clauseStuntDouble}
76 >   clauseComparator ::= atomproperty comparatorop integer
77  
78 <    clauseMolecule ::= {clauseMolName} | {clauseMolIndex}
78 >   clauseWithin     ::= WITHIN ( clauseDistance , expression )
79  
80 <    clauseMolName ::= molname clauseName
81 <    
82 <    clauseName::= *|string
80 >   clauseDistance   ::= integer | decimal
81 >        
82 >   clauseName::= *|string{.string{.string}}
83  
83    clauseMolIndex ::= molindex clauseIndex
84    
85    clauseIndex ::= integer {- integer }
86    
87    clauseStuntDouble ::= {clauseStuntDoubleName} | {clauseStuntDoubleIndex}
84  
85 <    clauseStuntDoubleName ::= name clauseName
86 <
87 <    clauseStuntDoubleIndex ::= index clauseIndex
88 <
89 < * </pre>
94 < */
95 < class SelectionCompiler{
96 <    public:
97 <        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 <            strError += " line#" + lineCurrent;
113 <            return strError;
122 <        }
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();
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);        
133  
134 <        bool compileCommand(const std::vector<vector>&);
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 clauseChemObject();
145 <        bool clauseMolecule();
146 <        bool clauseMolName();
147 <        bool clauseMolIndex();
148 <        bool clauseName();
150 <        bool clauseIndex();
151 <        bool clauseStuntDoubleName();
152 <        bool clauseStuntDoubleIndex();
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 compileError(const std::string& errorMessage) {
151 <            std::cerr << "SelectionCompiler Error: " << errorMessage <<  << std::endl;
152 <            error = true;
153 <            this.errorMessage = errorMessage;
154 <            return false;
155 <        }
150 >    bool addTokenToPostfix(const Token& token);
151 >    bool isNameValid(const std::string& name);
152 >
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 <            return compileError("unrecognized expression token:" + valuePeek());
200 <        }
198 >    bool unrecognizedExpressionToken() {
199 >      boost::any tmp = valuePeek();
200 >      std::string tokenStr;
201  
202 <        bool comparisonOperatorExpected() {
203 <            return compileError("comparison operator expected");
204 <        }
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 >    }
210  
211 <        bool integerExpected() {
212 <            return compileError("integer expected");
213 <        }        
211 >    bool comparisonOperatorExpected() {
212 >      return compileError("comparison operator expected");
213 >    }
214 >
215 >    bool numberExpected() {
216 >      return compileError("number expected");
217 >    }        
218          
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 278 by tim, Tue Feb 1 22:49:23 2005 UTC vs.
Revision 1879 by gezelter, Sun Jun 16 15:15:42 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines