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

Comparing trunk/OOPSE-4/src/selection/SelectionCompiler.hpp (file contents):
Revision 1961 by tim, Tue Feb 1 06:55:00 2005 UTC vs.
Revision 1962 by tim, Tue Feb 1 22:49:23 2005 UTC

# Line 41 | Line 41
41  
42   #ifndef SELECTION_SELECTIONCOMPILER_HPP
43   #define SELECTION_SELECTIONCOMPILER_HPP
44 <
44 > #include <string>
45   #include <vector>
46   namespace oopse {
47  
# Line 49 | Line 49 | namespace oopse {
49   /**
50   * @class SelectionCompiler SelectionCompiler.hpp "selection/SelectionCompiler.hpp"
51   * @brief compile a selection script to tokens
52 + * @todo document
53   * <pre>
54  
55      expression       :: = clauseOr
# Line 61 | Line 62 | namespace oopse {
62  
63      clausePrimitive  ::= clauseComparator |
64                           clauseWithin |
65 <                         clauseResidueSpec |
65 >                         clauseChemObject |
66                           none | all |
67                           ( clauseOr )
68  
# Line 70 | Line 71 | namespace oopse {
71      clauseWithin     ::= WITHIN ( clauseDistance , expression )
72  
73      clauseDistance   ::= integer | decimal
73
74      
75 +    clauseChemObject::= {clauseMolecule} | {clauseStuntDouble}
76  
77 +    clauseMolecule ::= {clauseMolName} | {clauseMolIndex}
78  
79 <    clauseResidueSpec::= { clauseResNameSpec }
80 <                         { clauseResNumSpec }
81 <                         { chainSpec }
80 <                         { clauseAtomSpec }
81 <                         { modelSpec }
79 >    clauseMolName ::= molname clauseName
80 >    
81 >    clauseName::= *|string
82  
83 <    clauseResNameSpec::= * | [ resNamePattern ] | resNamePattern
83 >    clauseMolIndex ::= molindex clauseIndex
84 >    
85 >    clauseIndex ::= integer {- integer }
86 >    
87 >    clauseStuntDouble ::= {clauseStuntDoubleName} | {clauseStuntDoubleIndex}
88  
89 <    // question marks are part of identifiers
86 <    // they get split up and dealt with as wildcards at runtime
87 <    // and the integers which are residue number chains get bundled
88 <    // in with the identifier and also split out at runtime
89 <    // iff a variable of that name does not exist
89 >    clauseStuntDoubleName ::= name clauseName
90  
91 <    resNamePattern   ::= up to 3 alphanumeric chars with * and ?
91 >    clauseStuntDoubleIndex ::= index clauseIndex
92  
93 <    clauseResNumSpec ::= * | clauseSequenceRange
93 > * </pre>
94 > */
95 > class SelectionCompiler{
96 >    public:
97 >        bool compile(const std::string& filename, const std::string& script );
98 >        
99  
100 <    clauseSequenceRange ::= clauseSequenceCode { - clauseSequenceCode }
100 >        std::vector<int> getLineNumbers() {
101 >            return lineNumbers;
102 >        }
103  
104 <    clauseSequenceCode ::= seqcode | {-} integer
104 >        std::vector<int> getLineIndices() {
105 >            return lineIndices;
106 >        }
107  
108 <    clauseChainSpec  ::= {:} * | identifier | integer
108 >        std::vector<std::vector<Token> > getAatokenCompiled() {
109 >            return aatokenCompiled;
110 >        }
111  
112 <    clauseAtomSpec   ::= . * | . identifier {*} // note that this * is *not* a wildcard
112 >        std::string getErrorMessage() {
113 >            std::string strError = errorMessage;
114 >            strError += " : " + errorLine + "\n";
115  
116 <    clauseModelSpec  ::= {:|/} * | integer
117 <
118 < * </pre>
106 < */
107 < class SelectionCompiler{
108 <    public:
109 <        bool compile();
116 >            if (!filename.empty()) {
117 >                strError += filename;
118 >            }
119  
120 <        std::vector<Token> getCompiledTokens();
120 >            strError += " line#" + lineCurrent;
121 >            return strError;
122 >        }
123 >
124 >        
125      private:
126  
127 +        bool internalcompile();
128 +
129 +
130 +        bool lookingAtLeadingWhitespace();
131 +        bool lookingAtComment();
132 +        bool lookingAtEndOfLine();
133 +        bool lookingAtEndOfStatement();
134 +        bool lookingAtString();
135 +
136 +
137 +        bool compileCommand(const std::vector<vector>&);
138 +        
139          bool clauseOr();
140          bool clauseAnd();
141          bool clauseNot();
142          bool clausePrimitive();
143          bool clauseWithin();
144          bool clauseComparator();
145 +        bool clauseChemObject();
146 +        bool clauseMolecule();
147 +        bool clauseMolName();
148 +        bool clauseMolIndex();
149 +        bool clauseName();
150 +        bool clauseIndex();
151 +        bool clauseStuntDoubleName();
152 +        bool clauseStuntDoubleIndex();
153 +
154 +        bool compileError(const std::string& errorMessage) {
155 +            std::cerr << "SelectionCompiler Error: " << errorMessage <<  << std::endl;
156 +            error = true;
157 +            this.errorMessage = errorMessage;
158 +            return false;
159 +        }
160          
161 <        internalCompile();
161 >        bool commandExpected() {
162 >            return compileError("command expected");
163 >        }
164  
165 <        std::vector<Token> compiledTokens_;
165 >        bool invalidExpressionToken(const std::string& ident) {
166 >            return compileError("invalid expression token:" + ident);
167 >        }
168 >
169 >        bool unrecognizedToken() {
170 >            return compileError("unrecognized token");
171 >        }
172 >
173 >        bool badArgumentCount() {
174 >            return compileError("bad argument count");
175 >        }
176 >
177 >        bool endOfExpressionExpected() {
178 >            return compileError("end of expression expected");
179 >        }
180 >
181 >        bool leftParenthesisExpected() {
182 >            return compileError("left parenthesis expected");
183 >        }
184 >
185 >        bool rightParenthesisExpected() {
186 >            return compileError("right parenthesis expected");
187 >        }
188 >
189 >        bool commaExpected() {
190 >            return compileError("comma expected");
191 >        }
192 >
193 >        bool unrecognizedExpressionToken() {
194 >            return compileError("unrecognized expression token:" + valuePeek());
195 >        }
196 >
197 >        bool comparisonOperatorExpected() {
198 >            return compileError("comparison operator expected");
199 >        }
200 >
201 >        bool integerExpected() {
202 >            return compileError("integer expected");
203 >        }        
204 >        
205 >        
206 >        std::string filename;
207 >        std::string script;
208 >
209 >        std::vector<int> lineNumbers;
210 >        std::vector<int> lineIndices;
211 >        std::vector<std::vector<Token> >aatokenCompiled;
212 >
213 >        bool error;
214 >        std::string errorMessage;
215 >        std::string errorLine;
216 >
217 >        int cchScript;
218 >        short lineCurrent;
219 >
220 >        int ichToken;
221 >        int cchToken;
222 >        std::vector<Token> atokenCommand;
223 >
224 >        int ichCurrentCommand;
225 >
226 >        std::vector<Token> ltokenPostfix;
227 >        std::vector<Token> atokenInfix;
228 >        int itokenInfix;
229 >
230 >        //std::vector<Token> compiledTokens_;
231   };
232  
233   }
234   #endif
235 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines