GME
13
|
00001 //############################################################################################################################################### 00002 // 00003 // Object Constraint Language Generic Manager 00004 // OCLParserStatic.cpp 00005 // 00006 //############################################################################################################################################### 00007 #include "Solve4786.h" 00008 #include "OCLParserStatic.h" 00009 00010 bool bTokenSetInitialized = false; 00011 00012 TokenSet First_name = TokenSet(); 00013 TokenSet First_typeName = TokenSet(); 00014 TokenSet First_colon = TokenSet(); 00015 TokenSet First_inputend = TokenSet(); 00016 TokenSet First_inv = TokenSet(); 00017 TokenSet First_right_parenthesis = TokenSet(); 00018 TokenSet First_left_parenthesis = TokenSet(); 00019 TokenSet First_prePost = TokenSet(); 00020 TokenSet First_in = TokenSet(); 00021 TokenSet First_equal = TokenSet(); 00022 TokenSet First_then = TokenSet(); 00023 TokenSet First_else = TokenSet(); 00024 TokenSet First_endif = TokenSet(); 00025 TokenSet First_delimiter = TokenSet(); 00026 TokenSet First_right_bracket = TokenSet(); 00027 TokenSet First_left_brace = TokenSet(); 00028 TokenSet First_right_brace = TokenSet(); 00029 TokenSet First_literal = TokenSet(); 00030 TokenSet First_expressionListOrRange = TokenSet(); 00031 TokenSet First_actualParameterList = TokenSet(); 00032 TokenSet First_primaryExpression = TokenSet(); 00033 TokenSet First_contextDeclarationHelper = TokenSet(); 00034 TokenSet First_formalParameterList = TokenSet(); 00035 TokenSet First_formalParameter = TokenSet(); 00036 TokenSet First_letExpression = TokenSet(); 00037 TokenSet First_featureCallParametersHelper = TokenSet(); 00038 TokenSet First_featureCallParameters = TokenSet(); 00039 TokenSet First_featureCall = TokenSet(); 00040 TokenSet First_unaryExpression = TokenSet(); 00041 TokenSet First_postfixExpression = TokenSet(); 00042 TokenSet First_implicationExpression = TokenSet(); 00043 TokenSet First_orExpression = TokenSet(); 00044 TokenSet First_xorExpression = TokenSet(); 00045 TokenSet First_andExpression = TokenSet(); 00046 TokenSet First_relationalExpression = TokenSet(); 00047 TokenSet First_additiveExpression = TokenSet(); 00048 TokenSet First_multiplicativeExpression = TokenSet(); 00049 TokenSet First_expression = TokenSet(); 00050 TokenSet First_qualifiers = TokenSet(); 00051 00052 TokenSet Last_primaryExpression = TokenSet(); 00053 TokenSet Last_featureCall = TokenSet(); 00054 TokenSet Last_featureCallParametersHelper = TokenSet(); 00055 TokenSet Last_literal = TokenSet(); 00056 TokenSet Last_expression = TokenSet(); 00057 TokenSet Last_implicationExpression = TokenSet(); 00058 TokenSet Last_contextDeclarationHelper = TokenSet(); 00059 00060 void InitializeTokenSets() 00061 { 00062 if ( ! bTokenSetInitialized ) { 00063 First_name.insert( IDENTIFIER ); 00064 00065 First_typeName.insert( IDENTIFIER ); 00066 00067 First_colon.insert( COLON ); 00068 00069 First_inputend.insert( INPUTEND ); 00070 00071 First_inv.insert( INV ); 00072 00073 First_right_parenthesis.insert( RIGHT_PARENTHESIS ); 00074 00075 First_left_parenthesis.insert( LEFT_PARENTHESIS ); 00076 00077 First_prePost.insert( CLASS_PREPOST ); 00078 00079 First_in.insert( INN ); 00080 00081 First_equal.insert( EQUAL ); 00082 00083 First_then.insert( THEN ); 00084 00085 First_else.insert( ELSE ); 00086 00087 First_endif.insert( ENDIF ); 00088 00089 First_delimiter.insert( DELIMITER ); 00090 00091 First_right_bracket.insert( RIGHT_BRACKET ); 00092 00093 First_left_brace.insert( LEFT_BRACE ); 00094 00095 First_right_brace.insert( RIGHT_BRACE ); 00096 00097 First_literal.insert( STRING ); 00098 First_literal.insert( REAL ); 00099 First_literal.insert( INTEGER ); 00100 First_literal.insert( POUND ); 00101 First_literal.insert( CLASS_BOOLEAN ); 00102 00103 First_primaryExpression = First_literal; 00104 First_primaryExpression .insert( IDENTIFIER ); 00105 First_primaryExpression .insert( LEFT_PARENTHESIS ); 00106 First_primaryExpression .insert( IF ); 00107 00108 First_contextDeclarationHelper.insert( IDENTIFIER ); 00109 00110 First_formalParameter.insert( IDENTIFIER ); 00111 00112 First_formalParameterList = First_formalParameter; 00113 00114 First_featureCallParameters.insert( LEFT_PARENTHESIS ); 00115 00116 First_featureCall.insert( IDENTIFIER ); 00117 00118 First_postfixExpression = Union( First_primaryExpression, First_featureCall ); 00119 00120 First_unaryExpression = First_postfixExpression; 00121 First_unaryExpression.insert( CLASS_UNARY ); 00122 00123 First_multiplicativeExpression = First_unaryExpression; 00124 00125 First_additiveExpression = First_multiplicativeExpression; 00126 00127 First_relationalExpression = First_additiveExpression; 00128 00129 First_andExpression = First_relationalExpression; 00130 00131 First_xorExpression = First_andExpression; 00132 00133 First_orExpression = First_xorExpression; 00134 00135 First_implicationExpression = First_orExpression; 00136 00137 First_letExpression.insert( LET ); 00138 00139 First_expression = Union( First_letExpression, First_implicationExpression ); 00140 00141 First_featureCallParametersHelper = First_expression; 00142 First_featureCallParametersHelper.insert( IDENTIFIER ); 00143 First_featureCallParametersHelper.insert( RIGHT_PARENTHESIS ); 00144 00145 First_actualParameterList = First_expression; 00146 00147 First_expressionListOrRange = First_expression; 00148 00149 First_qualifiers.insert( LEFT_BRACKET ); 00150 00151 bTokenSetInitialized = true; 00152 00153 Last_contextDeclarationHelper.insert( CLASS_STEREOTYPES ); 00154 00155 Last_literal.insert( STRING ); 00156 Last_literal.insert( REAL ); 00157 Last_literal.insert( INTEGER ); 00158 Last_literal.insert( IDENTIFIER ); 00159 Last_literal.insert( CLASS_BOOLEAN ); 00160 00161 Last_primaryExpression = Last_literal; 00162 Last_primaryExpression.insert( RIGHT_BRACE ); 00163 Last_primaryExpression.insert( RIGHT_PARENTHESIS ); 00164 Last_primaryExpression.insert( ENDIF ); 00165 00166 Last_featureCall.insert( IDENTIFIER ); 00167 Last_featureCall.insert( RIGHT_PARENTHESIS ); 00168 00169 Last_implicationExpression = Union( Last_primaryExpression, Last_featureCall ); 00170 00171 Last_expression = Last_implicationExpression; 00172 00173 Last_featureCallParametersHelper = Last_expression; 00174 } 00175 } 00176 00177 TokenSet Union( const TokenSet& setTokens1, const TokenSet& setTokens2 ) 00178 { 00179 TokenSet setResult( setTokens1 ); 00180 for ( TokenSet::const_iterator i = setTokens2.begin() ; i != setTokens2.end() ; ++i ) 00181 setResult.insert( *i ); 00182 return setResult; 00183 } 00184 00185 TokenSet Union( const TokenSet& setTokens, int iToken ) 00186 { 00187 TokenSet setResult( setTokens ); 00188 setResult.insert( iToken ); 00189 return setResult; 00190 } 00191 00192 std::string PrintToken( int iToken, bool bQuote ) 00193 { 00194 std::string strToken; 00195 switch ( iToken ) { 00196 case ARROWW : strToken = "->"; break; 00197 case DOUBLECOLON : strToken = "::"; break; 00198 case COLON : strToken = ":"; break; 00199 case SEMICOLON : strToken = ";"; break; 00200 case LEFT_BRACE : strToken = "{"; break; 00201 case RIGHT_BRACE : strToken = "}"; break; 00202 case LEFT_PARENTHESIS : strToken = "("; break; 00203 case RIGHT_PARENTHESIS : strToken = ")"; break; 00204 case LEFT_BRACKET : strToken = "["; break; 00205 case RIGHT_BRACKET : strToken = "]"; break; 00206 case POUND : strToken = "#"; break; 00207 case COMMA : strToken = ","; break; 00208 case DELIMITER : strToken = "|"; break; 00209 case ET : strToken = "@"; break; 00210 case MULTIPLE : strToken = "*"; break; 00211 case DIVIDE : strToken = "/"; break; 00212 case DIVIDEINT : strToken = "div"; break; 00213 case MODULO : strToken = "mod"; break; 00214 case PLUS : strToken = "+"; break; 00215 case MINUS : strToken = "-"; break; 00216 case DOT : strToken = "."; break; 00217 case PERCENT : strToken = "%"; break; 00218 case EXCLAMATION : strToken = "!"; break; 00219 case EQUAL : strToken = "="; break; 00220 case NONEQUAL : strToken = "!="; break; 00221 case DOUBLEEQUAL : strToken = "=="; break; 00222 case LESS : strToken = "<"; break; 00223 case LESSEQUAL : strToken = "<="; break; 00224 case LESSGREATER : strToken = "<>"; break; 00225 case GREATEREQUAL : strToken = ">="; break; 00226 case GREATER : strToken = ">"; break; 00227 case SC_AND : strToken = "&&"; break; 00228 case SC_OR : strToken = "||"; break; 00229 case SC_IMPLIES : strToken = "=>"; break; 00230 00231 case CONTEXTT : strToken = "context"; break; 00232 case INV : strToken = "inv"; break; 00233 case PRE : strToken = "pre"; break; 00234 case POST : strToken = "post"; break; 00235 case DEFATTRIBUTE : strToken = "defattribute"; break; 00236 case DEFMETHOD : strToken = "defattribute"; break; 00237 case IF : strToken = "if"; break; 00238 case THEN : strToken = "then"; break; 00239 case ELSE : strToken = "else"; break; 00240 case ENDIF : strToken = "endif"; break; 00241 case LET : strToken = "let"; break; 00242 case INN : strToken = "in"; break; 00243 case AND : strToken = "and"; break; 00244 case OR : strToken = "or"; break; 00245 case XOR : strToken = "xor"; break; 00246 case NOT : strToken = "not"; break; 00247 case IMPLIES : strToken = "implies"; break; 00248 case TRUEE : strToken = "true"; break; 00249 case FALSEE : strToken = "false"; break; 00250 case UNDEFINED : strToken = "undefined"; break; 00251 case NULLL : strToken = "null"; break; 00252 00253 case STRING : strToken = "String"; break; 00254 case IDENTIFIER : strToken = "Identifier"; break; 00255 case INTEGER : strToken = "Integer"; break; 00256 case REAL : strToken = "Real"; break; 00257 00258 case INPUTEND : strToken = "InputEnd"; break; 00259 00260 case CLASS_MULTIPLICATIVE : strToken = "MultiplicativeOperator"; break; 00261 case CLASS_ADDITIVE : strToken = "AdditiveOperator"; break; 00262 case CLASS_RELATIONAL : strToken = "RelationalOperator"; break; 00263 case CLASS_LOGICAL : strToken = "LogicalOperator"; break; 00264 case CLASS_UNARY : strToken = "UnaryOperator"; break; 00265 case CLASS_PREPOST : strToken = "pre post def"; break; 00266 case CLASS_STEREOTYPES : strToken = "inv pre post def"; break; 00267 case CLASS_BOOLEAN : strToken = "Boolean"; break; 00268 case CLASS_CALLKIND : strToken = ". ->"; break; 00269 case CLASS_LOGICAL_AND : strToken = "and &&"; break; 00270 case CLASS_LOGICAL_OR : strToken = "or ||"; break; 00271 case CLASS_LOGICAL_IMPLIES : strToken = "implies =>"; break; 00272 00273 default : strToken = "UNKNOWN"; 00274 } 00275 00276 if ( bQuote ) { 00277 switch ( iToken ) { 00278 case INPUTEND : 00279 case IDENTIFIER : 00280 case INTEGER : 00281 case REAL : 00282 case STRING : 00283 case CLASS_MULTIPLICATIVE : 00284 case CLASS_ADDITIVE : 00285 case CLASS_RELATIONAL : 00286 case CLASS_UNARY : 00287 case CLASS_LOGICAL : 00288 case CLASS_BOOLEAN : break; 00289 case CLASS_PREPOST : strToken = "\"pre\" \"post\" \"defattribute\" \"defmethod\""; break; 00290 case CLASS_STEREOTYPES : strToken = "\"inv\" \"pre\" \"post\" \"defattribute\" \"defmethod\""; break; 00291 case CLASS_CALLKIND : strToken = "\".\" \"->\""; break; 00292 case CLASS_LOGICAL_AND : strToken = "\"and\" \"&&\""; break; 00293 case CLASS_LOGICAL_OR : strToken = "\"or\" \"||\""; break; 00294 case CLASS_LOGICAL_IMPLIES : strToken = "\"implies\" \"=>\""; break; 00295 00296 default : strToken = "\"" + strToken; strToken += "\""; break; 00297 } 00298 } 00299 return strToken; 00300 } 00301 00302 std::string PrintTokens( const TokenSet& setTokens ) 00303 { 00304 std::string strTokens( " " ); 00305 for ( TokenSet::const_iterator i = setTokens.begin() ; i != setTokens.end() ; ++i ) 00306 strTokens += PrintToken( *i, true ) + " "; 00307 return strTokens; 00308 } 00309 00310 bool Contains( const TokenSet& setTokens, int iToken ) 00311 { 00312 if ( setTokens.empty() ) 00313 return false; 00314 switch ( iToken ) { 00315 case MULTIPLE : case DIVIDE : case DIVIDEINT : case PERCENT : case MODULO : 00316 { 00317 TokenSet::const_iterator i = setTokens.find( CLASS_MULTIPLICATIVE ); 00318 if ( i != setTokens.end() ) 00319 return true; 00320 break; 00321 } 00322 case NOT : 00323 { 00324 TokenSet::const_iterator i = setTokens.find( CLASS_UNARY ); 00325 if ( i != setTokens.end() ) 00326 return true; 00327 break; 00328 } 00329 case MINUS : 00330 { 00331 TokenSet::const_iterator i = setTokens.find( CLASS_UNARY ); 00332 if ( i != setTokens.end() ) 00333 return true; 00334 i = setTokens.find( CLASS_ADDITIVE ); 00335 if ( i != setTokens.end() ) 00336 return true; 00337 break; 00338 } 00339 case PLUS : 00340 { 00341 TokenSet::const_iterator i = setTokens.find( CLASS_ADDITIVE ); 00342 if ( i != setTokens.end() ) 00343 return true; 00344 break; 00345 } 00346 case LESS : case LESSEQUAL : case LESSGREATER : case EQUAL : case DOUBLEEQUAL : case NONEQUAL : case GREATER : case GREATEREQUAL : 00347 { 00348 TokenSet::const_iterator i = setTokens.find( CLASS_RELATIONAL ); 00349 if ( i != setTokens.end() ) 00350 return true; 00351 break; 00352 } 00353 case XOR : 00354 { 00355 TokenSet::const_iterator i = setTokens.find( CLASS_LOGICAL ); 00356 if ( i != setTokens.end() ) 00357 return true; 00358 break; 00359 } 00360 case AND : case SC_AND : 00361 { 00362 TokenSet::const_iterator i = setTokens.find( CLASS_LOGICAL_AND ); 00363 if ( i != setTokens.end() ) 00364 return true; 00365 i = setTokens.find( CLASS_LOGICAL ); 00366 if ( i != setTokens.end() ) 00367 return true; 00368 break; 00369 } 00370 case OR : case SC_OR : 00371 { 00372 TokenSet::const_iterator i = setTokens.find( CLASS_LOGICAL_OR ); 00373 if ( i != setTokens.end() ) 00374 return true; 00375 i = setTokens.find( CLASS_LOGICAL ); 00376 if ( i != setTokens.end() ) 00377 return true; 00378 break; 00379 } 00380 case IMPLIES : case SC_IMPLIES : 00381 { 00382 TokenSet::const_iterator i = setTokens.find( CLASS_LOGICAL_IMPLIES ); 00383 if ( i != setTokens.end() ) 00384 return true; 00385 i = setTokens.find( CLASS_LOGICAL ); 00386 if ( i != setTokens.end() ) 00387 return true; 00388 break; 00389 } 00390 case TRUEE: case FALSEE : 00391 { 00392 TokenSet::const_iterator i = setTokens.find( CLASS_BOOLEAN ); 00393 if ( i != setTokens.end() ) 00394 return true; 00395 break; 00396 } 00397 case DOT : case ARROWW : 00398 { 00399 TokenSet::const_iterator i = setTokens.find( CLASS_CALLKIND ); 00400 if ( i != setTokens.end() ) 00401 return true; 00402 break; 00403 } 00404 case PRE : case POST : case DEFATTRIBUTE : case DEFMETHOD : 00405 { 00406 TokenSet::const_iterator i = setTokens.find( CLASS_PREPOST ); 00407 if ( i != setTokens.end() ) 00408 return true; 00409 } 00410 case INV : 00411 { 00412 TokenSet::const_iterator i = setTokens.find( CLASS_STEREOTYPES ); 00413 if ( i != setTokens.end() ) 00414 return true; 00415 break; 00416 } 00417 } 00418 TokenSet::const_iterator i = setTokens.find( iToken ); 00419 return i != setTokens.end(); 00420 } 00421 00422 bool Contains( const TokenSet& setTokens1, const TokenSet& setTokens2 ) 00423 { 00424 if ( setTokens2.empty() ) 00425 return setTokens1.empty(); 00426 for ( TokenSet::const_iterator i = setTokens2.begin() ; i != setTokens2.end() ; ++i ) 00427 if ( ! Contains( setTokens1, *i ) ) 00428 return false; 00429 return true; 00430 }