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 1275 by cli2, Fri Jul 4 20:54:29 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 85 | Line 85 | atomstatement : assignment
85            ;
86  
87   atomstatement : assignment
88 <              | POSITION^ LPAREN! signedNumberTuple RPAREN! SEMICOLON!
89 <              | ORIENTATION^  LPAREN! signedNumberTuple RPAREN! SEMICOLON!
88 >              | POSITION^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
89 >              | ORIENTATION^  LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
90                ;
91  
92                        
# Line 111 | Line 111 | torsionstatement  : assignment
111                | MEMBERS^ LPAREN! inttuple RPAREN! SEMICOLON!
112                ;
113  
114 + inversionblock  : INVERSION^ (LBRACKET! intConst! RBRACKET!)?  LCURLY!(inversionstatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
115 +          ;
116 +
117 + inversionstatement  : assignment
118 +              | CENTER^ LPAREN! intConst RPAREN! SEMICOLON!
119 +              ;
120 +
121   rigidbodyblock  : RIGIDBODY^  LBRACKET! intConst RBRACKET! LCURLY!(rigidbodystatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
122                  ;
123  
# Line 133 | Line 140 | fragmentstatement : assignment
140  
141  
142                
143 < signedNumberTuple   : signedNumber (COMMA! signedNumber)*
143 > doubleNumberTuple   : doubleNumber (COMMA! doubleNumber)*
144                ;
145                            
146   inttuple      : intConst (COMMA! intConst)*
# Line 141 | Line 148 | intConst
148                
149   protected
150   intConst
151 <        :  OCTALINT | DECIMALINT | HEXADECIMALINT
151 >        :  NUM_INT | NUM_LONG
152          ;
153  
154   protected
155 < signedNumber  : (PLUS! | MINUS^)?
155 > doubleNumber  :  
156                  (intConst | floatConst)
157                ;
158                
159   protected
160   floatConst
161          :
162 <          FLOATONE | FLOATTWO
162 >          NUM_FLOAT | NUM_DOUBLE
163          ;
164  
165  
# Line 209 | Line 216 | RCURLY          : '}' ;
216   LCURLY          : '{' ;
217   RCURLY          : '}' ;
218  
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
219   Whitespace  
220    :
221      ( // whitespace ignored
# Line 400 | Line 365 | Escape  
365      )
366    ;
367  
403 // Numeric Constants:
368  
369   protected
370 + Vocabulary
371 +  :
372 +    '\3'..'\377'
373 +  ;
374 +
375 +
376 + ID
377 +  options {testLiterals = true;}
378 +  :
379 +    ('a'..'z'|'A'..'Z'|'_')
380 +    ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
381 +  ;
382 +
383 +
384 + protected
385   Digit
386    :
387      '0'..'9'
# Line 414 | Line 393 | Decimal
393      ('0'..'9')+
394    ;
395  
396 + // hexadecimal digit (again, note it's protected!)
397   protected
398 < LongSuffix
399 <  : 'l'
400 <  | 'L'
421 <  ;
398 > HEX_DIGIT
399 >        :       ('0'..'9'|'A'..'F'|'a'..'f')
400 >        ;
401  
423 protected
424 UnsignedSuffix
425  : 'u'
426  | 'U'
427  ;
402  
403 < protected
404 < FloatSuffix
405 <  : 'f'
406 <  | 'F'
407 <  ;
403 > // a numeric literal
404 > NUM_INT
405 >        {
406 >                bool isDecimal = false;
407 >                ANTLR_USE_NAMESPACE(antlr)RefToken t = ANTLR_USE_NAMESPACE(antlr)nullToken;
408 >        }
409 >    : ('+' | '-')?
410 >    (
411 >      '.' {_ttype = DOT;}
412 >            (   ('0'..'9')+ (EXPONENT)? (f1:FLOAT_SUFFIX {t=f1;})?
413 >            {
414 >                                        if ( t &&
415 >                                                  (t->getText().find('f') != ANTLR_USE_NAMESPACE(std)string::npos ||
416 >                                                        t->getText().find('F') != ANTLR_USE_NAMESPACE(std)string::npos ) ) {
417 >                                                _ttype = NUM_FLOAT;
418 >                                        }
419 >                                        else {
420 >                                                _ttype = NUM_DOUBLE; // assume double
421 >                                        }
422 >                                }
423 >            )?
424  
425 < protected
426 < Exponent
427 <  :
428 <    ('e'|'E'|'d'|'D') ('+'|'-')? (Digit)+
429 <  ;
425 >        |       (       '0' {isDecimal = true;} // special case for just '0'
426 >                        (       ('x'|'X')
427 >                                (                                                                                       // hex
428 >                                        // the 'e'|'E' and float suffix stuff look
429 >                                        // like hex digits, hence the (...)+ doesn't
430 >                                        // know when to stop: ambig.  ANTLR resolves
431 >                                        // it correctly by matching immediately.  It
432 >                                        // is therefor ok to hush warning.
433 >                                        options {
434 >                                                warnWhenFollowAmbig=false;
435 >                                        }
436 >                                :       HEX_DIGIT
437 >                                )+
438 >                        |       //float or double with leading zero
439 >                                (('0'..'9')+ ('.'|EXPONENT|FLOAT_SUFFIX)) => ('0'..'9')+
440 >                        |       ('0'..'7')+                                                                     // octal
441 >                        )?
442 >                |       ('1'..'9') ('0'..'9')*  {isDecimal=true;}               // non-zero decimal
443 >                )
444 >                (       ('l'|'L') { _ttype = NUM_LONG; }
445  
446 +                // only check to see if it's a float if looks like decimal so far
447 +                |       {isDecimal}?
448 +            (   '.' ('0'..'9')* (EXPONENT)? (f2:FLOAT_SUFFIX {t=f2;})?
449 +            |   EXPONENT (f3:FLOAT_SUFFIX {t=f3;})?
450 +            |   f4:FLOAT_SUFFIX {t=f4;}
451 +            )
452 +            {
453 +                                        if ( t &&
454 +                                                  (t->getText().find('f') != ANTLR_USE_NAMESPACE(std)string::npos ||
455 +                                                        t->getText().find('F') != ANTLR_USE_NAMESPACE(std)string::npos ) ) {
456 +                                                _ttype = NUM_FLOAT;
457 +                                        }
458 +                                        else {
459 +                                                _ttype = NUM_DOUBLE; // assume double
460 +                                        }
461 +                                }
462 +        )?
463 +  )
464 +        ;
465 +
466 + // a couple protected methods to assist in matching floating point numbers
467   protected
468 < Vocabulary
469 <  :
470 <    '\3'..'\377'
445 <  ;
468 > EXPONENT
469 >        :       ('e'|'E'|'d'|'D') ('+'|'-')? ('0'..'9')+
470 >        ;
471  
472 < Number
473 <  :
474 <    ( (Digit)+ ('.' | 'e' | 'E' | 'd' | 'D' ) )=>
475 <    (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 <  ;
472 > protected
473 > FLOAT_SUFFIX
474 >        :       'f'|'F'|'d'|'D'
475 >        ;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines