ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/mdParser/MDParser.g
(Generate patch)

Comparing trunk/src/mdParser/MDParser.g (file contents):
Revision 810 by tim, Wed Dec 14 18:02:28 2005 UTC vs.
Revision 2046 by gezelter, Tue Dec 2 22:11:04 2014 UTC

# Line 25 | Line 25 | tokens
25  
26   tokens
27   {
28 <  COMPONENT   = "component";
29 <  MOLECULE    = "molecule";
30 <  ZCONSTRAINT = "zconstraint";
31 <  ATOM        = "atom";
32 <  BOND        = "bond";
33 <  BEND        = "bend";
34 <  TORSION     = "torsion";
35 <  RIGIDBODY   = "rigidBody";
36 <  CUTOFFGROUP = "cutoffGroup";
37 <  FRAGMENT    = "fragment";
38 <  MEMBERS     = "members";
39 <  POSITION    = "position";
40 <  ORIENTATION = "orientation";
28 >  COMPONENT         = "component";
29 >  MOLECULE          = "molecule";
30 >  ZCONSTRAINT       = "zconstraint";
31 >  RESTRAINT         = "restraint";
32 >  ATOM              = "atom";
33 >  BOND              = "bond";
34 >  BEND              = "bend";
35 >  TORSION           = "torsion";
36 >  INVERSION         = "inversion";
37 >  RIGIDBODY         = "rigidBody";
38 >  CUTOFFGROUP       = "cutoffGroup";
39 >  CONSTRAINT        = "constraint";
40 >  DISTANCE          = "distance";
41 >  FRAGMENT          = "fragment";
42 >  MEMBERS           = "members";
43 >  CENTER            = "center";
44 >  SATELLITES        = "satellites";
45 >  POSITION          = "position";
46 >  ORIENTATION       = "orientation";
47 >  FLUCQ             = "flucQ";
48 >  RNEMD             = "RNEMD";
49 >  MINIMIZER         = "minimizer";
50 >  FIXED             = "Fixed";
51 >  HARMONIC          = "Harmonic";
52 >  CUBIC             = "Cubic";
53 >  QUARTIC           = "Quartic";
54 >  POLYNOMIAL        = "Polynomial";
55 >  MORSE             = "Morse";
56 >  GHOSTBEND         = "GhostBend";
57 >  UREYBRADLEY       = "UreyBradley";
58 >  COSINE            = "Cosine";
59 >  GHOSTTORSION      = "GhostTorsion";
60 >  CHARMM            = "Charmm";
61 >  OPLS              = "Opls";
62 >  TRAPPE            = "Trappe";
63 >  AMBERIMPROPER     = "AmberImproper";
64 >  IMPROPERCOSINE    = "ImproperCosine";
65 >  CENTRALATOMHEIGHT = "CentralAtomHeight";
66 >  DREIDING          = "Dreiding";
67 >  CHARGE            = "charge";
68    ENDBLOCK;
69   }
70  
# Line 46 | Line 73 | statement : assignment
73          ;
74  
75   statement : assignment
76 <          | componentblock
77 <          | moleculeblock
78 <          | zconstraintblock
79 <          ;
80 <            
76 >    | componentblock
77 >    | moleculeblock
78 >    | zconstraintblock
79 >    | restraintblock
80 >    | flucqblock
81 >    | rnemdblock
82 >    | minimizerblock
83 >    ;
84 >
85   assignment  : ID ASSIGNEQUAL^ constant SEMICOLON!
86              ;
87              
88 < constant    : signedNumber
88 > constant    : intConst
89 >                        | floatConst
90 >            | vectorConst
91              | ID
92              | StringLiteral
93              ;
# Line 64 | Line 97 | zconstraintblock  : ZCONSTRAINT^ LCURLY! (assignment)*
97      
98   zconstraintblock  : ZCONSTRAINT^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
99                    ;
100 +
101 + restraintblock  : RESTRAINT^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
102 +                  ;
103 +
104 + flucqblock  : FLUCQ^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
105 +    ;
106 +
107 + rnemdblock  : RNEMD^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
108 +    ;
109 +
110 + minimizerblock  : MINIMIZER^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
111 +    ;
112    
113   moleculeblock : MOLECULE^ LCURLY! (moleculestatement)*  RCURLY {#RCURLY->setType(ENDBLOCK);}
114                ;
# Line 73 | Line 118 | moleculestatement : assignment
118                    | bondblock
119                    | bendblock
120                    | torsionblock
121 +                  | inversionblock
122                    | rigidbodyblock
123                    | cutoffgroupblock
124                    | fragmentblock
125 +                  | constraintblock
126                    ;
127  
128   atomblock : ATOM^ LBRACKET! intConst RBRACKET! LCURLY! (atomstatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
129            ;
130  
131   atomstatement : assignment
132 <              | POSITION^ LPAREN! signedNumberTuple RPAREN! SEMICOLON!
133 <              | ORIENTATION^  LPAREN! signedNumberTuple RPAREN! SEMICOLON!
134 <              ;
132 >    | POSITION^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
133 >    | ORIENTATION^  LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
134 >    | CHARGE^ LPAREN! floatConst RPAREN! SEMICOLON!
135 >    ;
136  
137                        
138   bondblock : BOND^ (LBRACKET! intConst! RBRACKET!)?  LCURLY!(bondstatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
139            ;
140  
141   bondstatement : assignment
142 <              | MEMBERS^ LPAREN! inttuple RPAREN! SEMICOLON!
143 <              ;
142 >    | MEMBERS^ LPAREN! inttuple RPAREN! SEMICOLON!
143 >    | FIXED^ LPAREN! floatConst RPAREN! SEMICOLON!
144 >    | HARMONIC^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
145 >    | CUBIC^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
146 >    | QUARTIC^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
147 >    | POLYNOMIAL^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
148 >    | MORSE^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!        
149 >    ;
150  
151   bendblock : BEND^ (LBRACKET! intConst! RBRACKET!)? LCURLY!  (bendstatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
152            ;
153  
154   bendstatement : assignment
155 <              | MEMBERS^ LPAREN! inttuple RPAREN! SEMICOLON!
156 <              ;
155 >    | MEMBERS^ LPAREN! inttuple RPAREN! SEMICOLON!
156 >    | HARMONIC^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
157 >    | GHOSTBEND^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
158 >    | UREYBRADLEY^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
159 >    | CUBIC^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
160 >    | QUARTIC^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
161 >    | POLYNOMIAL^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
162 >    | COSINE^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!            
163 >    ;
164  
165   torsionblock  : TORSION^ (LBRACKET! intConst! RBRACKET!)?  LCURLY!(torsionstatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
166            ;
167  
168   torsionstatement  : assignment
169 <              | MEMBERS^ LPAREN! inttuple RPAREN! SEMICOLON!
170 <              ;
169 >    | MEMBERS^ LPAREN! inttuple RPAREN! SEMICOLON!
170 >    | GHOSTTORSION^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
171 >    | CUBIC^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
172 >    | QUARTIC^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
173 >    | POLYNOMIAL^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
174 >    | CHARMM^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
175 >    | OPLS^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
176 >    | TRAPPE^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
177 >    | HARMONIC^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
178 >    ;
179  
180 + inversionblock  : INVERSION^ (LBRACKET! intConst! RBRACKET!)?  LCURLY!(inversionstatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
181 +    ;
182 +
183 + inversionstatement  : assignment
184 +    | CENTER^ LPAREN! intConst RPAREN! SEMICOLON!
185 +    | SATELLITES^ LPAREN! inttuple RPAREN! SEMICOLON!
186 +    | AMBERIMPROPER^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
187 +    | IMPROPERCOSINE^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
188 +    | HARMONIC^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
189 +    | CENTRALATOMHEIGHT^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
190 +    | DREIDING^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
191 +    ;
192 +
193   rigidbodyblock  : RIGIDBODY^  LBRACKET! intConst RBRACKET! LCURLY!(rigidbodystatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
194                  ;
195  
196   rigidbodystatement  : assignment
197 <              | MEMBERS^ LPAREN!  inttuple  RPAREN! SEMICOLON!
198 <              ;
197 >    | MEMBERS^ LPAREN!  inttuple  RPAREN! SEMICOLON!
198 >    ;
199  
200   cutoffgroupblock  : CUTOFFGROUP^ (LBRACKET! intConst! RBRACKET!)? LCURLY! (cutoffgroupstatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
201 <                  ;
201 >    ;
202  
203   cutoffgroupstatement  : assignment
204 <              | MEMBERS^ LPAREN! inttuple RPAREN! SEMICOLON!
205 <              ;
204 >    | MEMBERS^ LPAREN! inttuple RPAREN! SEMICOLON!
205 >    ;
206  
207   fragmentblock : FRAGMENT^ LBRACKET! intConst RBRACKET! LCURLY! (fragmentstatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
208 <              ;
208 >    ;
209  
210   fragmentstatement : assignment
211 <              ;
211 >    ;
212  
213 + constraintblock : CONSTRAINT^ (LBRACKET! intConst! RBRACKET!)?  LCURLY!(constraintstatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
214 +    ;
215  
216 <              
217 < signedNumberTuple   : signedNumber (COMMA! signedNumber)*
218 <              ;
219 <                          
216 > constraintstatement : assignment
217 >    | MEMBERS^ LPAREN! inttuple RPAREN! SEMICOLON!
218 >    ;
219 >    
220 >
221 > doubleNumberTuple   : doubleNumber (COMMA! doubleNumber)*
222 >    ;
223 >
224   inttuple      : intConst (COMMA! intConst)*
225 <              ;
226 <              
225 >    ;
226 >
227   protected
228   intConst
229 <        :  OCTALINT | DECIMALINT | HEXADECIMALINT
230 <        ;
229 >    :
230 >        NUM_INT | NUM_LONG
231 >    ;
232  
233   protected
234 < signedNumber  :  
235 <                (intConst | floatConst)
236 <              ;
234 > doubleNumber
235 >    :
236 >    (intConst | floatConst)
237 >    ;
238                
239   protected
240   floatConst
241 <        :
242 <          FLOATONE | FLOATTWO
243 <        ;
241 >   :
242 >   NUM_FLOAT | NUM_DOUBLE
243 >   ;
244  
245  
246 + /*
247 + protected
248 + vectorConst
249 +    :
250 +        LPAREN^ doubleNumber COMMA doubleNumber COMMA doubleNumber RPAREN
251 +    ;
252 + */
253  
254 + protected
255 + vectorConst
256 +    :
257 +        LPAREN^ doubleNumberTuple RPAREN
258 +    ;
259 +
260 +
261   class MDLexer extends Lexer;
262  
263   options
# Line 206 | Line 310 | RCURLY          : '}' ;
310   LCURLY          : '{' ;
311   RCURLY          : '}' ;
312  
209
210 /*
211 EQUAL           : "==" ;
212 NOTEQUAL        : "!=" ;
213 LESSTHANOREQUALTO     : "<=" ;
214 LESSTHAN              : "<" ;
215 GREATERTHANOREQUALTO  : ">=" ;
216 GREATERTHAN           : ">" ;
217
218 DIVIDE          : '/' ;
219 DIVIDEEQUAL     : "/=" ;
220 PLUS            : '+' ;
221 PLUSEQUAL       : "+=" ;
222 PLUSPLUS        : "++" ;
223 MINUS           : '-' ;
224 MINUSEQUAL      : "-=" ;
225 MINUSMINUS      : "--" ;
226 STAR            : '*' ;
227 TIMESEQUAL      : "*=" ;
228 MOD             : '%' ;
229 MODEQUAL        : "%=" ;
230 SHIFTRIGHT      : ">>" ;
231 SHIFTRIGHTEQUAL : ">>=" ;
232 SHIFTLEFT       : "<<" ;
233 SHIFTLEFTEQUAL  : "<<=" ;
234
235 AND            : "&&" ;
236 NOT            : '!' ;
237 OR             : "||" ;
238
239 AMPERSAND       : '&' ;
240 BITWISEANDEQUAL : "&=" ;
241 TILDE           : '~' ;
242 BITWISEOR       : '|' ;
243 BITWISEOREQUAL  : "|=" ;
244 BITWISEXOR      : '^' ;
245 BITWISEXOREQUAL : "^=" ;
246 */
247
248
313   Whitespace  
314    :
315      ( // whitespace ignored
# Line 296 | Line 360 | LineDirective
360    }
361      ("line")?  // this would be for if the directive started "#line"
362      (Space)+
363 <    n:Decimal { setLine(oopse::lexi_cast<int>(n->getText()) - 1); }
363 >    n:Decimal { setLine(OpenMD::lexi_cast<int>(n->getText()) - 1); }
364      (Space)+
365      (sl:StringLiteral) {std::string filename = sl->getText().substr(1,sl->getText().length()-2); observer->notify(filename);}
366      ((Space)+ Decimal)* // To support cpp flags (GNU)
# Line 395 | Line 459 | Escape  
459      )
460    ;
461  
398 // Numeric Constants:
462  
463   protected
464 + Vocabulary
465 +  :
466 +    '\3'..'\377'
467 +  ;
468 +
469 +
470 + ID
471 +  options {testLiterals = true;}
472 +  :
473 +    ('a'..'z'|'A'..'Z'|'_')
474 +    ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
475 +  ;
476 +
477 +
478 + protected
479   Digit
480    :
481      '0'..'9'
# Line 409 | Line 487 | Decimal
487      ('0'..'9')+
488    ;
489  
490 + // hexadecimal digit (again, note it's protected!)
491   protected
492 < LongSuffix
493 <  : 'l'
494 <  | 'L'
416 <  ;
492 > HEX_DIGIT
493 >        :       ('0'..'9'|'A'..'F'|'a'..'f')
494 >        ;
495  
418 protected
419 UnsignedSuffix
420  : 'u'
421  | 'U'
422  ;
496  
497 < protected
498 < FloatSuffix
499 <  : 'f'
500 <  | 'F'
501 <  ;
497 > // a numeric literal
498 > NUM_INT
499 >        {
500 >                bool isDecimal = false;
501 >                ANTLR_USE_NAMESPACE(antlr)RefToken t = ANTLR_USE_NAMESPACE(antlr)nullToken;
502 >        }
503 >    : ('+' | '-')?
504 >    (
505 >      '.' {_ttype = DOT;}
506 >            (   ('0'..'9')+ (EXPONENT)? (f1:FLOAT_SUFFIX {t=f1;})?
507 >            {
508 >                                        if ( t &&
509 >                                                  (t->getText().find('f') != ANTLR_USE_NAMESPACE(std)string::npos ||
510 >                                                        t->getText().find('F') != ANTLR_USE_NAMESPACE(std)string::npos ) ) {
511 >                                                _ttype = NUM_FLOAT;
512 >                                        }
513 >                                        else {
514 >                                                _ttype = NUM_DOUBLE; // assume double
515 >                                        }
516 >                                }
517 >            )?
518 >
519 >        |       (       '0' {isDecimal = true;} // special case for just '0'
520 >                        (       ('x'|'X')
521 >                                (                                                                                       // hex
522 >                                        // the 'e'|'E' and float suffix stuff look
523 >                                        // like hex digits, hence the (...)+ doesn't
524 >                                        // know when to stop: ambig.  ANTLR resolves
525 >                                        // it correctly by matching immediately.  It
526 >                                        // is therefor ok to hush warning.
527 >                                        options {
528 >                                                warnWhenFollowAmbig=false;
529 >                                        }
530 >                                :       HEX_DIGIT
531 >                                )+
532 >                        |       //float or double with leading zero
533 >                                (('0'..'9')+ ('.'|EXPONENT|FLOAT_SUFFIX)) => ('0'..'9')+
534 >                        |       ('0'..'7')+                                                                     // octal
535 >                        )?
536 >                |       ('1'..'9') ('0'..'9')*  {isDecimal=true;}               // non-zero decimal
537 >                )
538 >                (       ('l'|'L') { _ttype = NUM_LONG; }
539  
540 < protected
541 < Exponent
542 <  :
543 <    ('e'|'E'|'d'|'D') ('+'|'-')? (Digit)+
544 <  ;
540 >                // only check to see if it's a float if looks like decimal so far
541 >                |       {isDecimal}?
542 >            (   '.' ('0'..'9')* (EXPONENT)? (f2:FLOAT_SUFFIX {t=f2;})?
543 >            |   EXPONENT (f3:FLOAT_SUFFIX {t=f3;})?
544 >            |   f4:FLOAT_SUFFIX {t=f4;}
545 >            )
546 >            {
547 >                                        if ( t &&
548 >                                                  (t->getText().find('f') != ANTLR_USE_NAMESPACE(std)string::npos ||
549 >                                                        t->getText().find('F') != ANTLR_USE_NAMESPACE(std)string::npos ) ) {
550 >                                                _ttype = NUM_FLOAT;
551 >                                        }
552 >                                        else {
553 >                                                _ttype = NUM_DOUBLE; // assume double
554 >                                        }
555 >                                }
556 >        )?
557 >  )
558 >        ;
559  
560 + // a couple protected methods to assist in matching floating point numbers
561   protected
562 < Vocabulary
563 <  :
564 <    '\3'..'\377'
440 <  ;
562 > EXPONENT
563 >        :       ('e'|'E'|'d'|'D') ('+'|'-')? ('0'..'9')+
564 >        ;
565  
566 < Number
567 <  :
568 <  ('+'|'-')?
569 <  (
446 <    ( (Digit)+ ('.' | 'e' | 'E' | 'd' | 'D' ) )=>
447 <    (Digit)+
448 <    ( '.' (Digit)* (Exponent)? {_ttype = FLOATONE;} //Zuo 3/12/01
449 <    | Exponent                 {_ttype = FLOATTWO;} //Zuo 3/12/01
450 <    )                          //{_ttype = DoubleDoubleConst;}
451 <    (FloatSuffix               //{_ttype = FloatDoubleConst;}
452 <    |LongSuffix                //{_ttype = LongDoubleConst;}
453 <    )?
454 <  |
455 <    '.'                        {_ttype = DOT;}
456 <    ( (Digit)+ (Exponent)?   {_ttype = FLOATONE;} //Zuo 3/12/01
457 <                                   //{_ttype = DoubleDoubleConst;}
458 <      (FloatSuffix           //{_ttype = FloatDoubleConst;}
459 <      |LongSuffix            //{_ttype = LongDoubleConst;}
460 <      )?
461 <    )?
462 <  |
463 <    '0' ('0'..'7')*            //{_ttype = IntOctalConst;}
464 <    (LongSuffix                //{_ttype = LongOctalConst;}
465 <    |UnsignedSuffix            //{_ttype = UnsignedOctalConst;}
466 <    )*                         {_ttype = OCTALINT;}
467 <  |
468 <    '1'..'9' (Digit)*          //{_ttype = IntIntConst;}
469 <    (LongSuffix                //{_ttype = LongIntConst;}
470 <    |UnsignedSuffix            //{_ttype = UnsignedIntConst;}
471 <    )*                         {_ttype = DECIMALINT;}  
472 <  |
473 <    '0' ('x' | 'X') ('a'..'f' | 'A'..'F' | Digit)+
474 <                                   //{_ttype = IntHexConst;}
475 <    (LongSuffix                //{_ttype = LongHexConst;}
476 <    |UnsignedSuffix            //{_ttype = UnsignedHexConst;}
477 <    )*                         {_ttype = HEXADECIMALINT;}  
478 <  )
479 <  ;
480 <
481 < ID
482 <  options {testLiterals = true;}
483 <  :
484 <    ('a'..'z'|'A'..'Z'|'_')
485 <    ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
486 <  ;
566 > protected
567 > FLOAT_SUFFIX
568 >        :       'f'|'F'|'d'|'D'
569 >        ;

Comparing trunk/src/mdParser/MDParser.g (property svn:keywords):
Revision 810 by tim, Wed Dec 14 18:02:28 2005 UTC vs.
Revision 2046 by gezelter, Tue Dec 2 22:11:04 2014 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines