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.
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  
# Line 46 | Line 51 | statement : assignment
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 64 | 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 73 | Line 91 | moleculestatement : assignment
91                    | bondblock
92                    | bendblock
93                    | torsionblock
94 +                  | inversionblock
95                    | rigidbodyblock
96                    | cutoffgroupblock
97                    | fragmentblock
# Line 82 | 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 108 | 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 130 | 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 138 | Line 164 | intConst
164                
165   protected
166   intConst
167 <        :  OCTALINT | DECIMALINT | HEXADECIMALINT
167 >        :  NUM_INT | NUM_LONG
168          ;
169  
170   protected
171 < signedNumber  :  
171 > doubleNumber  :  
172                  (intConst | floatConst)
173                ;
174                
175   protected
176   floatConst
177          :
178 <          FLOATONE | FLOATTWO
178 >          NUM_FLOAT | NUM_DOUBLE
179          ;
180  
181  
# Line 205 | Line 231 | RCURLY          : '}' ;
231   RBRACKET        : ']' ;
232   LCURLY          : '{' ;
233   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 */
247
248
235   Whitespace  
236    :
237      ( // whitespace ignored
# Line 296 | 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 395 | Line 381 | Escape  
381      )
382    ;
383  
398 // 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 409 | Line 409 | Decimal
409      ('0'..'9')+
410    ;
411  
412 + // hexadecimal digit (again, note it's protected!)
413   protected
414 < LongSuffix
415 <  : 'l'
416 <  | 'L'
416 <  ;
414 > HEX_DIGIT
415 >        :       ('0'..'9'|'A'..'F'|'a'..'f')
416 >        ;
417  
418 protected
419 UnsignedSuffix
420  : 'u'
421  | 'U'
422  ;
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 < protected
463 < Vocabulary
464 <  :
465 <    '\3'..'\377'
466 <  ;
467 <
468 < Number
469 <  :
470 <  ('+'|'-')?
471 <  (
472 <    ( (Digit)+ ('.' | 'e' | 'E' | 'd' | 'D' ) )=>
473 <    (Digit)+
474 <    ( '.' (Digit)* (Exponent)? {_ttype = FLOATONE;} //Zuo 3/12/01
475 <    | Exponent                 {_ttype = FLOATTWO;} //Zuo 3/12/01
476 <    )                          //{_ttype = DoubleDoubleConst;}
477 <    (FloatSuffix               //{_ttype = FloatDoubleConst;}
478 <    |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;}  
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 <  ;
480 >        ;
481  
482 < ID
483 <  options {testLiterals = true;}
484 <  :
485 <    ('a'..'z'|'A'..'Z'|'_')
486 <    ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
487 <  ;
482 > // a couple protected methods to assist in matching floating point numbers
483 > protected
484 > EXPONENT
485 >        :       ('e'|'E'|'d'|'D') ('+'|'-')? ('0'..'9')+
486 >        ;
487 >
488 > protected
489 > FLOAT_SUFFIX
490 >        :       'f'|'F'|'d'|'D'
491 >        ;

Comparing:
trunk/src/mdParser/MDParser.g (property svn:keywords), Revision 810 by tim, Wed Dec 14 18:02:28 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