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 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  
44 {
45    // Suppport C++-style single-line comments?
46 }
50  
51   mdfile  : (statement)*
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 67 | 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 76 | Line 96 | moleculestatement : assignment
96                    | bondblock
97                    | bendblock
98                    | torsionblock
99 +                  | inversionblock
100                    | rigidbodyblock
101                    | cutoffgroupblock
102                    | fragmentblock
# Line 85 | 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 111 | 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 133 | 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 141 | Line 169 | intConst
169                
170   protected
171   intConst
172 <        :  OCTALINT | DECIMALINT | HEXADECIMALINT
172 >        :  NUM_INT | NUM_LONG
173          ;
174  
175   protected
176 < signedNumber  : (PLUS! | MINUS^)?
176 > doubleNumber  :  
177                  (intConst | floatConst)
178                ;
179                
180   protected
181   floatConst
182          :
183 <          FLOATONE | FLOATTWO
183 >          NUM_FLOAT | NUM_DOUBLE
184          ;
185  
186  
# Line 209 | Line 237 | RCURLY          : '}' ;
237   LCURLY          : '{' ;
238   RCURLY          : '}' ;
239  
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
240   Whitespace  
241    :
242      ( // whitespace ignored
# Line 301 | 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 400 | Line 386 | Escape  
386      )
387    ;
388  
403 // Numeric Constants:
389  
390   protected
391 < Digit
391 > Vocabulary
392    :
393 <    '0'..'9'
393 >    '\3'..'\377'
394    ;
395  
396 < protected
397 < Decimal
396 >
397 > ID
398 >  options {testLiterals = true;}
399    :
400 <    ('0'..'9')+
400 >    ('a'..'z'|'A'..'Z'|'_')
401 >    ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
402    ;
403  
404 +
405   protected
406 < LongSuffix
407 <  : 'l'
408 <  | 'L'
406 > Digit
407 >  :
408 >    '0'..'9'
409    ;
410  
411   protected
412 < UnsignedSuffix
413 <  : 'u'
414 <  | 'U'
412 > Decimal
413 >  :
414 >    ('0'..'9')+
415    ;
416  
417 + // hexadecimal digit (again, note it's protected!)
418   protected
419 < FloatSuffix
420 <  : 'f'
421 <  | 'F'
433 <  ;
419 > HEX_DIGIT
420 >        :       ('0'..'9'|'A'..'F'|'a'..'f')
421 >        ;
422  
435 protected
436 Exponent
437  :
438    ('e'|'E'|'d'|'D') ('+'|'-')? (Digit)+
439  ;
423  
424 < protected
425 < Vocabulary
426 <  :
427 <    '\3'..'\377'
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 < Number
447 <  :
448 <    ( (Digit)+ ('.' | 'e' | 'E' | 'd' | 'D' ) )=>
449 <    (Digit)+
450 <    ( '.' (Digit)* (Exponent)? {_ttype = FLOATONE;} //Zuo 3/12/01
451 <    | Exponent                 {_ttype = FLOATTWO;} //Zuo 3/12/01
452 <    )                          //{_ttype = DoubleDoubleConst;}
453 <    (FloatSuffix               //{_ttype = FloatDoubleConst;}
454 <    |LongSuffix                //{_ttype = LongDoubleConst;}
455 <    )?
456 <  |
457 <    '.'                        {_ttype = DOT;}
458 <    ( (Digit)+ (Exponent)?   {_ttype = FLOATONE;} //Zuo 3/12/01
459 <                                   //{_ttype = DoubleDoubleConst;}
460 <      (FloatSuffix           //{_ttype = FloatDoubleConst;}
461 <      |LongSuffix            //{_ttype = LongDoubleConst;}
462 <      )?
463 <    )?
464 <  |
465 <    '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 <  ;
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 < ID
468 <  options {testLiterals = true;}
469 <  :
470 <    ('a'..'z'|'A'..'Z'|'_')
471 <    ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
472 <  ;
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 >        ;
486 >
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 770 by tim, Fri Dec 2 15:38:03 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