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 810 by tim, Wed Dec 14 18:02:28 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;
# Line 54 | 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 82 | 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 108 | 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 130 | 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 138 | Line 148 | intConst
148                
149   protected
150   intConst
151 <        :  OCTALINT | DECIMALINT | HEXADECIMALINT
151 >        :  NUM_INT | NUM_LONG
152          ;
153  
154   protected
155 < signedNumber  :  
155 > doubleNumber  :  
156                  (intConst | floatConst)
157                ;
158                
159   protected
160   floatConst
161          :
162 <          FLOATONE | FLOATTWO
162 >          NUM_FLOAT | NUM_DOUBLE
163          ;
164  
165  
# Line 205 | Line 215 | RCURLY          : '}' ;
215   RBRACKET        : ']' ;
216   LCURLY          : '{' ;
217   RCURLY          : '}' ;
208
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 */
218  
248
219   Whitespace  
220    :
221      ( // whitespace ignored
# Line 395 | Line 365 | Escape  
365      )
366    ;
367  
398 // 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 409 | Line 393 | Decimal
393      ('0'..'9')+
394    ;
395  
396 + // hexadecimal digit (again, note it's protected!)
397   protected
398 < LongSuffix
399 <  : 'l'
400 <  | 'L'
416 <  ;
398 > HEX_DIGIT
399 >        :       ('0'..'9'|'A'..'F'|'a'..'f')
400 >        ;
401  
418 protected
419 UnsignedSuffix
420  : 'u'
421  | 'U'
422  ;
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 < protected
447 < Vocabulary
448 <  :
449 <    '\3'..'\377'
450 <  ;
451 <
452 < Number
453 <  :
454 <  ('+'|'-')?
455 <  (
456 <    ( (Digit)+ ('.' | 'e' | 'E' | 'd' | 'D' ) )=>
457 <    (Digit)+
458 <    ( '.' (Digit)* (Exponent)? {_ttype = FLOATONE;} //Zuo 3/12/01
459 <    | Exponent                 {_ttype = FLOATTWO;} //Zuo 3/12/01
460 <    )                          //{_ttype = DoubleDoubleConst;}
461 <    (FloatSuffix               //{_ttype = FloatDoubleConst;}
462 <    |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;}  
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 <  ;
464 >        ;
465  
466 < ID
467 <  options {testLiterals = true;}
468 <  :
469 <    ('a'..'z'|'A'..'Z'|'_')
470 <    ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
471 <  ;
466 > // a couple protected methods to assist in matching floating point numbers
467 > protected
468 > EXPONENT
469 >        :       ('e'|'E'|'d'|'D') ('+'|'-')? ('0'..'9')+
470 >        ;
471 >
472 > protected
473 > FLOAT_SUFFIX
474 >        :       'f'|'F'|'d'|'D'
475 >        ;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines