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

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 1776 by gezelter, Thu Aug 9 15:52:59 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines