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.
Revision 848 by gezelter, Wed Jan 11 23:06:08 2006 UTC

# Line 41 | Line 41 | tokens
41    ENDBLOCK;
42   }
43  
44 {
45    // Suppport C++-style single-line comments?
46 }
44  
45   mdfile  : (statement)*
46          ;
# Line 57 | Line 54 | assignment  : ID ASSIGNEQUAL^ constant SEMICOLON!
54   assignment  : ID ASSIGNEQUAL^ constant SEMICOLON!
55              ;
56              
57 < constant    : signedNumber
57 > constant    : intConst
58 >                                                | floatConst
59              | ID
60              | StringLiteral
61              ;
# Line 85 | Line 83 | atomstatement : assignment
83            ;
84  
85   atomstatement : assignment
86 <              | POSITION^ LPAREN! signedNumberTuple RPAREN! SEMICOLON!
87 <              | ORIENTATION^  LPAREN! signedNumberTuple RPAREN! SEMICOLON!
86 >              | POSITION^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
87 >              | ORIENTATION^  LPAREN! doubleNumberTuple RPAREN! SEMICOLON!
88                ;
89  
90                        
# Line 133 | Line 131 | fragmentstatement : assignment
131  
132  
133                
134 < signedNumberTuple   : signedNumber (COMMA! signedNumber)*
134 > doubleNumberTuple   : doubleNumber (COMMA! doubleNumber)*
135                ;
136                            
137   inttuple      : intConst (COMMA! intConst)*
# Line 141 | Line 139 | intConst
139                
140   protected
141   intConst
142 <        :  OCTALINT | DECIMALINT | HEXADECIMALINT
142 >        :  NUM_INT | NUM_LONG
143          ;
144  
145   protected
146 < signedNumber  : (PLUS! | MINUS^)?
146 > doubleNumber  :  
147                  (intConst | floatConst)
148                ;
149                
150   protected
151   floatConst
152          :
153 <          FLOATONE | FLOATTWO
153 >          NUM_FLOAT | NUM_DOUBLE
154          ;
155  
156  
# Line 209 | Line 207 | RCURLY          : '}' ;
207   LCURLY          : '{' ;
208   RCURLY          : '}' ;
209  
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
210   Whitespace  
211    :
212      ( // whitespace ignored
# Line 400 | Line 356 | Escape  
356      )
357    ;
358  
403 // Numeric Constants:
359  
360   protected
361 + Vocabulary
362 +  :
363 +    '\3'..'\377'
364 +  ;
365 +
366 +
367 + ID
368 +  options {testLiterals = true;}
369 +  :
370 +    ('a'..'z'|'A'..'Z'|'_')
371 +    ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
372 +  ;
373 +
374 +
375 + protected
376   Digit
377    :
378      '0'..'9'
# Line 414 | Line 384 | Decimal
384      ('0'..'9')+
385    ;
386  
387 + // hexadecimal digit (again, note it's protected!)
388   protected
389 < LongSuffix
390 <  : 'l'
391 <  | 'L'
421 <  ;
389 > HEX_DIGIT
390 >        :       ('0'..'9'|'A'..'F'|'a'..'f')
391 >        ;
392  
423 protected
424 UnsignedSuffix
425  : 'u'
426  | 'U'
427  ;
393  
394 < protected
395 < FloatSuffix
396 <  : 'f'
397 <  | 'F'
398 <  ;
394 > // a numeric literal
395 > NUM_INT
396 >        {
397 >                bool isDecimal = false;
398 >                ANTLR_USE_NAMESPACE(antlr)RefToken t = ANTLR_USE_NAMESPACE(antlr)nullToken;
399 >        }
400 >    : ('+' | '-')?
401 >    (
402 >      '.' {_ttype = DOT;}
403 >            (   ('0'..'9')+ (EXPONENT)? (f1:FLOAT_SUFFIX {t=f1;})?
404 >            {
405 >                                        if ( t &&
406 >                                                  (t->getText().find('f') != ANTLR_USE_NAMESPACE(std)string::npos ||
407 >                                                        t->getText().find('F') != ANTLR_USE_NAMESPACE(std)string::npos ) ) {
408 >                                                _ttype = NUM_FLOAT;
409 >                                        }
410 >                                        else {
411 >                                                _ttype = NUM_DOUBLE; // assume double
412 >                                        }
413 >                                }
414 >            )?
415  
416 < protected
417 < Exponent
418 <  :
419 <    ('e'|'E'|'d'|'D') ('+'|'-')? (Digit)+
420 <  ;
416 >        |       (       '0' {isDecimal = true;} // special case for just '0'
417 >                        (       ('x'|'X')
418 >                                (                                                                                       // hex
419 >                                        // the 'e'|'E' and float suffix stuff look
420 >                                        // like hex digits, hence the (...)+ doesn't
421 >                                        // know when to stop: ambig.  ANTLR resolves
422 >                                        // it correctly by matching immediately.  It
423 >                                        // is therefor ok to hush warning.
424 >                                        options {
425 >                                                warnWhenFollowAmbig=false;
426 >                                        }
427 >                                :       HEX_DIGIT
428 >                                )+
429 >                        |       //float or double with leading zero
430 >                                (('0'..'9')+ ('.'|EXPONENT|FLOAT_SUFFIX)) => ('0'..'9')+
431 >                        |       ('0'..'7')+                                                                     // octal
432 >                        )?
433 >                |       ('1'..'9') ('0'..'9')*  {isDecimal=true;}               // non-zero decimal
434 >                )
435 >                (       ('l'|'L') { _ttype = NUM_LONG; }
436  
437 +                // only check to see if it's a float if looks like decimal so far
438 +                |       {isDecimal}?
439 +            (   '.' ('0'..'9')* (EXPONENT)? (f2:FLOAT_SUFFIX {t=f2;})?
440 +            |   EXPONENT (f3:FLOAT_SUFFIX {t=f3;})?
441 +            |   f4:FLOAT_SUFFIX {t=f4;}
442 +            )
443 +            {
444 +                                        if ( t &&
445 +                                                  (t->getText().find('f') != ANTLR_USE_NAMESPACE(std)string::npos ||
446 +                                                        t->getText().find('F') != ANTLR_USE_NAMESPACE(std)string::npos ) ) {
447 +                                                _ttype = NUM_FLOAT;
448 +                                        }
449 +                                        else {
450 +                                                _ttype = NUM_DOUBLE; // assume double
451 +                                        }
452 +                                }
453 +        )?
454 +  )
455 +        ;
456 +
457 + // a couple protected methods to assist in matching floating point numbers
458   protected
459 < Vocabulary
460 <  :
461 <    '\3'..'\377'
445 <  ;
459 > EXPONENT
460 >        :       ('e'|'E'|'d'|'D') ('+'|'-')? ('0'..'9')+
461 >        ;
462  
463 < Number
464 <  :
465 <    ( (Digit)+ ('.' | 'e' | 'E' | 'd' | 'D' ) )=>
466 <    (Digit)+
451 <    ( '.' (Digit)* (Exponent)? {_ttype = FLOATONE;} //Zuo 3/12/01
452 <    | Exponent                 {_ttype = FLOATTWO;} //Zuo 3/12/01
453 <    )                          //{_ttype = DoubleDoubleConst;}
454 <    (FloatSuffix               //{_ttype = FloatDoubleConst;}
455 <    |LongSuffix                //{_ttype = LongDoubleConst;}
456 <    )?
457 <  |
458 <    '.'                        {_ttype = DOT;}
459 <    ( (Digit)+ (Exponent)?   {_ttype = FLOATONE;} //Zuo 3/12/01
460 <                                   //{_ttype = DoubleDoubleConst;}
461 <      (FloatSuffix           //{_ttype = FloatDoubleConst;}
462 <      |LongSuffix            //{_ttype = LongDoubleConst;}
463 <      )?
464 <    )?
465 <  |
466 <    '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 <  ;
482 <
483 < ID
484 <  options {testLiterals = true;}
485 <  :
486 <    ('a'..'z'|'A'..'Z'|'_')
487 <    ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
488 <  ;
463 > protected
464 > FLOAT_SUFFIX
465 >        :       'f'|'F'|'d'|'D'
466 >        ;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines