ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/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.
Revision 1902 by gezelter, Tue Jul 16 17:16:45 2013 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 +  SATELLITES  = "satellites";
43    POSITION    = "position";
44    ORIENTATION = "orientation";
45 +  FLUCQ       = "flucQ";
46 +  RNEMD       = "RNEMD";
47 +  MINIMIZER   = "minimizer";
48    ENDBLOCK;
49   }
50  
44 {
45    // Suppport C++-style single-line comments?
46 }
51  
52   mdfile  : (statement)*
53          ;
54  
55   statement : assignment
56 <          | componentblock
57 <          | moleculeblock
58 <          | zconstraintblock
59 <          ;
60 <            
56 >    | componentblock
57 >    | moleculeblock
58 >    | zconstraintblock
59 >    | restraintblock
60 >    | flucqblock
61 >    | rnemdblock
62 >    | minimizerblock
63 >    ;
64 >
65   assignment  : ID ASSIGNEQUAL^ constant SEMICOLON!
66              ;
67              
68 < constant    : signedNumber
68 > constant    : intConst
69 >                        | floatConst
70 >            | vectorConst
71              | ID
72              | StringLiteral
73              ;
# Line 67 | Line 77 | zconstraintblock  : ZCONSTRAINT^ LCURLY! (assignment)*
77      
78   zconstraintblock  : ZCONSTRAINT^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
79                    ;
80 +
81 + restraintblock  : RESTRAINT^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
82 +                  ;
83 +
84 + flucqblock  : FLUCQ^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
85 +    ;
86 +
87 + rnemdblock  : RNEMD^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
88 +    ;
89 +
90 + minimizerblock  : MINIMIZER^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);}
91 +    ;
92    
93   moleculeblock : MOLECULE^ LCURLY! (moleculestatement)*  RCURLY {#RCURLY->setType(ENDBLOCK);}
94                ;
# Line 76 | Line 98 | moleculestatement : assignment
98                    | bondblock
99                    | bendblock
100                    | torsionblock
101 +                  | inversionblock
102                    | rigidbodyblock
103                    | cutoffgroupblock
104                    | fragmentblock
# Line 85 | Line 108 | atomstatement : assignment
108            ;
109  
110   atomstatement : assignment
111 <              | POSITION^ LPAREN! signedNumberTuple RPAREN! SEMICOLON!
112 <              | ORIENTATION^  LPAREN! signedNumberTuple RPAREN! SEMICOLON!
111 >              | POSITION^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
112 >              | ORIENTATION^  LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
113                ;
114  
115                        
# Line 111 | Line 134 | torsionstatement  : assignment
134                | MEMBERS^ LPAREN! inttuple RPAREN! SEMICOLON!
135                ;
136  
137 + inversionblock  : INVERSION^ (LBRACKET! intConst! RBRACKET!)?  LCURLY!(inversionstatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
138 +          ;
139 +
140 + inversionstatement  : assignment
141 +              | CENTER^ LPAREN! intConst RPAREN! SEMICOLON!
142 +              | SATELLITES^ LPAREN! inttuple RPAREN! SEMICOLON!
143 +              ;
144 +
145   rigidbodyblock  : RIGIDBODY^  LBRACKET! intConst RBRACKET! LCURLY!(rigidbodystatement)* RCURLY {#RCURLY->setType(ENDBLOCK);}
146                  ;
147  
# Line 133 | Line 164 | fragmentstatement : assignment
164  
165  
166                
167 < signedNumberTuple   : signedNumber (COMMA! signedNumber)*
167 > doubleNumberTuple   : doubleNumber (COMMA! doubleNumber)*
168                ;
169                            
170   inttuple      : intConst (COMMA! intConst)*
# Line 141 | Line 172 | intConst
172                
173   protected
174   intConst
175 <        :  OCTALINT | DECIMALINT | HEXADECIMALINT
175 >        :  NUM_INT | NUM_LONG
176          ;
177  
178   protected
179 < signedNumber  : (PLUS! | MINUS^)?
179 > doubleNumber  :  
180                  (intConst | floatConst)
181                ;
182                
183   protected
184   floatConst
185          :
186 <          FLOATONE | FLOATTWO
186 >          NUM_FLOAT | NUM_DOUBLE
187          ;
188  
189 + protected
190 + vectorConst
191 +    :
192 +        LPAREN^ doubleNumber COMMA doubleNumber COMMA doubleNumber RPAREN
193 +    ;
194  
159
195   class MDLexer extends Lexer;
196  
197   options
# Line 209 | Line 244 | RCURLY          : '}' ;
244   LCURLY          : '{' ;
245   RCURLY          : '}' ;
246  
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
247   Whitespace  
248    :
249      ( // whitespace ignored
# Line 301 | Line 294 | LineDirective
294    }
295      ("line")?  // this would be for if the directive started "#line"
296      (Space)+
297 <    n:Decimal { setLine(oopse::lexi_cast<int>(n->getText()) - 1); }
297 >    n:Decimal { setLine(OpenMD::lexi_cast<int>(n->getText()) - 1); }
298      (Space)+
299      (sl:StringLiteral) {std::string filename = sl->getText().substr(1,sl->getText().length()-2); observer->notify(filename);}
300      ((Space)+ Decimal)* // To support cpp flags (GNU)
# Line 400 | Line 393 | Escape  
393      )
394    ;
395  
403 // Numeric Constants:
396  
397   protected
398 < Digit
398 > Vocabulary
399    :
400 <    '0'..'9'
400 >    '\3'..'\377'
401    ;
402  
403 < protected
404 < Decimal
403 >
404 > ID
405 >  options {testLiterals = true;}
406    :
407 <    ('0'..'9')+
407 >    ('a'..'z'|'A'..'Z'|'_')
408 >    ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
409    ;
410  
411 +
412   protected
413 < LongSuffix
414 <  : 'l'
415 <  | 'L'
413 > Digit
414 >  :
415 >    '0'..'9'
416    ;
417  
418   protected
419 < UnsignedSuffix
420 <  : 'u'
421 <  | 'U'
419 > Decimal
420 >  :
421 >    ('0'..'9')+
422    ;
423  
424 + // hexadecimal digit (again, note it's protected!)
425   protected
426 < FloatSuffix
427 <  : 'f'
428 <  | 'F'
433 <  ;
426 > HEX_DIGIT
427 >        :       ('0'..'9'|'A'..'F'|'a'..'f')
428 >        ;
429  
435 protected
436 Exponent
437  :
438    ('e'|'E'|'d'|'D') ('+'|'-')? (Digit)+
439  ;
430  
431 < protected
432 < Vocabulary
433 <  :
434 <    '\3'..'\377'
435 <  ;
431 > // a numeric literal
432 > NUM_INT
433 >        {
434 >                bool isDecimal = false;
435 >                ANTLR_USE_NAMESPACE(antlr)RefToken t = ANTLR_USE_NAMESPACE(antlr)nullToken;
436 >        }
437 >    : ('+' | '-')?
438 >    (
439 >      '.' {_ttype = DOT;}
440 >            (   ('0'..'9')+ (EXPONENT)? (f1:FLOAT_SUFFIX {t=f1;})?
441 >            {
442 >                                        if ( t &&
443 >                                                  (t->getText().find('f') != ANTLR_USE_NAMESPACE(std)string::npos ||
444 >                                                        t->getText().find('F') != ANTLR_USE_NAMESPACE(std)string::npos ) ) {
445 >                                                _ttype = NUM_FLOAT;
446 >                                        }
447 >                                        else {
448 >                                                _ttype = NUM_DOUBLE; // assume double
449 >                                        }
450 >                                }
451 >            )?
452  
453 < Number
454 <  :
455 <    ( (Digit)+ ('.' | 'e' | 'E' | 'd' | 'D' ) )=>
456 <    (Digit)+
457 <    ( '.' (Digit)* (Exponent)? {_ttype = FLOATONE;} //Zuo 3/12/01
458 <    | Exponent                 {_ttype = FLOATTWO;} //Zuo 3/12/01
459 <    )                          //{_ttype = DoubleDoubleConst;}
460 <    (FloatSuffix               //{_ttype = FloatDoubleConst;}
461 <    |LongSuffix                //{_ttype = LongDoubleConst;}
462 <    )?
463 <  |
464 <    '.'                        {_ttype = DOT;}
465 <    ( (Digit)+ (Exponent)?   {_ttype = FLOATONE;} //Zuo 3/12/01
466 <                                   //{_ttype = DoubleDoubleConst;}
467 <      (FloatSuffix           //{_ttype = FloatDoubleConst;}
468 <      |LongSuffix            //{_ttype = LongDoubleConst;}
469 <      )?
470 <    )?
471 <  |
472 <    '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 <  ;
453 >        |       (       '0' {isDecimal = true;} // special case for just '0'
454 >                        (       ('x'|'X')
455 >                                (                                                                                       // hex
456 >                                        // the 'e'|'E' and float suffix stuff look
457 >                                        // like hex digits, hence the (...)+ doesn't
458 >                                        // know when to stop: ambig.  ANTLR resolves
459 >                                        // it correctly by matching immediately.  It
460 >                                        // is therefor ok to hush warning.
461 >                                        options {
462 >                                                warnWhenFollowAmbig=false;
463 >                                        }
464 >                                :       HEX_DIGIT
465 >                                )+
466 >                        |       //float or double with leading zero
467 >                                (('0'..'9')+ ('.'|EXPONENT|FLOAT_SUFFIX)) => ('0'..'9')+
468 >                        |       ('0'..'7')+                                                                     // octal
469 >                        )?
470 >                |       ('1'..'9') ('0'..'9')*  {isDecimal=true;}               // non-zero decimal
471 >                )
472 >                (       ('l'|'L') { _ttype = NUM_LONG; }
473  
474 < ID
475 <  options {testLiterals = true;}
476 <  :
477 <    ('a'..'z'|'A'..'Z'|'_')
478 <    ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
479 <  ;
474 >                // only check to see if it's a float if looks like decimal so far
475 >                |       {isDecimal}?
476 >            (   '.' ('0'..'9')* (EXPONENT)? (f2:FLOAT_SUFFIX {t=f2;})?
477 >            |   EXPONENT (f3:FLOAT_SUFFIX {t=f3;})?
478 >            |   f4:FLOAT_SUFFIX {t=f4;}
479 >            )
480 >            {
481 >                                        if ( t &&
482 >                                                  (t->getText().find('f') != ANTLR_USE_NAMESPACE(std)string::npos ||
483 >                                                        t->getText().find('F') != ANTLR_USE_NAMESPACE(std)string::npos ) ) {
484 >                                                _ttype = NUM_FLOAT;
485 >                                        }
486 >                                        else {
487 >                                                _ttype = NUM_DOUBLE; // assume double
488 >                                        }
489 >                                }
490 >        )?
491 >  )
492 >        ;
493 >
494 > // a couple protected methods to assist in matching floating point numbers
495 > protected
496 > EXPONENT
497 >        :       ('e'|'E'|'d'|'D') ('+'|'-')? ('0'..'9')+
498 >        ;
499 >
500 > protected
501 > FLOAT_SUFFIX
502 >        :       'f'|'F'|'d'|'D'
503 >        ;

Comparing trunk/src/mdParser/MDParser.g (property svn:keywords):
Revision 770 by tim, Fri Dec 2 15:38:03 2005 UTC vs.
Revision 1902 by gezelter, Tue Jul 16 17:16:45 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines