ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/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 1277 by gezelter, Mon Jul 14 12:35:58 2008 UTC

# Line 32 | Line 32 | tokens
32    BOND        = "bond";
33    BEND        = "bend";
34    TORSION     = "torsion";
35 +  INVERSION   = "inversion";
36    RIGIDBODY   = "rigidBody";
37    CUTOFFGROUP = "cutoffGroup";
38    FRAGMENT    = "fragment";
39    MEMBERS     = "members";
40 +  CENTER      = "center";
41    POSITION    = "position";
42    ORIENTATION = "orientation";
43    ENDBLOCK;
44   }
45  
44 {
45    // Suppport C++-style single-line comments?
46 }
46  
47   mdfile  : (statement)*
48          ;
# Line 57 | Line 56 | assignment  : ID ASSIGNEQUAL^ constant SEMICOLON!
56   assignment  : ID ASSIGNEQUAL^ constant SEMICOLON!
57              ;
58              
59 < constant    : signedNumber
59 > constant    : intConst
60 >                                                | floatConst
61              | ID
62              | StringLiteral
63              ;
# Line 76 | Line 76 | moleculestatement : assignment
76                    | bondblock
77                    | bendblock
78                    | torsionblock
79 +                  | inversionblock
80                    | rigidbodyblock
81                    | cutoffgroupblock
82                    | fragmentblock
# Line 85 | Line 86 | atomstatement : assignment
86            ;
87  
88   atomstatement : assignment
89 <              | POSITION^ LPAREN! signedNumberTuple RPAREN! SEMICOLON!
90 <              | ORIENTATION^  LPAREN! signedNumberTuple RPAREN! SEMICOLON!
89 >              | POSITION^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
90 >              | ORIENTATION^  LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
91                ;
92  
93                        
# Line 111 | Line 112 | torsionstatement  : assignment
112                | MEMBERS^ LPAREN! inttuple RPAREN! SEMICOLON!
113                ;
114  
115 + inversionblock  : INVERSION^ (LBRACKET! intConst! RBRACKET!)?  LCURLY!(inversionstatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
116 +          ;
117 +
118 + inversionstatement  : assignment
119 +              | CENTER^ LPAREN! intConst RPAREN! SEMICOLON!
120 +              ;
121 +
122   rigidbodyblock  : RIGIDBODY^  LBRACKET! intConst RBRACKET! LCURLY!(rigidbodystatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
123                  ;
124  
# Line 133 | Line 141 | fragmentstatement : assignment
141  
142  
143                
144 < signedNumberTuple   : signedNumber (COMMA! signedNumber)*
144 > doubleNumberTuple   : doubleNumber (COMMA! doubleNumber)*
145                ;
146                            
147   inttuple      : intConst (COMMA! intConst)*
# Line 141 | Line 149 | intConst
149                
150   protected
151   intConst
152 <        :  OCTALINT | DECIMALINT | HEXADECIMALINT
152 >        :  NUM_INT | NUM_LONG
153          ;
154  
155   protected
156 < signedNumber  : (PLUS! | MINUS^)?
156 > doubleNumber  :  
157                  (intConst | floatConst)
158                ;
159                
160   protected
161   floatConst
162          :
163 <          FLOATONE | FLOATTWO
163 >          NUM_FLOAT | NUM_DOUBLE
164          ;
165  
166  
# Line 208 | Line 216 | RCURLY          : '}' ;
216   RBRACKET        : ']' ;
217   LCURLY          : '{' ;
218   RCURLY          : '}' ;
211
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             : "||" ;
219  
244 AMPERSAND       : '&' ;
245 BITWISEANDEQUAL : "&=" ;
246 TILDE           : '~' ;
247 BITWISEOR       : '|' ;
248 BITWISEOREQUAL  : "|=" ;
249 BITWISEXOR      : '^' ;
250 BITWISEXOREQUAL : "^=" ;
251 */
252
253
220   Whitespace  
221    :
222      ( // whitespace ignored
# Line 400 | Line 366 | Escape  
366      )
367    ;
368  
403 // Numeric Constants:
369  
370   protected
371 + Vocabulary
372 +  :
373 +    '\3'..'\377'
374 +  ;
375 +
376 +
377 + ID
378 +  options {testLiterals = true;}
379 +  :
380 +    ('a'..'z'|'A'..'Z'|'_')
381 +    ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
382 +  ;
383 +
384 +
385 + protected
386   Digit
387    :
388      '0'..'9'
# Line 414 | Line 394 | Decimal
394      ('0'..'9')+
395    ;
396  
397 + // hexadecimal digit (again, note it's protected!)
398   protected
399 < LongSuffix
400 <  : 'l'
401 <  | 'L'
421 <  ;
399 > HEX_DIGIT
400 >        :       ('0'..'9'|'A'..'F'|'a'..'f')
401 >        ;
402  
423 protected
424 UnsignedSuffix
425  : 'u'
426  | 'U'
427  ;
403  
404 < protected
405 < FloatSuffix
406 <  : 'f'
407 <  | 'F'
408 <  ;
404 > // a numeric literal
405 > NUM_INT
406 >        {
407 >                bool isDecimal = false;
408 >                ANTLR_USE_NAMESPACE(antlr)RefToken t = ANTLR_USE_NAMESPACE(antlr)nullToken;
409 >        }
410 >    : ('+' | '-')?
411 >    (
412 >      '.' {_ttype = DOT;}
413 >            (   ('0'..'9')+ (EXPONENT)? (f1:FLOAT_SUFFIX {t=f1;})?
414 >            {
415 >                                        if ( t &&
416 >                                                  (t->getText().find('f') != ANTLR_USE_NAMESPACE(std)string::npos ||
417 >                                                        t->getText().find('F') != ANTLR_USE_NAMESPACE(std)string::npos ) ) {
418 >                                                _ttype = NUM_FLOAT;
419 >                                        }
420 >                                        else {
421 >                                                _ttype = NUM_DOUBLE; // assume double
422 >                                        }
423 >                                }
424 >            )?
425  
426 < protected
427 < Exponent
428 <  :
429 <    ('e'|'E'|'d'|'D') ('+'|'-')? (Digit)+
430 <  ;
426 >        |       (       '0' {isDecimal = true;} // special case for just '0'
427 >                        (       ('x'|'X')
428 >                                (                                                                                       // hex
429 >                                        // the 'e'|'E' and float suffix stuff look
430 >                                        // like hex digits, hence the (...)+ doesn't
431 >                                        // know when to stop: ambig.  ANTLR resolves
432 >                                        // it correctly by matching immediately.  It
433 >                                        // is therefor ok to hush warning.
434 >                                        options {
435 >                                                warnWhenFollowAmbig=false;
436 >                                        }
437 >                                :       HEX_DIGIT
438 >                                )+
439 >                        |       //float or double with leading zero
440 >                                (('0'..'9')+ ('.'|EXPONENT|FLOAT_SUFFIX)) => ('0'..'9')+
441 >                        |       ('0'..'7')+                                                                     // octal
442 >                        )?
443 >                |       ('1'..'9') ('0'..'9')*  {isDecimal=true;}               // non-zero decimal
444 >                )
445 >                (       ('l'|'L') { _ttype = NUM_LONG; }
446  
447 +                // only check to see if it's a float if looks like decimal so far
448 +                |       {isDecimal}?
449 +            (   '.' ('0'..'9')* (EXPONENT)? (f2:FLOAT_SUFFIX {t=f2;})?
450 +            |   EXPONENT (f3:FLOAT_SUFFIX {t=f3;})?
451 +            |   f4:FLOAT_SUFFIX {t=f4;}
452 +            )
453 +            {
454 +                                        if ( t &&
455 +                                                  (t->getText().find('f') != ANTLR_USE_NAMESPACE(std)string::npos ||
456 +                                                        t->getText().find('F') != ANTLR_USE_NAMESPACE(std)string::npos ) ) {
457 +                                                _ttype = NUM_FLOAT;
458 +                                        }
459 +                                        else {
460 +                                                _ttype = NUM_DOUBLE; // assume double
461 +                                        }
462 +                                }
463 +        )?
464 +  )
465 +        ;
466 +
467 + // a couple protected methods to assist in matching floating point numbers
468   protected
469 < Vocabulary
470 <  :
471 <    '\3'..'\377'
445 <  ;
469 > EXPONENT
470 >        :       ('e'|'E'|'d'|'D') ('+'|'-')? ('0'..'9')+
471 >        ;
472  
473 < Number
474 <  :
475 <    ( (Digit)+ ('.' | 'e' | 'E' | 'd' | 'D' ) )=>
476 <    (Digit)+
451 <    ( '.' (Digit)* (Exponent)? {_ttype = FLOATONE;} //Zuo 3/12/01
452 <    | Exponent                 {_ttype = FLOATTWO;} //Zuo 3/12/01
453 <    )                          //{_ttype = DoubleDoubleConst;}
454 <    (FloatSuffix               //{_ttype = FloatDoubleConst;}
455 <    |LongSuffix                //{_ttype = LongDoubleConst;}
456 <    )?
457 <  |
458 <    '.'                        {_ttype = DOT;}
459 <    ( (Digit)+ (Exponent)?   {_ttype = FLOATONE;} //Zuo 3/12/01
460 <                                   //{_ttype = DoubleDoubleConst;}
461 <      (FloatSuffix           //{_ttype = FloatDoubleConst;}
462 <      |LongSuffix            //{_ttype = LongDoubleConst;}
463 <      )?
464 <    )?
465 <  |
466 <    '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 <  ;
482 <
483 < ID
484 <  options {testLiterals = true;}
485 <  :
486 <    ('a'..'z'|'A'..'Z'|'_')
487 <    ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
488 <  ;
473 > protected
474 > FLOAT_SUFFIX
475 >        :       'f'|'F'|'d'|'D'
476 >        ;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines