ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/selection/SelectionCompiler.hpp
Revision: 2204
Committed: Fri Apr 15 22:04:00 2005 UTC (19 years, 3 months ago) by gezelter
File size: 6810 byte(s)
Log Message:
xemacs has been drafted to perform our indentation services

File Contents

# User Rev Content
1 tim 1961 /*
2     * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3     *
4     * The University of Notre Dame grants you ("Licensee") a
5     * non-exclusive, royalty free, license to use, modify and
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
19     * notice, this list of conditions and the following disclaimer.
20     *
21     * 3. Redistributions in binary form must reproduce the above copyright
22     * notice, this list of conditions and the following disclaimer in the
23     * documentation and/or other materials provided with the
24     * distribution.
25     *
26     * This software is provided "AS IS," without a warranty of any
27     * kind. All express or implied conditions, representations and
28     * warranties, including any implied warranty of merchantability,
29     * fitness for a particular purpose or non-infringement, are hereby
30     * excluded. The University of Notre Dame and its licensors shall not
31     * be liable for any damages suffered by licensee as a result of
32     * using, modifying or distributing the software or its
33     * derivatives. In no event will the University of Notre Dame or its
34     * licensors be liable for any lost revenue, profit or data, or for
35     * direct, indirect, special, consequential, incidental or punitive
36     * damages, however caused and regardless of the theory of liability,
37     * arising out of the use of or inability to use software, even if the
38     * University of Notre Dame has been advised of the possibility of
39     * such damages.
40     */
41    
42     #ifndef SELECTION_SELECTIONCOMPILER_HPP
43     #define SELECTION_SELECTIONCOMPILER_HPP
44 tim 1965 #include <iostream>
45 tim 1962 #include <string>
46 tim 1961 #include <vector>
47 tim 1965
48     #include "selection/Token.hpp"
49     #include "selection/TokenMap.hpp"
50 tim 1961 namespace oopse {
51    
52    
53 gezelter 2204 /**
54     * @class SelectionCompiler SelectionCompiler.hpp "selection/SelectionCompiler.hpp"
55     * @brief compile a selection script to tokens
56     * @todo document
57     * <pre>
58 tim 1961
59 gezelter 2204 expression :: = clauseOr
60 tim 1961
61 gezelter 2204 clauseOr ::= clauseAnd {OR clauseAnd}*
62 tim 1961
63 gezelter 2204 clauseAnd ::= clauseNot {AND clauseNot}*
64 tim 1961
65 gezelter 2204 clauseNot ::= NOT clauseNot | clausePrimitive
66 tim 1961
67 gezelter 2204 clausePrimitive ::= clauseComparator |
68     clauseWithin |
69     clauseName |
70     none | all |
71     ( clauseOr )
72 tim 1961
73 gezelter 2204 clauseComparator ::= atomproperty comparatorop integer
74 tim 1961
75 gezelter 2204 clauseWithin ::= WITHIN ( clauseDistance , expression )
76 tim 1961
77 gezelter 2204 clauseDistance ::= integer | decimal
78 tim 1967
79 gezelter 2204 clauseName::= *|string{.string{.string}}
80 tim 1961
81 tim 1962
82 gezelter 2204 * </pre>
83     */
84     class SelectionCompiler{
85     public:
86     bool compile(const std::string& filename, const std::string& script );
87 tim 1962
88 tim 1961
89 gezelter 2204 std::vector<int> getLineNumbers() {
90     return lineNumbers;
91     }
92 tim 1961
93 gezelter 2204 std::vector<int> getLineIndices() {
94     return lineIndices;
95     }
96 tim 1961
97 gezelter 2204 std::vector<std::vector<Token> > getAatokenCompiled() {
98     return aatokenCompiled;
99     }
100 tim 1961
101 gezelter 2204 std::string getErrorMessage() {
102     std::string strError = errorMessage;
103     strError += " : " + errorLine + "\n";
104 tim 1961
105 gezelter 2204 if (!filename.empty()) {
106     strError += filename;
107     }
108 tim 1961
109 gezelter 2204 return strError;
110     }
111 tim 1961
112 tim 1962
113 gezelter 2204 private:
114 tim 1961
115 gezelter 2204 bool internalCompile();
116 tim 1962
117    
118 gezelter 2204 bool lookingAtLeadingWhitespace();
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 tim 1962
128 gezelter 2204 std::string getUnescapedStringLiteral();
129     int getHexitValue(char ch);
130 tim 1962
131 gezelter 2204 bool compileCommand(const std::vector<Token>& ltoken);
132     bool compileExpression();
133     bool compileExpression(int itoken);
134 tim 1962
135 gezelter 2204 bool clauseOr();
136     bool clauseAnd();
137     bool clauseNot();
138     bool clausePrimitive();
139     bool clauseWithin();
140     bool clauseComparator();
141     bool clauseChemObjName();
142     bool clauseIndex();
143     Token tokenNext();
144     boost::any valuePeek();
145     int tokPeek();
146 tim 1965
147 gezelter 2204 bool addTokenToPostfix(const Token& token);
148     bool isNameValid(const std::string& name);
149 tim 1965
150 gezelter 2204 bool compileError(const std::string& errorMsg) {
151     std::cerr << "SelectionCompiler Error: " << errorMsg << std::endl;
152     error = true;
153     this->errorMessage = errorMsg;
154     return false;
155     }
156 tim 1961
157 gezelter 2204 bool commandExpected() {
158     return compileError("command expected");
159     }
160 tim 1961
161 gezelter 2204 bool invalidExpressionToken(const std::string& ident) {
162     return compileError("invalid expression token:" + ident);
163     }
164 tim 1962
165 gezelter 2204 bool unrecognizedToken() {
166     return compileError("unrecognized token");
167     }
168 tim 1962
169 gezelter 2204 bool badArgumentCount() {
170     return compileError("bad argument count");
171     }
172 tim 1962
173 gezelter 2204 bool endOfExpressionExpected() {
174     return compileError("end of expression expected");
175     }
176 tim 1962
177 gezelter 2204 bool leftParenthesisExpected() {
178     return compileError("left parenthesis expected");
179     }
180 tim 1962
181 gezelter 2204 bool rightParenthesisExpected() {
182     return compileError("right parenthesis expected");
183     }
184 tim 1962
185 gezelter 2204 bool commaExpected() {
186     return compileError("comma expected");
187     }
188 tim 1962
189 gezelter 2204 bool unrecognizedExpressionToken() {
190     boost::any tmp = valuePeek();
191     std::string tokenStr;
192 tim 1965
193 gezelter 2204 try {
194     tokenStr = boost::any_cast<std::string>(tmp);
195     } catch(const boost::bad_any_cast &) {
196     return compileError("any_cast error");
197     }
198 tim 1965
199 gezelter 2204 return compileError("unrecognized expression token:" + tokenStr);
200     }
201 tim 1962
202 gezelter 2204 bool comparisonOperatorExpected() {
203     return compileError("comparison operator expected");
204     }
205 tim 1962
206 gezelter 2204 bool numberExpected() {
207     return compileError("number expected");
208     }
209 tim 1962
210 gezelter 2204 bool numberOrKeywordExpected() {
211     return compileError("number or keyword expected");
212     }
213 tim 1962
214 gezelter 2204 std::string filename;
215     std::string script;
216 tim 1962
217 gezelter 2204 std::vector<int> lineNumbers;
218     std::vector<int> lineIndices;
219     std::vector<std::vector<Token> >aatokenCompiled;
220 tim 1962
221 gezelter 2204 bool error;
222     std::string errorMessage;
223     std::string errorLine;
224 tim 1962
225 gezelter 2204 int cchScript;
226     short lineCurrent;
227 tim 1962
228 gezelter 2204 int ichToken;
229     int cchToken;
230     std::vector<Token> atokenCommand;
231 tim 1962
232 gezelter 2204 int ichCurrentCommand;
233 tim 1962
234 gezelter 2204 std::vector<Token> ltokenPostfix;
235     std::vector<Token> atokenInfix;
236     int itokenInfix;
237 tim 1962
238 gezelter 2204 //std::vector<Token> compiledTokens_;
239     };
240 tim 1961
241     }
242     #endif
243 tim 1962