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 770 by tim, Fri Dec 2 15:38:03 2005 UTC vs.
Revision 1979 by gezelter, Sat Apr 5 20:56:01 2014 UTC

# Line 28 | Line 28 | tokens
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    ENDBLOCK;
51   }
52  
44 {
45    // Suppport C++-style single-line comments?
46 }
53  
54   mdfile  : (statement)*
55          ;
56  
57   statement : assignment
58 <          | componentblock
59 <          | moleculeblock
60 <          | zconstraintblock
61 <          ;
62 <            
58 >    | componentblock
59 >    | moleculeblock
60 >    | zconstraintblock
61 >    | restraintblock
62 >    | flucqblock
63 >    | rnemdblock
64 >    | minimizerblock
65 >    ;
66 >
67   assignment  : ID ASSIGNEQUAL^ constant SEMICOLON!
68              ;
69              
70 < constant    : signedNumber
70 > constant    : intConst
71 >                        | floatConst
72 >            | vectorConst
73              | ID
74              | StringLiteral
75              ;
# Line 67 | Line 79 | zconstraintblock  : ZCONSTRAINT^ LCURLY! (assignment)*
79      
80   zconstraintblock  : ZCONSTRAINT^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
81                    ;
82 +
83 + restraintblock  : RESTRAINT^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
84 +                  ;
85 +
86 + flucqblock  : FLUCQ^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
87 +    ;
88 +
89 + rnemdblock  : RNEMD^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
90 +    ;
91 +
92 + minimizerblock  : MINIMIZER^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
93 +    ;
94    
95   moleculeblock : MOLECULE^ LCURLY! (moleculestatement)*  RCURLY {#RCURLY->setType(ENDBLOCK);}
96                ;
# Line 76 | Line 100 | moleculestatement : assignment
100                    | bondblock
101                    | bendblock
102                    | torsionblock
103 +                  | inversionblock
104                    | rigidbodyblock
105                    | cutoffgroupblock
106                    | fragmentblock
107 +                  | constraintblock
108                    ;
109  
110   atomblock : ATOM^ LBRACKET! intConst RBRACKET! LCURLY! (atomstatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
111            ;
112  
113   atomstatement : assignment
114 <              | POSITION^ LPAREN! signedNumberTuple RPAREN! SEMICOLON!
115 <              | ORIENTATION^  LPAREN! signedNumberTuple RPAREN! SEMICOLON!
114 >              | POSITION^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
115 >              | ORIENTATION^  LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
116                ;
117  
118                        
# Line 111 | Line 137 | torsionstatement  : assignment
137                | MEMBERS^ LPAREN! inttuple RPAREN! SEMICOLON!
138                ;
139  
140 + inversionblock  : INVERSION^ (LBRACKET! intConst! RBRACKET!)?  LCURLY!(inversionstatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
141 +          ;
142 +
143 + inversionstatement  : assignment
144 +              | CENTER^ LPAREN! intConst RPAREN! SEMICOLON!
145 +              | SATELLITES^ LPAREN! inttuple RPAREN! SEMICOLON!
146 +              ;
147 +
148   rigidbodyblock  : RIGIDBODY^  LBRACKET! intConst RBRACKET! LCURLY!(rigidbodystatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
149                  ;
150  
# Line 131 | Line 165 | fragmentstatement : assignment
165   fragmentstatement : assignment
166                ;
167  
168 + constraintblock : CONSTRAINT^ (LBRACKET! intConst! RBRACKET!)?  LCURLY!(constraintstatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
169 +          ;
170  
171 + constraintstatement : assignment
172 +              | MEMBERS^ LPAREN! inttuple RPAREN! SEMICOLON!
173 +              ;
174 +
175                
176 < signedNumberTuple   : signedNumber (COMMA! signedNumber)*
176 > doubleNumberTuple   : doubleNumber (COMMA! doubleNumber)*
177                ;
178                            
179   inttuple      : intConst (COMMA! intConst)*
# Line 141 | Line 181 | intConst
181                
182   protected
183   intConst
184 <        :  OCTALINT | DECIMALINT | HEXADECIMALINT
184 >        :  NUM_INT | NUM_LONG
185          ;
186  
187   protected
188 < signedNumber  : (PLUS! | MINUS^)?
188 > doubleNumber  :  
189                  (intConst | floatConst)
190                ;
191                
192   protected
193   floatConst
194          :
195 <          FLOATONE | FLOATTWO
195 >          NUM_FLOAT | NUM_DOUBLE
196          ;
197  
198 <
198 > protected
199 > vectorConst
200 >    :
201 >        LPAREN^ doubleNumber COMMA doubleNumber COMMA doubleNumber RPAREN
202 >    ;
203  
204   class MDLexer extends Lexer;
205  
# Line 209 | Line 253 | RCURLY          : '}' ;
253   LCURLY          : '{' ;
254   RCURLY          : '}' ;
255  
212 PLUS            : '+' ;
213 MINUS           : '-' ;
214
215 /*
216 EQUAL           : "==" ;
217 NOTEQUAL        : "!=" ;
218 LESSTHANOREQUALTO     : "<=" ;
219 LESSTHAN              : "<" ;
220 GREATERTHANOREQUALTO  : ">=" ;
221 GREATERTHAN           : ">" ;
222
223 DIVIDE          : '/' ;
224 DIVIDEEQUAL     : "/=" ;
225 PLUS            : '+' ;
226 PLUSEQUAL       : "+=" ;
227 PLUSPLUS        : "++" ;
228 MINUS           : '-' ;
229 MINUSEQUAL      : "-=" ;
230 MINUSMINUS      : "--" ;
231 STAR            : '*' ;
232 TIMESEQUAL      : "*=" ;
233 MOD             : '%' ;
234 MODEQUAL        : "%=" ;
235 SHIFTRIGHT      : ">>" ;
236 SHIFTRIGHTEQUAL : ">>=" ;
237 SHIFTLEFT       : "<<" ;
238 SHIFTLEFTEQUAL  : "<<=" ;
239
240 AND            : "&&" ;
241 NOT            : '!' ;
242 OR             : "||" ;
243
244 AMPERSAND       : '&' ;
245 BITWISEANDEQUAL : "&=" ;
246 TILDE           : '~' ;
247 BITWISEOR       : '|' ;
248 BITWISEOREQUAL  : "|=" ;
249 BITWISEXOR      : '^' ;
250 BITWISEXOREQUAL : "^=" ;
251 */
252
253
256   Whitespace  
257    :
258      ( // whitespace ignored
# Line 301 | Line 303 | LineDirective
303    }
304      ("line")?  // this would be for if the directive started "#line"
305      (Space)+
306 <    n:Decimal { setLine(oopse::lexi_cast<int>(n->getText()) - 1); }
306 >    n:Decimal { setLine(OpenMD::lexi_cast<int>(n->getText()) - 1); }
307      (Space)+
308      (sl:StringLiteral) {std::string filename = sl->getText().substr(1,sl->getText().length()-2); observer->notify(filename);}
309      ((Space)+ Decimal)* // To support cpp flags (GNU)
# Line 400 | Line 402 | Escape  
402      )
403    ;
404  
403 // Numeric Constants:
405  
406   protected
407 < Digit
407 > Vocabulary
408    :
409 <    '0'..'9'
409 >    '\3'..'\377'
410    ;
411  
412 < protected
413 < Decimal
412 >
413 > ID
414 >  options {testLiterals = true;}
415    :
416 <    ('0'..'9')+
416 >    ('a'..'z'|'A'..'Z'|'_')
417 >    ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
418    ;
419  
420 +
421   protected
422 < LongSuffix
423 <  : 'l'
424 <  | 'L'
422 > Digit
423 >  :
424 >    '0'..'9'
425    ;
426  
427   protected
428 < UnsignedSuffix
429 <  : 'u'
430 <  | 'U'
428 > Decimal
429 >  :
430 >    ('0'..'9')+
431    ;
432  
433 + // hexadecimal digit (again, note it's protected!)
434   protected
435 < FloatSuffix
436 <  : 'f'
437 <  | 'F'
433 <  ;
435 > HEX_DIGIT
436 >        :       ('0'..'9'|'A'..'F'|'a'..'f')
437 >        ;
438  
435 protected
436 Exponent
437  :
438    ('e'|'E'|'d'|'D') ('+'|'-')? (Digit)+
439  ;
439  
440 < protected
441 < Vocabulary
442 <  :
443 <    '\3'..'\377'
444 <  ;
440 > // a numeric literal
441 > NUM_INT
442 >        {
443 >                bool isDecimal = false;
444 >                ANTLR_USE_NAMESPACE(antlr)RefToken t = ANTLR_USE_NAMESPACE(antlr)nullToken;
445 >        }
446 >    : ('+' | '-')?
447 >    (
448 >      '.' {_ttype = DOT;}
449 >            (   ('0'..'9')+ (EXPONENT)? (f1:FLOAT_SUFFIX {t=f1;})?
450 >            {
451 >                                        if ( t &&
452 >                                                  (t->getText().find('f') != ANTLR_USE_NAMESPACE(std)string::npos ||
453 >                                                        t->getText().find('F') != ANTLR_USE_NAMESPACE(std)string::npos ) ) {
454 >                                                _ttype = NUM_FLOAT;
455 >                                        }
456 >                                        else {
457 >                                                _ttype = NUM_DOUBLE; // assume double
458 >                                        }
459 >                                }
460 >            )?
461  
462 < Number
463 <  :
464 <    ( (Digit)+ ('.' | 'e' | 'E' | 'd' | 'D' ) )=>
465 <    (Digit)+
466 <    ( '.' (Digit)* (Exponent)? {_ttype = FLOATONE;} //Zuo 3/12/01
467 <    | Exponent                 {_ttype = FLOATTWO;} //Zuo 3/12/01
468 <    )                          //{_ttype = DoubleDoubleConst;}
469 <    (FloatSuffix               //{_ttype = FloatDoubleConst;}
470 <    |LongSuffix                //{_ttype = LongDoubleConst;}
471 <    )?
472 <  |
473 <    '.'                        {_ttype = DOT;}
474 <    ( (Digit)+ (Exponent)?   {_ttype = FLOATONE;} //Zuo 3/12/01
475 <                                   //{_ttype = DoubleDoubleConst;}
476 <      (FloatSuffix           //{_ttype = FloatDoubleConst;}
477 <      |LongSuffix            //{_ttype = LongDoubleConst;}
478 <      )?
479 <    )?
480 <  |
481 <    '0' ('0'..'7')*            //{_ttype = IntOctalConst;}
467 <    (LongSuffix                //{_ttype = LongOctalConst;}
468 <    |UnsignedSuffix            //{_ttype = UnsignedOctalConst;}
469 <    )*                         {_ttype = OCTALINT;}
470 <  |
471 <    '1'..'9' (Digit)*          //{_ttype = IntIntConst;}
472 <    (LongSuffix                //{_ttype = LongIntConst;}
473 <    |UnsignedSuffix            //{_ttype = UnsignedIntConst;}
474 <    )*                         {_ttype = DECIMALINT;}  
475 <  |
476 <    '0' ('x' | 'X') ('a'..'f' | 'A'..'F' | Digit)+
477 <                                   //{_ttype = IntHexConst;}
478 <    (LongSuffix                //{_ttype = LongHexConst;}
479 <    |UnsignedSuffix            //{_ttype = UnsignedHexConst;}
480 <    )*                         {_ttype = HEXADECIMALINT;}  
481 <  ;
462 >        |       (       '0' {isDecimal = true;} // special case for just '0'
463 >                        (       ('x'|'X')
464 >                                (                                                                                       // hex
465 >                                        // the 'e'|'E' and float suffix stuff look
466 >                                        // like hex digits, hence the (...)+ doesn't
467 >                                        // know when to stop: ambig.  ANTLR resolves
468 >                                        // it correctly by matching immediately.  It
469 >                                        // is therefor ok to hush warning.
470 >                                        options {
471 >                                                warnWhenFollowAmbig=false;
472 >                                        }
473 >                                :       HEX_DIGIT
474 >                                )+
475 >                        |       //float or double with leading zero
476 >                                (('0'..'9')+ ('.'|EXPONENT|FLOAT_SUFFIX)) => ('0'..'9')+
477 >                        |       ('0'..'7')+                                                                     // octal
478 >                        )?
479 >                |       ('1'..'9') ('0'..'9')*  {isDecimal=true;}               // non-zero decimal
480 >                )
481 >                (       ('l'|'L') { _ttype = NUM_LONG; }
482  
483 < ID
484 <  options {testLiterals = true;}
485 <  :
486 <    ('a'..'z'|'A'..'Z'|'_')
487 <    ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
488 <  ;
483 >                // only check to see if it's a float if looks like decimal so far
484 >                |       {isDecimal}?
485 >            (   '.' ('0'..'9')* (EXPONENT)? (f2:FLOAT_SUFFIX {t=f2;})?
486 >            |   EXPONENT (f3:FLOAT_SUFFIX {t=f3;})?
487 >            |   f4:FLOAT_SUFFIX {t=f4;}
488 >            )
489 >            {
490 >                                        if ( t &&
491 >                                                  (t->getText().find('f') != ANTLR_USE_NAMESPACE(std)string::npos ||
492 >                                                        t->getText().find('F') != ANTLR_USE_NAMESPACE(std)string::npos ) ) {
493 >                                                _ttype = NUM_FLOAT;
494 >                                        }
495 >                                        else {
496 >                                                _ttype = NUM_DOUBLE; // assume double
497 >                                        }
498 >                                }
499 >        )?
500 >  )
501 >        ;
502 >
503 > // a couple protected methods to assist in matching floating point numbers
504 > protected
505 > EXPONENT
506 >        :       ('e'|'E'|'d'|'D') ('+'|'-')? ('0'..'9')+
507 >        ;
508 >
509 > protected
510 > FLOAT_SUFFIX
511 >        :       'f'|'F'|'d'|'D'
512 >        ;

Comparing trunk/src/mdParser/MDParser.g (property svn:keywords):
Revision 770 by tim, Fri Dec 2 15:38:03 2005 UTC vs.
Revision 1979 by gezelter, Sat Apr 5 20:56:01 2014 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines