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 1731 by gezelter, Thu May 31 12:25:30 2012 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 +  FLUCQ       = "flucQ";
45 +  RNEMD       = "RNEMD";
46    ENDBLOCK;
47   }
48  
44 {
45    // Suppport C++-style single-line comments?
46 }
49  
50   mdfile  : (statement)*
51          ;
52  
53   statement : assignment
54 <          | componentblock
55 <          | moleculeblock
56 <          | zconstraintblock
57 <          ;
58 <            
54 >    | componentblock
55 >    | moleculeblock
56 >    | zconstraintblock
57 >    | restraintblock
58 >    | flucqblock
59 >    | rnemdblock
60 >    ;
61 >
62   assignment  : ID ASSIGNEQUAL^ constant SEMICOLON!
63              ;
64              
65 < constant    : signedNumber
65 > constant    : intConst
66 >                                                | floatConst
67              | ID
68              | StringLiteral
69              ;
# Line 67 | Line 73 | zconstraintblock  : ZCONSTRAINT^ LCURLY! (assignment)*
73      
74   zconstraintblock  : ZCONSTRAINT^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
75                    ;
76 +
77 + restraintblock  : RESTRAINT^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
78 +                  ;
79 +
80 + flucqblock  : FLUCQ^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
81 +    ;
82 +
83 + rnemdblock  : RNEMD^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
84 +    ;
85    
86   moleculeblock : MOLECULE^ LCURLY! (moleculestatement)*  RCURLY {#RCURLY->setType(ENDBLOCK);}
87                ;
# Line 76 | Line 91 | moleculestatement : assignment
91                    | bondblock
92                    | bendblock
93                    | torsionblock
94 +                  | inversionblock
95                    | rigidbodyblock
96                    | cutoffgroupblock
97                    | fragmentblock
# Line 85 | Line 101 | atomstatement : assignment
101            ;
102  
103   atomstatement : assignment
104 <              | POSITION^ LPAREN! signedNumberTuple RPAREN! SEMICOLON!
105 <              | ORIENTATION^  LPAREN! signedNumberTuple RPAREN! SEMICOLON!
104 >              | POSITION^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
105 >              | ORIENTATION^  LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
106                ;
107  
108                        
# Line 111 | Line 127 | torsionstatement  : assignment
127                | MEMBERS^ LPAREN! inttuple RPAREN! SEMICOLON!
128                ;
129  
130 + inversionblock  : INVERSION^ (LBRACKET! intConst! RBRACKET!)?  LCURLY!(inversionstatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
131 +          ;
132 +
133 + inversionstatement  : assignment
134 +              | CENTER^ LPAREN! intConst RPAREN! SEMICOLON!
135 +              ;
136 +
137   rigidbodyblock  : RIGIDBODY^  LBRACKET! intConst RBRACKET! LCURLY!(rigidbodystatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
138                  ;
139  
# Line 133 | Line 156 | fragmentstatement : assignment
156  
157  
158                
159 < signedNumberTuple   : signedNumber (COMMA! signedNumber)*
159 > doubleNumberTuple   : doubleNumber (COMMA! doubleNumber)*
160                ;
161                            
162   inttuple      : intConst (COMMA! intConst)*
# Line 141 | Line 164 | intConst
164                
165   protected
166   intConst
167 <        :  OCTALINT | DECIMALINT | HEXADECIMALINT
167 >        :  NUM_INT | NUM_LONG
168          ;
169  
170   protected
171 < signedNumber  : (PLUS! | MINUS^)?
171 > doubleNumber  :  
172                  (intConst | floatConst)
173                ;
174                
175   protected
176   floatConst
177          :
178 <          FLOATONE | FLOATTWO
178 >          NUM_FLOAT | NUM_DOUBLE
179          ;
180  
181  
# Line 208 | Line 231 | RCURLY          : '}' ;
231   RBRACKET        : ']' ;
232   LCURLY          : '{' ;
233   RCURLY          : '}' ;
211
212 PLUS            : '+' ;
213 MINUS           : '-' ;
214
215 /*
216 EQUAL           : "==" ;
217 NOTEQUAL        : "!=" ;
218 LESSTHANOREQUALTO     : "<=" ;
219 LESSTHAN              : "<" ;
220 GREATERTHANOREQUALTO  : ">=" ;
221 GREATERTHAN           : ">" ;
234  
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
235   Whitespace  
236    :
237      ( // whitespace ignored
# Line 301 | Line 282 | LineDirective
282    }
283      ("line")?  // this would be for if the directive started "#line"
284      (Space)+
285 <    n:Decimal { setLine(oopse::lexi_cast<int>(n->getText()) - 1); }
285 >    n:Decimal { setLine(OpenMD::lexi_cast<int>(n->getText()) - 1); }
286      (Space)+
287      (sl:StringLiteral) {std::string filename = sl->getText().substr(1,sl->getText().length()-2); observer->notify(filename);}
288      ((Space)+ Decimal)* // To support cpp flags (GNU)
# Line 400 | Line 381 | Escape  
381      )
382    ;
383  
403 // Numeric Constants:
384  
385   protected
386 + Vocabulary
387 +  :
388 +    '\3'..'\377'
389 +  ;
390 +
391 +
392 + ID
393 +  options {testLiterals = true;}
394 +  :
395 +    ('a'..'z'|'A'..'Z'|'_')
396 +    ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
397 +  ;
398 +
399 +
400 + protected
401   Digit
402    :
403      '0'..'9'
# Line 414 | Line 409 | Decimal
409      ('0'..'9')+
410    ;
411  
412 + // hexadecimal digit (again, note it's protected!)
413   protected
414 < LongSuffix
415 <  : 'l'
416 <  | 'L'
421 <  ;
414 > HEX_DIGIT
415 >        :       ('0'..'9'|'A'..'F'|'a'..'f')
416 >        ;
417  
423 protected
424 UnsignedSuffix
425  : 'u'
426  | 'U'
427  ;
418  
419 < protected
420 < FloatSuffix
421 <  : 'f'
422 <  | 'F'
423 <  ;
419 > // a numeric literal
420 > NUM_INT
421 >        {
422 >                bool isDecimal = false;
423 >                ANTLR_USE_NAMESPACE(antlr)RefToken t = ANTLR_USE_NAMESPACE(antlr)nullToken;
424 >        }
425 >    : ('+' | '-')?
426 >    (
427 >      '.' {_ttype = DOT;}
428 >            (   ('0'..'9')+ (EXPONENT)? (f1:FLOAT_SUFFIX {t=f1;})?
429 >            {
430 >                                        if ( t &&
431 >                                                  (t->getText().find('f') != ANTLR_USE_NAMESPACE(std)string::npos ||
432 >                                                        t->getText().find('F') != ANTLR_USE_NAMESPACE(std)string::npos ) ) {
433 >                                                _ttype = NUM_FLOAT;
434 >                                        }
435 >                                        else {
436 >                                                _ttype = NUM_DOUBLE; // assume double
437 >                                        }
438 >                                }
439 >            )?
440  
441 < protected
442 < Exponent
443 <  :
444 <    ('e'|'E'|'d'|'D') ('+'|'-')? (Digit)+
445 <  ;
441 >        |       (       '0' {isDecimal = true;} // special case for just '0'
442 >                        (       ('x'|'X')
443 >                                (                                                                                       // hex
444 >                                        // the 'e'|'E' and float suffix stuff look
445 >                                        // like hex digits, hence the (...)+ doesn't
446 >                                        // know when to stop: ambig.  ANTLR resolves
447 >                                        // it correctly by matching immediately.  It
448 >                                        // is therefor ok to hush warning.
449 >                                        options {
450 >                                                warnWhenFollowAmbig=false;
451 >                                        }
452 >                                :       HEX_DIGIT
453 >                                )+
454 >                        |       //float or double with leading zero
455 >                                (('0'..'9')+ ('.'|EXPONENT|FLOAT_SUFFIX)) => ('0'..'9')+
456 >                        |       ('0'..'7')+                                                                     // octal
457 >                        )?
458 >                |       ('1'..'9') ('0'..'9')*  {isDecimal=true;}               // non-zero decimal
459 >                )
460 >                (       ('l'|'L') { _ttype = NUM_LONG; }
461  
462 +                // only check to see if it's a float if looks like decimal so far
463 +                |       {isDecimal}?
464 +            (   '.' ('0'..'9')* (EXPONENT)? (f2:FLOAT_SUFFIX {t=f2;})?
465 +            |   EXPONENT (f3:FLOAT_SUFFIX {t=f3;})?
466 +            |   f4:FLOAT_SUFFIX {t=f4;}
467 +            )
468 +            {
469 +                                        if ( t &&
470 +                                                  (t->getText().find('f') != ANTLR_USE_NAMESPACE(std)string::npos ||
471 +                                                        t->getText().find('F') != ANTLR_USE_NAMESPACE(std)string::npos ) ) {
472 +                                                _ttype = NUM_FLOAT;
473 +                                        }
474 +                                        else {
475 +                                                _ttype = NUM_DOUBLE; // assume double
476 +                                        }
477 +                                }
478 +        )?
479 +  )
480 +        ;
481 +
482 + // a couple protected methods to assist in matching floating point numbers
483   protected
484 < Vocabulary
485 <  :
486 <    '\3'..'\377'
445 <  ;
484 > EXPONENT
485 >        :       ('e'|'E'|'d'|'D') ('+'|'-')? ('0'..'9')+
486 >        ;
487  
488 < Number
489 <  :
490 <    ( (Digit)+ ('.' | 'e' | 'E' | 'd' | 'D' ) )=>
491 <    (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 <  ;
488 > protected
489 > FLOAT_SUFFIX
490 >        :       'f'|'F'|'d'|'D'
491 >        ;

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 1731 by gezelter, Thu May 31 12:25:30 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines