ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/mdParser/MDTreeParser.g
Revision: 1275
Committed: Fri Jul 4 20:54:29 2008 UTC (16 years, 10 months ago) by cli2
Original Path: trunk/src/mdParser/MDTreeParser.g
File size: 10447 byte(s)
Log Message:
Changes required for Inversions and Base Atom types.  This will
break OOPSE badly for a few days or so...

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

Properties

Name Value
svn:executable *