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 1746 by gezelter, Wed Jun 6 02:18:54 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 +  MINIMIZER   = "minimizer";
47    ENDBLOCK;
48   }
49  
# Line 46 | Line 52 | statement : assignment
52          ;
53  
54   statement : assignment
55 <          | componentblock
56 <          | moleculeblock
57 <          | zconstraintblock
58 <          ;
59 <            
55 >    | componentblock
56 >    | moleculeblock
57 >    | zconstraintblock
58 >    | restraintblock
59 >    | flucqblock
60 >    | rnemdblock
61 >    | minimizerblock
62 >    ;
63 >
64   assignment  : ID ASSIGNEQUAL^ constant SEMICOLON!
65              ;
66              
67 < constant    : signedNumber
67 > constant    : intConst
68 >                                                | floatConst
69              | ID
70              | StringLiteral
71              ;
# Line 64 | Line 75 | zconstraintblock  : ZCONSTRAINT^ LCURLY! (assignment)*
75      
76   zconstraintblock  : ZCONSTRAINT^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
77                    ;
78 +
79 + restraintblock  : RESTRAINT^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
80 +                  ;
81 +
82 + flucqblock  : FLUCQ^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
83 +    ;
84 +
85 + rnemdblock  : RNEMD^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
86 +    ;
87 +
88 + minimizerblock  : MINIMIZER^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
89 +    ;
90    
91   moleculeblock : MOLECULE^ LCURLY! (moleculestatement)*  RCURLY {#RCURLY->setType(ENDBLOCK);}
92                ;
# Line 73 | Line 96 | moleculestatement : assignment
96                    | bondblock
97                    | bendblock
98                    | torsionblock
99 +                  | inversionblock
100                    | rigidbodyblock
101                    | cutoffgroupblock
102                    | fragmentblock
# Line 82 | Line 106 | atomstatement : assignment
106            ;
107  
108   atomstatement : assignment
109 <              | POSITION^ LPAREN! signedNumberTuple RPAREN! SEMICOLON!
110 <              | ORIENTATION^  LPAREN! signedNumberTuple RPAREN! SEMICOLON!
109 >              | POSITION^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
110 >              | ORIENTATION^  LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
111                ;
112  
113                        
# Line 108 | Line 132 | torsionstatement  : assignment
132                | MEMBERS^ LPAREN! inttuple RPAREN! SEMICOLON!
133                ;
134  
135 + inversionblock  : INVERSION^ (LBRACKET! intConst! RBRACKET!)?  LCURLY!(inversionstatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
136 +          ;
137 +
138 + inversionstatement  : assignment
139 +              | CENTER^ LPAREN! intConst RPAREN! SEMICOLON!
140 +              ;
141 +
142   rigidbodyblock  : RIGIDBODY^  LBRACKET! intConst RBRACKET! LCURLY!(rigidbodystatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
143                  ;
144  
# Line 130 | Line 161 | fragmentstatement : assignment
161  
162  
163                
164 < signedNumberTuple   : signedNumber (COMMA! signedNumber)*
164 > doubleNumberTuple   : doubleNumber (COMMA! doubleNumber)*
165                ;
166                            
167   inttuple      : intConst (COMMA! intConst)*
# Line 138 | Line 169 | intConst
169                
170   protected
171   intConst
172 <        :  OCTALINT | DECIMALINT | HEXADECIMALINT
172 >        :  NUM_INT | NUM_LONG
173          ;
174  
175   protected
176 < signedNumber  :  
176 > doubleNumber  :  
177                  (intConst | floatConst)
178                ;
179                
180   protected
181   floatConst
182          :
183 <          FLOATONE | FLOATTWO
183 >          NUM_FLOAT | NUM_DOUBLE
184          ;
185  
186  
# Line 206 | Line 237 | RCURLY          : '}' ;
237   LCURLY          : '{' ;
238   RCURLY          : '}' ;
239  
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
240   Whitespace  
241    :
242      ( // whitespace ignored
# Line 296 | Line 287 | LineDirective
287    }
288      ("line")?  // this would be for if the directive started "#line"
289      (Space)+
290 <    n:Decimal { setLine(oopse::lexi_cast<int>(n->getText()) - 1); }
290 >    n:Decimal { setLine(OpenMD::lexi_cast<int>(n->getText()) - 1); }
291      (Space)+
292      (sl:StringLiteral) {std::string filename = sl->getText().substr(1,sl->getText().length()-2); observer->notify(filename);}
293      ((Space)+ Decimal)* // To support cpp flags (GNU)
# Line 395 | Line 386 | Escape  
386      )
387    ;
388  
398 // Numeric Constants:
389  
390   protected
391 + Vocabulary
392 +  :
393 +    '\3'..'\377'
394 +  ;
395 +
396 +
397 + ID
398 +  options {testLiterals = true;}
399 +  :
400 +    ('a'..'z'|'A'..'Z'|'_')
401 +    ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
402 +  ;
403 +
404 +
405 + protected
406   Digit
407    :
408      '0'..'9'
# Line 409 | Line 414 | Decimal
414      ('0'..'9')+
415    ;
416  
417 + // hexadecimal digit (again, note it's protected!)
418   protected
419 < LongSuffix
420 <  : 'l'
421 <  | 'L'
416 <  ;
419 > HEX_DIGIT
420 >        :       ('0'..'9'|'A'..'F'|'a'..'f')
421 >        ;
422  
418 protected
419 UnsignedSuffix
420  : 'u'
421  | 'U'
422  ;
423  
424 < protected
425 < FloatSuffix
426 <  : 'f'
427 <  | 'F'
428 <  ;
424 > // a numeric literal
425 > NUM_INT
426 >        {
427 >                bool isDecimal = false;
428 >                ANTLR_USE_NAMESPACE(antlr)RefToken t = ANTLR_USE_NAMESPACE(antlr)nullToken;
429 >        }
430 >    : ('+' | '-')?
431 >    (
432 >      '.' {_ttype = DOT;}
433 >            (   ('0'..'9')+ (EXPONENT)? (f1:FLOAT_SUFFIX {t=f1;})?
434 >            {
435 >                                        if ( t &&
436 >                                                  (t->getText().find('f') != ANTLR_USE_NAMESPACE(std)string::npos ||
437 >                                                        t->getText().find('F') != ANTLR_USE_NAMESPACE(std)string::npos ) ) {
438 >                                                _ttype = NUM_FLOAT;
439 >                                        }
440 >                                        else {
441 >                                                _ttype = NUM_DOUBLE; // assume double
442 >                                        }
443 >                                }
444 >            )?
445  
446 < protected
447 < Exponent
448 <  :
449 <    ('e'|'E'|'d'|'D') ('+'|'-')? (Digit)+
450 <  ;
446 >        |       (       '0' {isDecimal = true;} // special case for just '0'
447 >                        (       ('x'|'X')
448 >                                (                                                                                       // hex
449 >                                        // the 'e'|'E' and float suffix stuff look
450 >                                        // like hex digits, hence the (...)+ doesn't
451 >                                        // know when to stop: ambig.  ANTLR resolves
452 >                                        // it correctly by matching immediately.  It
453 >                                        // is therefor ok to hush warning.
454 >                                        options {
455 >                                                warnWhenFollowAmbig=false;
456 >                                        }
457 >                                :       HEX_DIGIT
458 >                                )+
459 >                        |       //float or double with leading zero
460 >                                (('0'..'9')+ ('.'|EXPONENT|FLOAT_SUFFIX)) => ('0'..'9')+
461 >                        |       ('0'..'7')+                                                                     // octal
462 >                        )?
463 >                |       ('1'..'9') ('0'..'9')*  {isDecimal=true;}               // non-zero decimal
464 >                )
465 >                (       ('l'|'L') { _ttype = NUM_LONG; }
466  
467 < protected
468 < Vocabulary
469 <  :
470 <    '\3'..'\377'
471 <  ;
472 <
473 < Number
474 <  :
475 <  ('+'|'-')?
476 <  (
477 <    ( (Digit)+ ('.' | 'e' | 'E' | 'd' | 'D' ) )=>
478 <    (Digit)+
479 <    ( '.' (Digit)* (Exponent)? {_ttype = FLOATONE;} //Zuo 3/12/01
480 <    | Exponent                 {_ttype = FLOATTWO;} //Zuo 3/12/01
481 <    )                          //{_ttype = DoubleDoubleConst;}
482 <    (FloatSuffix               //{_ttype = FloatDoubleConst;}
483 <    |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;}  
467 >                // only check to see if it's a float if looks like decimal so far
468 >                |       {isDecimal}?
469 >            (   '.' ('0'..'9')* (EXPONENT)? (f2:FLOAT_SUFFIX {t=f2;})?
470 >            |   EXPONENT (f3:FLOAT_SUFFIX {t=f3;})?
471 >            |   f4:FLOAT_SUFFIX {t=f4;}
472 >            )
473 >            {
474 >                                        if ( t &&
475 >                                                  (t->getText().find('f') != ANTLR_USE_NAMESPACE(std)string::npos ||
476 >                                                        t->getText().find('F') != ANTLR_USE_NAMESPACE(std)string::npos ) ) {
477 >                                                _ttype = NUM_FLOAT;
478 >                                        }
479 >                                        else {
480 >                                                _ttype = NUM_DOUBLE; // assume double
481 >                                        }
482 >                                }
483 >        )?
484    )
485 <  ;
485 >        ;
486  
487 < ID
488 <  options {testLiterals = true;}
489 <  :
490 <    ('a'..'z'|'A'..'Z'|'_')
491 <    ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
492 <  ;
487 > // a couple protected methods to assist in matching floating point numbers
488 > protected
489 > EXPONENT
490 >        :       ('e'|'E'|'d'|'D') ('+'|'-')? ('0'..'9')+
491 >        ;
492 >
493 > protected
494 > FLOAT_SUFFIX
495 >        :       'f'|'F'|'d'|'D'
496 >        ;

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 1746 by gezelter, Wed Jun 6 02:18:54 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines