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.
branches/development/src/mdParser/MDParser.g (file contents), Revision 1465 by chuckv, Fri Jul 9 23:08:25 2010 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    FRAGMENT    = "fragment";
40    MEMBERS     = "members";
41 +  CENTER      = "center";
42    POSITION    = "position";
43    ORIENTATION = "orientation";
44    ENDBLOCK;
45   }
46  
44 {
45    // Suppport C++-style single-line comments?
46 }
47  
48   mdfile  : (statement)*
49          ;
# Line 52 | Line 52 | statement : assignment
52            | componentblock
53            | moleculeblock
54            | zconstraintblock
55 +          | restraintblock
56            ;
57              
58   assignment  : ID ASSIGNEQUAL^ constant SEMICOLON!
59              ;
60              
61 < constant    : signedNumber
61 > constant    : intConst
62 >                                                | floatConst
63              | ID
64              | StringLiteral
65              ;
# Line 67 | Line 69 | zconstraintblock  : ZCONSTRAINT^ LCURLY! (assignment)*
69      
70   zconstraintblock  : ZCONSTRAINT^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
71                    ;
72 +
73 + restraintblock  : RESTRAINT^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
74 +                  ;
75    
76   moleculeblock : MOLECULE^ LCURLY! (moleculestatement)*  RCURLY {#RCURLY->setType(ENDBLOCK);}
77                ;
# Line 76 | Line 81 | moleculestatement : assignment
81                    | bondblock
82                    | bendblock
83                    | torsionblock
84 +                  | inversionblock
85                    | rigidbodyblock
86                    | cutoffgroupblock
87                    | fragmentblock
# Line 85 | Line 91 | atomstatement : assignment
91            ;
92  
93   atomstatement : assignment
94 <              | POSITION^ LPAREN! signedNumberTuple RPAREN! SEMICOLON!
95 <              | ORIENTATION^  LPAREN! signedNumberTuple RPAREN! SEMICOLON!
94 >              | POSITION^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
95 >              | ORIENTATION^  LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
96                ;
97  
98                        
# Line 111 | Line 117 | torsionstatement  : assignment
117                | MEMBERS^ LPAREN! inttuple RPAREN! SEMICOLON!
118                ;
119  
120 + inversionblock  : INVERSION^ (LBRACKET! intConst! RBRACKET!)?  LCURLY!(inversionstatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
121 +          ;
122 +
123 + inversionstatement  : assignment
124 +              | CENTER^ LPAREN! intConst RPAREN! SEMICOLON!
125 +              ;
126 +
127   rigidbodyblock  : RIGIDBODY^  LBRACKET! intConst RBRACKET! LCURLY!(rigidbodystatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
128                  ;
129  
# Line 133 | Line 146 | fragmentstatement : assignment
146  
147  
148                
149 < signedNumberTuple   : signedNumber (COMMA! signedNumber)*
149 > doubleNumberTuple   : doubleNumber (COMMA! doubleNumber)*
150                ;
151                            
152   inttuple      : intConst (COMMA! intConst)*
# Line 141 | Line 154 | intConst
154                
155   protected
156   intConst
157 <        :  OCTALINT | DECIMALINT | HEXADECIMALINT
157 >        :  NUM_INT | NUM_LONG
158          ;
159  
160   protected
161 < signedNumber  : (PLUS! | MINUS^)?
161 > doubleNumber  :  
162                  (intConst | floatConst)
163                ;
164                
165   protected
166   floatConst
167          :
168 <          FLOATONE | FLOATTWO
168 >          NUM_FLOAT | NUM_DOUBLE
169          ;
170  
171  
# Line 209 | Line 222 | RCURLY          : '}' ;
222   LCURLY          : '{' ;
223   RCURLY          : '}' ;
224  
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
225   Whitespace  
226    :
227      ( // whitespace ignored
# Line 301 | Line 272 | LineDirective
272    }
273      ("line")?  // this would be for if the directive started "#line"
274      (Space)+
275 <    n:Decimal { setLine(oopse::lexi_cast<int>(n->getText()) - 1); }
275 >    n:Decimal { setLine(OpenMD::lexi_cast<int>(n->getText()) - 1); }
276      (Space)+
277      (sl:StringLiteral) {std::string filename = sl->getText().substr(1,sl->getText().length()-2); observer->notify(filename);}
278      ((Space)+ Decimal)* // To support cpp flags (GNU)
# Line 400 | Line 371 | Escape  
371      )
372    ;
373  
403 // Numeric Constants:
374  
375   protected
376 + Vocabulary
377 +  :
378 +    '\3'..'\377'
379 +  ;
380 +
381 +
382 + ID
383 +  options {testLiterals = true;}
384 +  :
385 +    ('a'..'z'|'A'..'Z'|'_')
386 +    ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
387 +  ;
388 +
389 +
390 + protected
391   Digit
392    :
393      '0'..'9'
# Line 414 | Line 399 | Decimal
399      ('0'..'9')+
400    ;
401  
402 + // hexadecimal digit (again, note it's protected!)
403   protected
404 < LongSuffix
405 <  : 'l'
406 <  | 'L'
421 <  ;
404 > HEX_DIGIT
405 >        :       ('0'..'9'|'A'..'F'|'a'..'f')
406 >        ;
407  
423 protected
424 UnsignedSuffix
425  : 'u'
426  | 'U'
427  ;
408  
409 < protected
410 < FloatSuffix
411 <  : 'f'
412 <  | 'F'
413 <  ;
409 > // a numeric literal
410 > NUM_INT
411 >        {
412 >                bool isDecimal = false;
413 >                ANTLR_USE_NAMESPACE(antlr)RefToken t = ANTLR_USE_NAMESPACE(antlr)nullToken;
414 >        }
415 >    : ('+' | '-')?
416 >    (
417 >      '.' {_ttype = DOT;}
418 >            (   ('0'..'9')+ (EXPONENT)? (f1:FLOAT_SUFFIX {t=f1;})?
419 >            {
420 >                                        if ( t &&
421 >                                                  (t->getText().find('f') != ANTLR_USE_NAMESPACE(std)string::npos ||
422 >                                                        t->getText().find('F') != ANTLR_USE_NAMESPACE(std)string::npos ) ) {
423 >                                                _ttype = NUM_FLOAT;
424 >                                        }
425 >                                        else {
426 >                                                _ttype = NUM_DOUBLE; // assume double
427 >                                        }
428 >                                }
429 >            )?
430  
431 < protected
432 < Exponent
433 <  :
434 <    ('e'|'E'|'d'|'D') ('+'|'-')? (Digit)+
435 <  ;
431 >        |       (       '0' {isDecimal = true;} // special case for just '0'
432 >                        (       ('x'|'X')
433 >                                (                                                                                       // hex
434 >                                        // the 'e'|'E' and float suffix stuff look
435 >                                        // like hex digits, hence the (...)+ doesn't
436 >                                        // know when to stop: ambig.  ANTLR resolves
437 >                                        // it correctly by matching immediately.  It
438 >                                        // is therefor ok to hush warning.
439 >                                        options {
440 >                                                warnWhenFollowAmbig=false;
441 >                                        }
442 >                                :       HEX_DIGIT
443 >                                )+
444 >                        |       //float or double with leading zero
445 >                                (('0'..'9')+ ('.'|EXPONENT|FLOAT_SUFFIX)) => ('0'..'9')+
446 >                        |       ('0'..'7')+                                                                     // octal
447 >                        )?
448 >                |       ('1'..'9') ('0'..'9')*  {isDecimal=true;}               // non-zero decimal
449 >                )
450 >                (       ('l'|'L') { _ttype = NUM_LONG; }
451  
452 +                // only check to see if it's a float if looks like decimal so far
453 +                |       {isDecimal}?
454 +            (   '.' ('0'..'9')* (EXPONENT)? (f2:FLOAT_SUFFIX {t=f2;})?
455 +            |   EXPONENT (f3:FLOAT_SUFFIX {t=f3;})?
456 +            |   f4:FLOAT_SUFFIX {t=f4;}
457 +            )
458 +            {
459 +                                        if ( t &&
460 +                                                  (t->getText().find('f') != ANTLR_USE_NAMESPACE(std)string::npos ||
461 +                                                        t->getText().find('F') != ANTLR_USE_NAMESPACE(std)string::npos ) ) {
462 +                                                _ttype = NUM_FLOAT;
463 +                                        }
464 +                                        else {
465 +                                                _ttype = NUM_DOUBLE; // assume double
466 +                                        }
467 +                                }
468 +        )?
469 +  )
470 +        ;
471 +
472 + // a couple protected methods to assist in matching floating point numbers
473   protected
474 < Vocabulary
475 <  :
476 <    '\3'..'\377'
445 <  ;
474 > EXPONENT
475 >        :       ('e'|'E'|'d'|'D') ('+'|'-')? ('0'..'9')+
476 >        ;
477  
478 < Number
479 <  :
480 <    ( (Digit)+ ('.' | 'e' | 'E' | 'd' | 'D' ) )=>
481 <    (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 <  ;
478 > protected
479 > FLOAT_SUFFIX
480 >        :       'f'|'F'|'d'|'D'
481 >        ;

Comparing:
trunk/src/mdParser/MDParser.g (property svn:keywords), Revision 770 by tim, Fri Dec 2 15:38:03 2005 UTC vs.
branches/development/src/mdParser/MDParser.g (property svn:keywords), Revision 1465 by chuckv, Fri Jul 9 23:08:25 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines