--- trunk/src/mdParser/MDParser.g 2005/12/14 18:02:28 810 +++ trunk/src/mdParser/MDParser.g 2014/04/05 20:56:01 1979 @@ -28,16 +28,25 @@ tokens COMPONENT = "component"; MOLECULE = "molecule"; ZCONSTRAINT = "zconstraint"; + RESTRAINT = "restraint"; ATOM = "atom"; BOND = "bond"; BEND = "bend"; TORSION = "torsion"; + INVERSION = "inversion"; RIGIDBODY = "rigidBody"; CUTOFFGROUP = "cutoffGroup"; + CONSTRAINT = "constraint"; + DISTANCE = "distance"; FRAGMENT = "fragment"; MEMBERS = "members"; + CENTER = "center"; + SATELLITES = "satellites"; POSITION = "position"; ORIENTATION = "orientation"; + FLUCQ = "flucQ"; + RNEMD = "RNEMD"; + MINIMIZER = "minimizer"; ENDBLOCK; } @@ -46,15 +55,21 @@ statement : assignment ; statement : assignment - | componentblock - | moleculeblock - | zconstraintblock - ; - + | componentblock + | moleculeblock + | zconstraintblock + | restraintblock + | flucqblock + | rnemdblock + | minimizerblock + ; + assignment : ID ASSIGNEQUAL^ constant SEMICOLON! ; -constant : signedNumber +constant : intConst + | floatConst + | vectorConst | ID | StringLiteral ; @@ -64,6 +79,18 @@ zconstraintblock : ZCONSTRAINT^ LCURLY! (assignment)* zconstraintblock : ZCONSTRAINT^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);} ; + +restraintblock : RESTRAINT^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);} + ; + +flucqblock : FLUCQ^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);} + ; + +rnemdblock : RNEMD^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);} + ; + +minimizerblock : MINIMIZER^ LCURLY! (assignment)* RCURLY {#RCURLY->setType(ENDBLOCK);} + ; moleculeblock : MOLECULE^ LCURLY! (moleculestatement)* RCURLY {#RCURLY->setType(ENDBLOCK);} ; @@ -73,17 +100,19 @@ moleculestatement : assignment | bondblock | bendblock | torsionblock + | inversionblock | rigidbodyblock | cutoffgroupblock | fragmentblock + | constraintblock ; atomblock : ATOM^ LBRACKET! intConst RBRACKET! LCURLY! (atomstatement)* RCURLY {#RCURLY->setType(ENDBLOCK);} ; atomstatement : assignment - | POSITION^ LPAREN! signedNumberTuple RPAREN! SEMICOLON! - | ORIENTATION^ LPAREN! signedNumberTuple RPAREN! SEMICOLON! + | POSITION^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON! + | ORIENTATION^ LPAREN! doubleNumberTuple RPAREN! SEMICOLON! ; @@ -108,6 +137,14 @@ torsionstatement : assignment | MEMBERS^ LPAREN! inttuple RPAREN! SEMICOLON! ; +inversionblock : INVERSION^ (LBRACKET! intConst! RBRACKET!)? LCURLY!(inversionstatement)* RCURLY {#RCURLY->setType(ENDBLOCK);} + ; + +inversionstatement : assignment + | CENTER^ LPAREN! intConst RPAREN! SEMICOLON! + | SATELLITES^ LPAREN! inttuple RPAREN! SEMICOLON! + ; + rigidbodyblock : RIGIDBODY^ LBRACKET! intConst RBRACKET! LCURLY!(rigidbodystatement)* RCURLY {#RCURLY->setType(ENDBLOCK);} ; @@ -128,9 +165,15 @@ fragmentstatement : assignment fragmentstatement : assignment ; +constraintblock : CONSTRAINT^ (LBRACKET! intConst! RBRACKET!)? LCURLY!(constraintstatement)* RCURLY {#RCURLY->setType(ENDBLOCK);} + ; +constraintstatement : assignment + | MEMBERS^ LPAREN! inttuple RPAREN! SEMICOLON! + ; + -signedNumberTuple : signedNumber (COMMA! signedNumber)* +doubleNumberTuple : doubleNumber (COMMA! doubleNumber)* ; inttuple : intConst (COMMA! intConst)* @@ -138,22 +181,26 @@ intConst protected intConst - : OCTALINT | DECIMALINT | HEXADECIMALINT + : NUM_INT | NUM_LONG ; protected -signedNumber : +doubleNumber : (intConst | floatConst) ; protected floatConst : - FLOATONE | FLOATTWO + NUM_FLOAT | NUM_DOUBLE ; +protected +vectorConst + : + LPAREN^ doubleNumber COMMA doubleNumber COMMA doubleNumber RPAREN + ; - class MDLexer extends Lexer; options @@ -206,46 +253,6 @@ RCURLY : '}' ; LCURLY : '{' ; RCURLY : '}' ; - -/* -EQUAL : "==" ; -NOTEQUAL : "!=" ; -LESSTHANOREQUALTO : "<=" ; -LESSTHAN : "<" ; -GREATERTHANOREQUALTO : ">=" ; -GREATERTHAN : ">" ; - -DIVIDE : '/' ; -DIVIDEEQUAL : "/=" ; -PLUS : '+' ; -PLUSEQUAL : "+=" ; -PLUSPLUS : "++" ; -MINUS : '-' ; -MINUSEQUAL : "-=" ; -MINUSMINUS : "--" ; -STAR : '*' ; -TIMESEQUAL : "*=" ; -MOD : '%' ; -MODEQUAL : "%=" ; -SHIFTRIGHT : ">>" ; -SHIFTRIGHTEQUAL : ">>=" ; -SHIFTLEFT : "<<" ; -SHIFTLEFTEQUAL : "<<=" ; - -AND : "&&" ; -NOT : '!' ; -OR : "||" ; - -AMPERSAND : '&' ; -BITWISEANDEQUAL : "&=" ; -TILDE : '~' ; -BITWISEOR : '|' ; -BITWISEOREQUAL : "|=" ; -BITWISEXOR : '^' ; -BITWISEXOREQUAL : "^=" ; -*/ - - Whitespace : ( // whitespace ignored @@ -296,7 +303,7 @@ LineDirective } ("line")? // this would be for if the directive started "#line" (Space)+ - n:Decimal { setLine(oopse::lexi_cast(n->getText()) - 1); } + n:Decimal { setLine(OpenMD::lexi_cast(n->getText()) - 1); } (Space)+ (sl:StringLiteral) {std::string filename = sl->getText().substr(1,sl->getText().length()-2); observer->notify(filename);} ((Space)+ Decimal)* // To support cpp flags (GNU) @@ -395,92 +402,111 @@ Escape ) ; -// Numeric Constants: protected -Digit +Vocabulary : - '0'..'9' + '\3'..'\377' ; -protected -Decimal + +ID + options {testLiterals = true;} : - ('0'..'9')+ + ('a'..'z'|'A'..'Z'|'_') + ('a'..'z'|'A'..'Z'|'_'|'0'..'9')* ; + protected -LongSuffix - : 'l' - | 'L' +Digit + : + '0'..'9' ; protected -UnsignedSuffix - : 'u' - | 'U' +Decimal + : + ('0'..'9')+ ; +// hexadecimal digit (again, note it's protected!) protected -FloatSuffix - : 'f' - | 'F' - ; +HEX_DIGIT + : ('0'..'9'|'A'..'F'|'a'..'f') + ; -protected -Exponent - : - ('e'|'E'|'d'|'D') ('+'|'-')? (Digit)+ - ; -protected -Vocabulary - : - '\3'..'\377' - ; +// a numeric literal +NUM_INT + { + bool isDecimal = false; + ANTLR_USE_NAMESPACE(antlr)RefToken t = ANTLR_USE_NAMESPACE(antlr)nullToken; + } + : ('+' | '-')? + ( + '.' {_ttype = DOT;} + ( ('0'..'9')+ (EXPONENT)? (f1:FLOAT_SUFFIX {t=f1;})? + { + if ( t && + (t->getText().find('f') != ANTLR_USE_NAMESPACE(std)string::npos || + t->getText().find('F') != ANTLR_USE_NAMESPACE(std)string::npos ) ) { + _ttype = NUM_FLOAT; + } + else { + _ttype = NUM_DOUBLE; // assume double + } + } + )? -Number - : - ('+'|'-')? - ( - ( (Digit)+ ('.' | 'e' | 'E' | 'd' | 'D' ) )=> - (Digit)+ - ( '.' (Digit)* (Exponent)? {_ttype = FLOATONE;} //Zuo 3/12/01 - | Exponent {_ttype = FLOATTWO;} //Zuo 3/12/01 - ) //{_ttype = DoubleDoubleConst;} - (FloatSuffix //{_ttype = FloatDoubleConst;} - |LongSuffix //{_ttype = LongDoubleConst;} - )? - | - '.' {_ttype = DOT;} - ( (Digit)+ (Exponent)? {_ttype = FLOATONE;} //Zuo 3/12/01 - //{_ttype = DoubleDoubleConst;} - (FloatSuffix //{_ttype = FloatDoubleConst;} - |LongSuffix //{_ttype = LongDoubleConst;} - )? - )? - | - '0' ('0'..'7')* //{_ttype = IntOctalConst;} - (LongSuffix //{_ttype = LongOctalConst;} - |UnsignedSuffix //{_ttype = UnsignedOctalConst;} - )* {_ttype = OCTALINT;} - | - '1'..'9' (Digit)* //{_ttype = IntIntConst;} - (LongSuffix //{_ttype = LongIntConst;} - |UnsignedSuffix //{_ttype = UnsignedIntConst;} - )* {_ttype = DECIMALINT;} - | - '0' ('x' | 'X') ('a'..'f' | 'A'..'F' | Digit)+ - //{_ttype = IntHexConst;} - (LongSuffix //{_ttype = LongHexConst;} - |UnsignedSuffix //{_ttype = UnsignedHexConst;} - )* {_ttype = HEXADECIMALINT;} + | ( '0' {isDecimal = true;} // special case for just '0' + ( ('x'|'X') + ( // hex + // the 'e'|'E' and float suffix stuff look + // like hex digits, hence the (...)+ doesn't + // know when to stop: ambig. ANTLR resolves + // it correctly by matching immediately. It + // is therefor ok to hush warning. + options { + warnWhenFollowAmbig=false; + } + : HEX_DIGIT + )+ + | //float or double with leading zero + (('0'..'9')+ ('.'|EXPONENT|FLOAT_SUFFIX)) => ('0'..'9')+ + | ('0'..'7')+ // octal + )? + | ('1'..'9') ('0'..'9')* {isDecimal=true;} // non-zero decimal + ) + ( ('l'|'L') { _ttype = NUM_LONG; } + + // only check to see if it's a float if looks like decimal so far + | {isDecimal}? + ( '.' ('0'..'9')* (EXPONENT)? (f2:FLOAT_SUFFIX {t=f2;})? + | EXPONENT (f3:FLOAT_SUFFIX {t=f3;})? + | f4:FLOAT_SUFFIX {t=f4;} + ) + { + if ( t && + (t->getText().find('f') != ANTLR_USE_NAMESPACE(std)string::npos || + t->getText().find('F') != ANTLR_USE_NAMESPACE(std)string::npos ) ) { + _ttype = NUM_FLOAT; + } + else { + _ttype = NUM_DOUBLE; // assume double + } + } + )? ) - ; + ; -ID - options {testLiterals = true;} - : - ('a'..'z'|'A'..'Z'|'_') - ('a'..'z'|'A'..'Z'|'_'|'0'..'9')* - ; +// a couple protected methods to assist in matching floating point numbers +protected +EXPONENT + : ('e'|'E'|'d'|'D') ('+'|'-')? ('0'..'9')+ + ; + +protected +FLOAT_SUFFIX + : 'f'|'F'|'d'|'D' + ;