ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/mdParser/MDTreeParser.g
Revision: 1390
Committed: Wed Nov 25 20:02:06 2009 UTC (15 years, 5 months ago) by gezelter
Original Path: trunk/src/mdParser/MDTreeParser.g
File size: 10803 byte(s)
Log Message:
Almost all of the changes necessary to create OpenMD out of our old
project (OOPSE-4)

File Contents

# User Rev Content
1 tim 770 header
2     {
3     #include <stack>
4     #include "io/Globals.hpp"
5     #include "utils/StringUtils.hpp"
6     using namespace std;
7 gezelter 1390 using namespace OpenMD;
8 tim 770 }
9     options
10     {
11     language = "Cpp";
12     }
13    
14     class MDTreeParser extends TreeParser;
15    
16     options
17     {
18 gezelter 1277 k = 1;
19 tim 770 importVocab = MD;
20     }
21     {
22     public:
23     Globals* walkTree(ANTLR_USE_NAMESPACE(antlr)RefAST tree)
24     {
25     currConf = new Globals;
26     blockStack.push(currConf);
27     mdfile(tree);
28     return currConf;
29     }
30     private:
31     Globals* currConf;
32     stack<DataHolder*> blockStack;
33     }
34     mdfile : (statement)* {blockStack.top()->validate(); blockStack.pop();}
35     ;
36    
37     statement : assignment
38     | componentblock
39     | moleculeblock
40     | zconstraintblock
41 cli2 1360 | restraintblock
42 tim 770 ;
43    
44    
45     assignment : #(ASSIGNEQUAL id:ID constant[#id]) //{blockStack.top()->assign(#ID->getText(),);}
46     ;
47    
48 tim 814 constant [ANTLR_USE_NAMESPACE(antlr)RefAST id]
49     {
50     int ival;
51 tim 963 RealType dval;
52 tim 814 }
53     : ival=intConst {blockStack.top()->assign(id->getText(), ival);}
54     | dval=floatConst {blockStack.top()->assign(id->getText(), dval);}
55 tim 770 | str1:ID {blockStack.top()->assign(id->getText(), str1->getText());}
56     | str2:StringLiteral { std::string s = str2->getText();
57     s = s.substr(1, s.length()-2);
58     blockStack.top()->assign(id->getText(),s);
59     }
60     ;
61    
62    
63     componentblock : #(COMPONENT {Component* currComponet = new Component(); blockStack.push(currComponet);}
64     (assignment)*
65     ENDBLOCK ) {blockStack.top()->validate();blockStack.pop(); currConf->addComponent(currComponet);}
66     ;
67    
68     zconstraintblock : #(ZCONSTRAINT {ZConsStamp* currZConsStamp = new ZConsStamp(); blockStack.push(currZConsStamp);}
69     (assignment)*
70     ENDBLOCK ) {blockStack.top()->validate();blockStack.pop(); currConf->addZConsStamp(currZConsStamp);}
71     ;
72 cli2 1360
73     restraintblock : #(RESTRAINT {RestraintStamp* currRestraintStamp = new RestraintStamp(); blockStack.push(currRestraintStamp);}
74     (assignment)*
75     ENDBLOCK ) {blockStack.top()->validate();blockStack.pop(); currConf->addRestraintStamp(currRestraintStamp);}
76     ;
77 tim 770
78     moleculeblock : #(MOLECULE {MoleculeStamp* currMoleculeStamp = new MoleculeStamp(); blockStack.push(currMoleculeStamp);}
79     (moleculestatement)*
80     ENDBLOCK ) {blockStack.top()->validate(); blockStack.pop(); currConf->addMoleculeStamp(currMoleculeStamp);}
81     ;
82    
83     moleculestatement : assignment
84     | atomblock
85     | bondblock
86     | bendblock
87     | torsionblock
88 cli2 1275 | inversionblock
89 tim 770 | rigidbodyblock
90     | cutoffgroupblock
91     | fragmentblock
92     ;
93    
94     atomblock
95     {
96     int index;
97     }
98     : #(ATOM index=intConst {AtomStamp* currAtomStamp = new AtomStamp(index); blockStack.push(currAtomStamp);}
99     (atomstatement)*
100     ENDBLOCK ) {
101     blockStack.top()->validate();
102     blockStack.pop();
103     MoleculeStamp* currMoleculeStamp = static_cast<MoleculeStamp*>(blockStack.top());
104     currMoleculeStamp->addAtomStamp(currAtomStamp);
105     }
106     ;
107    
108     atomstatement
109     {
110 tim 963 vector<RealType> dvec;
111 tim 770 AtomStamp* currAtomStamp = static_cast<AtomStamp*>(blockStack.top());
112    
113     }
114     : assignment
115 tim 814 | #(POSITION dvec=doubleNumberTuple) {currAtomStamp->setPosition(dvec);}
116     | #(ORIENTATION dvec=doubleNumberTuple) {currAtomStamp->setOrientation(dvec);}
117 tim 770 ;
118    
119    
120     bondblock : #(BOND {BondStamp* currBondStamp = new BondStamp(); blockStack.push(currBondStamp);}
121     (bondstatement)*
122     ENDBLOCK ) {
123     blockStack.pop();
124     MoleculeStamp* currMoleculeStamp = static_cast<MoleculeStamp*>(blockStack.top());
125     currMoleculeStamp->addBondStamp(currBondStamp);
126     }
127     ;
128    
129     bondstatement
130     {
131     vector<int> ivec;
132     BondStamp* currBondStamp = static_cast<BondStamp*>(blockStack.top());
133     }
134     : assignment
135     | #(MEMBERS ivec=inttuple) {currBondStamp->setMembers(ivec);}
136     ;
137    
138     bendblock : #(BEND {BendStamp* currBendStamp = new BendStamp(); blockStack.push(currBendStamp);}
139     (bendstatement)*
140     ENDBLOCK) {
141     blockStack.top()->validate();
142     blockStack.pop();
143     MoleculeStamp* currMoleculeStamp = static_cast<MoleculeStamp*>(blockStack.top());
144     currMoleculeStamp->addBendStamp(currBendStamp);
145     }
146     ;
147    
148     bendstatement
149     {
150     vector<int> ivec;
151     BendStamp* currBendStamp = static_cast<BendStamp*>(blockStack.top());
152     }
153     : assignment
154     | #(MEMBERS ivec=inttuple) {currBendStamp->setMembers(ivec);}
155     ;
156    
157     torsionblock : #(TORSION {TorsionStamp* currTorsionStamp = new TorsionStamp(); blockStack.push(currTorsionStamp);}
158     (torsionstatement)*
159     ENDBLOCK ) {
160     blockStack.top()->validate();
161     blockStack.pop();
162     MoleculeStamp* currMoleculeStamp = static_cast<MoleculeStamp*>(blockStack.top());
163     currMoleculeStamp->addTorsionStamp(currTorsionStamp);
164     }
165     ;
166    
167     torsionstatement
168     {
169     vector<int> ivec;
170     TorsionStamp* currTorsionStamp = static_cast<TorsionStamp*>(blockStack.top());
171     }
172     : assignment
173     | #(MEMBERS ivec=inttuple) {currTorsionStamp->setMembers(ivec);}
174     ;
175    
176 cli2 1275 inversionblock : #(INVERSION {InversionStamp* currInversionStamp = new InversionStamp(); blockStack.push(currInversionStamp);}
177     (inversionstatement)*
178     ENDBLOCK ) {
179     blockStack.top()->validate();
180     blockStack.pop();
181     MoleculeStamp* currMoleculeStamp = static_cast<MoleculeStamp*>(blockStack.top());
182     currMoleculeStamp->addInversionStamp(currInversionStamp);
183     }
184     ;
185    
186     inversionstatement
187     {
188     int icent;
189     InversionStamp* currInversionStamp = static_cast<InversionStamp*>(blockStack.top());
190     }
191     : assignment
192     | #(CENTER icent=intConst) {currInversionStamp->setCenter(icent);}
193     ;
194    
195 tim 770 rigidbodyblock
196     {
197     int index;
198     }
199     : #(RIGIDBODY index=intConst {RigidBodyStamp* currRigidBodyStamp = new RigidBodyStamp(index); blockStack.push(currRigidBodyStamp);}
200     (rigidbodystatement)*
201     ENDBLOCK ) {
202     blockStack.top()->validate();
203     blockStack.pop();
204     MoleculeStamp* currMoleculeStamp = static_cast<MoleculeStamp*>(blockStack.top());
205     currMoleculeStamp->addRigidBodyStamp(currRigidBodyStamp);
206     }
207     ;
208    
209     rigidbodystatement
210     {
211     vector<int> ivec;
212     RigidBodyStamp* currRigidBodyStamp = static_cast<RigidBodyStamp*>(blockStack.top());
213     }
214     : assignment
215     | #(MEMBERS ivec=inttuple) {currRigidBodyStamp->setMembers(ivec);}
216     ;
217    
218     cutoffgroupblock : #(CUTOFFGROUP {CutoffGroupStamp* currCutoffGroupStamp = new CutoffGroupStamp(); blockStack.push(currCutoffGroupStamp);}
219     (cutoffgroupstatement)*
220     ENDBLOCK ) {
221     blockStack.top()->validate();
222     blockStack.pop();
223     MoleculeStamp* currMoleculeStamp = static_cast<MoleculeStamp*>(blockStack.top());
224     currMoleculeStamp->addCutoffGroupStamp(currCutoffGroupStamp);
225     }
226     ;
227    
228     cutoffgroupstatement
229     {
230     vector<int> ivec;
231     CutoffGroupStamp* currCutoffGroupStamp = static_cast<CutoffGroupStamp*>(blockStack.top());
232     }
233     : assignment
234     | #(MEMBERS ivec=inttuple) {currCutoffGroupStamp->setMembers(ivec);}
235     ;
236    
237     fragmentblock {int ival;}
238     : #(FRAGMENT ival=intConst {FragmentStamp* currFragmentStamp = new FragmentStamp(ival); blockStack.push(currFragmentStamp);}
239     (fragmentstatement)*
240     ENDBLOCK) {
241     blockStack.top()->validate();
242     blockStack.pop();
243     MoleculeStamp* currMoleculeStamp = static_cast<MoleculeStamp*>(blockStack.top());
244     currMoleculeStamp->addFragmentStamp(currFragmentStamp);
245     }
246     ;
247    
248     fragmentstatement : assignment
249     ;
250    
251    
252    
253 tim 963 doubleNumberTuple returns [vector<RealType> dvec]
254 tim 770 {
255 tim 963 RealType dval;
256 tim 770 }
257 tim 814 : (dval=doubleNumber {dvec.push_back(dval);})+
258 tim 770 ;
259    
260     inttuple returns [vector<int> ivec]
261     {
262     int ival;
263     }
264     : (ival=intConst {ivec.push_back(ival);})+
265     ;
266    
267     protected
268     intConst returns [int ival]
269 tim 814 : i1:NUM_INT {ival = lexi_cast<int>(i1->getText());}
270     | i2:NUM_LONG {ival = lexi_cast<int>(i2->getText());}
271 tim 770 ;
272    
273     protected
274 tim 963 doubleNumber returns [RealType dval]
275 tim 810 :
276 tim 963 ic:intConst {dval = lexi_cast<RealType>(ic->getText());}
277     | fc:floatConst {dval = lexi_cast<RealType>(fc->getText());}
278 tim 810
279 tim 770 ;
280    
281     protected
282 tim 963 floatConst returns [RealType dval]
283     : d1:NUM_FLOAT {dval = lexi_cast<RealType>(d1->getText());}
284     | d2:NUM_DOUBLE {dval = lexi_cast<RealType>(d2->getText());}
285 tim 770 ;
286 tim 810

Properties

Name Value
svn:executable *