EaseaLex.l 96.6 KB
Newer Older
moh_lo's avatar
moh_lo committed
1
%{
kruger's avatar
kruger committed
2
/****************************************************************************
moh_lo's avatar
moh_lo committed
3 4 5 6 7
EaseaLex.l
Lexical analyser for the EASEA language (EAsy Specification for Evolutionary Algorithms)

Pierre COLLET (Pierre.Collet@polytechnique.fr)
Ecole Polytechnique
8
Centre de Math�matiques Appliqu�es
moh_lo's avatar
moh_lo committed
9
91128 Palaiseau cedex
maitre's avatar
maitre committed
10
  ****************************************************************************/
kruger's avatar
kruger committed
11 12 13 14
#ifdef WIN32
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(lib, "libAlexYacc.lib")
#endif
moh_lo's avatar
moh_lo committed
15 16
#include "Easea.h"
#include "EaseaParse.h"
kruger's avatar
kruger committed
17 18 19
#ifdef WIN32
#include <direct.h>
#else
maitre's avatar
maitre committed
20
#include <unistd.h>
kruger's avatar
kruger committed
21
#endif
maitre's avatar
maitre committed
22
#include "debug.h"
23 24
#include <iostream>
#include <sstream>
maitre's avatar
maitre committed
25

maitre's avatar
maitre committed
26 27
  size_t genomeSize;
  bool genomeSizeValidity=false;
28
  int lineCounter = 0;
maitre's avatar
maitre committed
29

30
  // local functions
maitre's avatar
maitre committed
31 32 33 34 35 36 37 38 39 40
  char* selectorDetermination(int nMINIMISE, char* sSELECTOR){

  char selectorName[50];  
  selectorName[3] = 0;
  if( nMINIMISE )
    strcpy(selectorName,"Min");
  else
    strcpy(selectorName,"Max");
  

maitre's avatar
maitre committed
41
  if( mystricmp("Tournament",sSELECTOR)==0 )
maitre's avatar
maitre committed
42 43 44
    strcat(selectorName,"Tournament(globalRandomGenerator)");
  else if( mystricmp("dettour",sSELECTOR)==0 )
    strcat(selectorName,"Tournament(globalRandomGenerator)");
maitre's avatar
maitre committed
45 46 47
  else if( mystricmp("Deterministic",sSELECTOR)==0 )
    strcat(selectorName,"Deterministic()");
  else if( mystricmp("deterministic",sSELECTOR)==0 )
48 49 50
    strcat(selectorName,"Deterministic()");
  else if( mystricmp("Random",sSELECTOR)==0 )
    strcat(selectorName,"Random(globalRandomGenerator)");
51 52
  else if( mystricmp("Roulette",sSELECTOR)==0 )
    strcat(selectorName,"Roulette(globalRandomGenerator)");
53

54
  else{
kruger's avatar
kruger committed
55
    //DEBUG_PRT_PRT("%s is not yet implemented",sSELECTOR);
56 57
    return NULL;
  }
maitre's avatar
maitre committed
58 59 60 61 62 63 64
  
  char* ret = (char*)malloc((strlen(selectorName)+1)*sizeof(char));
  strcpy(ret,selectorName);

  return ret;
}
  %}
moh_lo's avatar
moh_lo committed
65 66 67

// include file
%include {
maitre's avatar
maitre committed
68 69 70
  // forward references
  class CEASEAParser;
  class CSymbolTable;
71
  class OPCodeDesc;
maitre's avatar
maitre committed
72
 }                                                     
moh_lo's avatar
moh_lo committed
73 74
                                         
%start GENOME_ANALYSIS TEMPLATE_ANALYSIS MACRO_IDENTIFIER MACRO_DEFINITION 
75
%start COPY_USER_DECLARATIONS COPY_USER_CUDA COPY_INITIALISATION_FUNCTION ANALYSE_USER_CLASSES
76
%start COPY_EO_INITIALISER COPY_GP_OPCODE
77
%start COPY COPY_INITIALISER COPY_CROSSOVER COPY_MUTATOR COPY_EVALUATOR COPY_OPTIMISER COPY_FINALIZATION_FUNCTION
moh_lo's avatar
moh_lo committed
78
%start COPY_DISPLAY COPY_USER_FUNCTION COPY_USER_GENERATION PARAMETERS_ANALYSIS GET_PARAMETERS 
79
%start COPY_USER_FUNCTIONS COPY_GENERATION_FUNCTION_BEFORE_REPLACEMENT GET_METHODS COPY_MAKEFILE_OPTION COPY_BOUND_CHECKING_FUNCTION COPY_BEG_GENERATION_FUNCTION COPY_END_GENERATION_FUNCTION COPY_INSTEAD_EVAL GP_RULE_ANALYSIS GP_COPY_OPCODE_CODE COPY_GP_EVAL
moh_lo's avatar
moh_lo committed
80

maitre's avatar
maitre committed
81
 // lexical analyser name and class definition
moh_lo's avatar
moh_lo committed
82
%name CEASEALexer {
maitre's avatar
maitre committed
83
 protected:
moh_lo's avatar
moh_lo committed
84
  CSymbolTable *pSymbolTable;   // the symbol table
kruger's avatar
kruger committed
85
  bool bSymbolInserted,bWithinEvaluator, bWithinOptimiser;  // used to change evalutor type from double to float 
maitre's avatar
maitre committed
86 87
  bool bInitFunction,bDisplayFunction,bFunction, bNotFinishedYet, bWithinEO_Function;
  bool bDoubleQuotes,bWithinDisplayFunction,bWithinInitialiser,bWithinMutator,bWithinXover;
maitre's avatar
maitre committed
88
  bool bWaitingForSemiColon,bFinishNB_GEN,bFinishMINIMISE,bFinishMINIMIZE,bGenerationReplacementFunction;
maitre's avatar
maitre committed
89
  bool bCatchNextSemiColon,bWaitingToClosePopulation, bMethodsInGenome, bFinalizationFunction;
maitre's avatar
maitre committed
90
  bool bWithinCUDA_Initializer, bWithinMAKEFILEOPTION, bWithinCUDA_Evaluator, bBoundCheckingFunction;
maitre's avatar
maitre committed
91
  bool bIsParentReduce, bIsOffspringReduce, bEndGeneration, bBeginGeneration, bEndGenerationFunction, bBeginGenerationFunction, bGenerationFunctionBeforeReplacement;
92
  bool bGPOPCODE_ANALYSIS,bCOPY_GP_EVAL_GPU;
moh_lo's avatar
moh_lo committed
93 94
  CSymbol *pASymbol;

95 96 97 98 99 100 101 102
  unsigned iGP_OPCODE_FIELD, accolade_counter;
  OPCodeDesc* opDesc[128];
  unsigned iNoOp;

  enum COPY_GP_EVAL_STATUS {EVAL_HDR,EVAL_BDY,EVAL_FTR};
  unsigned iCOPY_GP_EVAL_STATUS;
  bool bIsCopyingGPEval;

maitre's avatar
maitre committed
103
 public:
moh_lo's avatar
moh_lo committed
104 105 106
  int create(CEASEAParser* pParser, CSymbolTable* pSymbolTable);
  int yywrap();
  double myStrtod() const;                              
maitre's avatar
maitre committed
107
 }
moh_lo's avatar
moh_lo committed
108 109 110

// constructor
{                                
kruger's avatar
kruger committed
111
  bFunction=bWithinEvaluator=bWithinOptimiser=bDisplayFunction=bInitFunction=bNotFinishedYet=0;
maitre's avatar
maitre committed
112
  bSymbolInserted=bDoubleQuotes=bWithinDisplayFunction=bWithinInitialiser=bWithinMutator=bWithinXover=0;
maitre's avatar
maitre committed
113
  bWaitingForSemiColon=bFinishNB_GEN=bFinishMINIMISE=bFinishMINIMIZE=bGenerationReplacementFunction=0;
maitre's avatar
maitre committed
114
  bCatchNextSemiColon,bWaitingToClosePopulation=bMethodsInGenome=0;
maitre's avatar
maitre committed
115
  bBoundCheckingFunction = bWithinCUDA_Initializer=bWithinMAKEFILEOPTION =bWithinCUDA_Evaluator=0;
maitre's avatar
maitre committed
116
  bIsParentReduce = bIsOffspringReduce = false;
117 118 119 120
  bGPOPCODE_ANALYSIS = bGenerationFunctionBeforeReplacement = bEndGeneration = bBeginGeneration = bEndGenerationFunction = bBeginGenerationFunction = false;
  iGP_OPCODE_FIELD = accolade_counter = 0;
  iNoOp = 0;
  bCOPY_GP_EVAL_GPU,bIsCopyingGPEval = false;
moh_lo's avatar
moh_lo committed
121 122 123 124 125
}

// macros
exponent  ([Ee][+-]?[0-9]+)

maitre's avatar
maitre committed
126 127


moh_lo's avatar
moh_lo committed
128 129 130
%%                                              

%{
maitre's avatar
maitre committed
131 132 133
  // extract yylval for use later on in actions
  YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
  %}
moh_lo's avatar
moh_lo committed
134 135 136 137 138 139

// Gobbles up ^Ms, to be compatible with unix
\r {}

// switch immediately to TEMPLATE_ANALYSIS state
<INITIAL>.    {
maitre's avatar
maitre committed
140 141
  BEGIN TEMPLATE_ANALYSIS; yyless(yyleng-1);
 }
moh_lo's avatar
moh_lo committed
142 143 144 145 146 147

//****************************************
//  GA_GENERATION lexer (feeds on template file and occasionally on .ez file)
//****************************************

<TEMPLATE_ANALYSIS>"\\TEMPLATE_START"  {             
maitre's avatar
maitre committed
148 149
  char sFileName[1000];
  strcpy(sFileName, sRAW_PROJECT_NAME);
kruger's avatar
kruger committed
150
  strcat(sFileName,".cpp"); 
maitre's avatar
maitre committed
151 152
  fpOutputFile=fopen(sFileName,"w");
 }
moh_lo's avatar
moh_lo committed
153 154 155
<TEMPLATE_ANALYSIS>"AESAE" {fprintf(fpOutputFile,"EASEA");}        
<TEMPLATE_ANALYSIS>"EASEA" {fprintf(fpOutputFile,"%s",sPROJECT_NAME);}        
<TEMPLATE_ANALYSIS>"\\EZ_PATH" {fprintf(fpOutputFile,"%s",sEZ_PATH);}        
kruger's avatar
kruger committed
156
<TEMPLATE_ANALYSIS>"\\TPL_DIR" {fprintf(fpOutputFile,"%s",sTPL_DIR);}
moh_lo's avatar
moh_lo committed
157 158 159
<TEMPLATE_ANALYSIS>"\\EO_DIR" {fprintf(fpOutputFile,"%s",sEO_DIR);}        
<TEMPLATE_ANALYSIS>"LC_EASEA" {fprintf(fpOutputFile,"%s",sLOWER_CASE_PROJECT_NAME);}        
<TEMPLATE_ANALYSIS>"\\OPERATING_SYSTEM"  {switch (OPERATING_SYSTEM) {
moh_lo's avatar
moh_lo committed
160 161 162 163 164
  case UNIX : fprintf(fpOutputFile,"UNIX_OS"); break;
  case WINDOWS : fprintf(fpOutputFile,"WINDOWS_OS"); break;
  case UNKNOWN_OS : fprintf(fpOutputFile,"UNKNOWN_OS"); break;
  }
 }
moh_lo's avatar
moh_lo committed
165
<TEMPLATE_ANALYSIS>"\\INSERT_USER_DECLARATIONS"  {
maitre's avatar
maitre committed
166 167
  if (bVERBOSE) printf ("Inserting user declarations.\n");
  yyreset();
168 169
  yyin = fpGenomeFile;                                                    // switch to .ez file and analyser
  lineCounter=1;
maitre's avatar
maitre committed
170 171
  BEGIN COPY_USER_DECLARATIONS;
 }
172 173 174 175 176 177 178 179 180

<TEMPLATE_ANALYSIS>"\\INSERT_USER_CUDA"  {
  if (bVERBOSE) printf ("Inserting user cuda.\n");
  yyreset();
  yyin = fpGenomeFile;                                                    // switch to .ez file and analyser
  lineCounter=1;
  BEGIN COPY_USER_CUDA;
 }

moh_lo's avatar
moh_lo committed
181
<TEMPLATE_ANALYSIS>"\\INSERT_INITIALISATION_FUNCTION"  {
maitre's avatar
maitre committed
182 183 184
  if (bVERBOSE) printf ("Inserting initialisation function.\n");
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
Ogier Maitre's avatar
Ogier Maitre committed
185
  lineCounter = 1;
maitre's avatar
maitre committed
186 187
  BEGIN COPY_INITIALISATION_FUNCTION;
 }
maitre's avatar
maitre committed
188 189 190

<TEMPLATE_ANALYSIS>"\\INSERT_GENERATION_FUNCTION_BEFORE_REPLACEMENT"  {
  if (bVERBOSE) printf ("Inserting generation before reduce function.\n");
maitre's avatar
maitre committed
191 192
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
maitre's avatar
maitre committed
193 194
  bGenerationFunctionBeforeReplacement = true;
  BEGIN COPY_GENERATION_FUNCTION_BEFORE_REPLACEMENT;
maitre's avatar
maitre committed
195
 }
maitre's avatar
maitre committed
196

maitre's avatar
maitre committed
197 198

<TEMPLATE_ANALYSIS>"\\INSERT_BEGIN_GENERATION_FUNCTION"  {
kruger's avatar
kruger committed
199
  //DEBUG_PRT_PRT("insert beg");
maitre's avatar
maitre committed
200
  if (bVERBOSE) printf ("Inserting at the begining of each generation function.\n");
Ogier Maitre's avatar
Ogier Maitre committed
201 202 203
  if( bLINE_NUM_EZ_FILE )
    fprintf(fpOutputFile,"#line %d \"%s.ez\"\n",lineCounter+1, sRAW_PROJECT_NAME);

maitre's avatar
maitre committed
204 205
  yyreset();
  yyin = fpGenomeFile;
206 207
  bBeginGeneration = true;
  bEndGeneration = false;
Ogier Maitre's avatar
Ogier Maitre committed
208
  lineCounter = 1;
209
  BEGIN COPY_BEG_GENERATION_FUNCTION;
maitre's avatar
maitre committed
210 211 212
 }


213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338

/*
  Here we will insert parmeters for GP template.
*/
<TEMPLATE_ANALYSIS>"\\INSERT_GP_PARAMETERS" {
  if( bVERBOSE )printf("inserting gp parameters\n");
  //  fprintf(fpOutputFile,"#define MAX_XOVER_DEPTH",%d
  fprintf(fpOutputFile,"#define TREE_DEPTH_MAX %d\n",iMAX_TREE_D);
  fprintf(fpOutputFile,"#define INIT_TREE_DEPTH_MAX %d\n",iMAX_INIT_TREE_D);
  fprintf(fpOutputFile,"#define INIT_TREE_DEPTH_MIN %d\n",iMIN_INIT_TREE_D);

  fprintf(fpOutputFile,"#define MAX_PROGS_SIZE %d\n",iPRG_BUF_SIZE);
  fprintf(fpOutputFile,"#define NB_GPU %d\n",iNB_GPU);

  fprintf(fpOutputFile,"#define NO_FITNESS_CASES %d\n",iNO_FITNESS_CASES);
}

/*
  This part dump every declaration related to gp opcode.
  the enumeration, the array of name (to plot trees)
  and the arity of every opcode.
 */
<TEMPLATE_ANALYSIS>"\\INSERT_GP_OPCODE_DECL" {
  
  fprintf(fpOutputFile,"enum OPCODE              {"); 
  for( unsigned i=0 ; i<iNoOp ; i++ ){
    fprintf(fpOutputFile,"%s,",opDesc[i]->opcode->c_str());
  }
  fprintf(fpOutputFile,"OPCODE_SIZE, OP_RETURN};\n");


  fprintf(fpOutputFile,"const char* opCodeName[]={"); 
  for( unsigned i=0 ; i<iNoOp ; i++ ){
    fprintf(fpOutputFile,"%s",opDesc[i]->realName->c_str());
    if( i<(iNoOp-1) )fprintf(fpOutputFile,",");
  }
  fprintf(fpOutputFile,"};\n"); 
  fprintf(fpOutputFile,"unsigned opArity[]=     {"); 
  for( unsigned i=0 ; i<iNoOp ; i++ ){
    fprintf(fpOutputFile,"%d",opDesc[i]->arity);
    if( i<(iNoOp-1) )fprintf(fpOutputFile,",");
  }
  fprintf(fpOutputFile,"};\n"); 


  // count the number of variable (arity zero and non-erc operator)
  unsigned var_len = 0;
  for( unsigned i=0 ; i<iNoOp ; i++ ){
    if( opDesc[i]->arity==0 && !opDesc[i]->isERC ) var_len++;
  }
  if( bVERBOSE ) printf("var length is %d\n",var_len);
  fprintf(fpOutputFile,"#define VAR_LEN %d\n",var_len); 
 }

<TEMPLATE_ANALYSIS>"\\INSERT_GP_GPU_SWITCH" {
  for( unsigned i=0 ; i<iNoOp ; i++ ){
    fprintf(fpOutputFile,"    case %s :\n",opDesc[i]->opcode->c_str());
    fprintf(fpOutputFile,"      %s",opDesc[i]->gpuCodeStream.str().c_str());
    fprintf(fpOutputFile,"      break;\n");

  }
 }

<TEMPLATE_ANALYSIS>"\\INSERT_GP_CPU_SWITCH" {
  for( unsigned i=0 ; i<iNoOp ; i++ ){
    fprintf(fpOutputFile,"  case %s :\n",opDesc[i]->opcode->c_str());
    fprintf(fpOutputFile,"    %s\n",opDesc[i]->cpuCodeStream.str().c_str());
    fprintf(fpOutputFile,"    break;\n");
  }
 }


<TEMPLATE_ANALYSIS>"\\ANALYSE_GP_OPCODE"  {
  yyreset();
  rewind(fpGenomeFile);
  yyin = fpGenomeFile;
  if (bVERBOSE) printf ("Analysing GP OP code from ez file\n");
  BEGIN COPY_GP_OPCODE;
 }


<COPY_GP_OPCODE>"\\begin operator description :" {
  if (bVERBOSE) printf ("found begin section\n");
  bGPOPCODE_ANALYSIS = true;
  BEGIN GP_RULE_ANALYSIS;
 }

<GP_RULE_ANALYSIS>"\\end" { 
  if (bVERBOSE) printf ("found end section\n");
  if( bGPOPCODE_ANALYSIS ){
    rewind(fpGenomeFile);
    yyin = fpTemplateFile;
    bGPOPCODE_ANALYSIS = false;
    
    OPCodeDesc::sort(opDesc,iNoOp);
    /*for( unsigned i=0 ; i<iNoOp ; i++ ){
      opDesc[i]->show();
      }*/
    BEGIN TEMPLATE_ANALYSIS; 
  }  
 }

<COPY_GP_OPCODE><<EOF>> {
  if (bVERBOSE) printf("*** No GP OP codes were found. ***\n");
  rewind(fpGenomeFile);
  yyin = fpTemplateFile;
  BEGIN TEMPLATE_ANALYSIS;
 }
<COPY_GP_OPCODE>. {} //if( bGPOPCODE_ANALYSIS ) printf("%c",yytext[0]);}                                      
<COPY_GP_OPCODE>\n {if( bGPOPCODE_ANALYSIS )printf("\n");lineCounter++;}

/*
  This section analyse a GP rule which is written as : 
  OP_NAME, "realopname", arity (a number), { the c code for this operator};
  OP_NAME, "realopname", arity (a number), { the c code for this operator};
 */
<GP_RULE_ANALYSIS>[A-Za-z_][a-zA-Z0-9_]* {
  // this rule match the OP_NAME
  if( iGP_OPCODE_FIELD != 0 ){
    fprintf(stderr,"Error, OP_CODE name must be given first\n");
    exit(-1);
  }
  opDesc[iNoOp] = new OPCodeDesc();
  opDesc[iNoOp]->opcode = new string(yytext);
 }

339 340
<GP_RULE_ANALYSIS>"//".*"\n" {}

341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
<GP_RULE_ANALYSIS>"\""([a-zA-Z0-9]|\*|\+|\-|\/|\%)*"\"" {
  if( iGP_OPCODE_FIELD != 1 ){
    fprintf(stderr,"Error, op code real name must be given at the second place\n");
    exit(-1);
  }
  opDesc[iNoOp]->realName = new string(yytext);
 }


<GP_RULE_ANALYSIS>[0-9]* {
  if( iGP_OPCODE_FIELD != 2 ){
    fprintf(stderr,"Error, arity must be given at the third place\n");
    exit(-1);
  }
  char* endptr;
  
  opDesc[iNoOp]->arity = strtol(yytext,&endptr,10);
  if( endptr==yytext ){
    fprintf(stderr, "warning, unable to translate this arity %s assuming 0\n",yytext);
    opDesc[iNoOp]->arity = 0;
  }
 }

<GP_RULE_ANALYSIS>[ \t\n] {}
<GP_RULE_ANALYSIS>";"  {
  iGP_OPCODE_FIELD = 0;
  iNoOp++;
 }

<GP_RULE_ANALYSIS>"," {
  if( bGPOPCODE_ANALYSIS ) iGP_OPCODE_FIELD++;
 }


<GP_RULE_ANALYSIS>"{" {
  if( iGP_OPCODE_FIELD != 3 ){
    fprintf(stderr,"Error, code must be given at the forth place\n");
    exit(-1);
  }
  if( bVERBOSE ) printf("begining of the code part\n");
  accolade_counter=1;

383
//  printf("arity : %d\n",opDesc[iNoOp]->arity);
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
  if( opDesc[iNoOp]->arity>=2 )
    opDesc[iNoOp]->gpuCodeStream << "OP2 = stack[--sp];\n      ";
  if( opDesc[iNoOp]->arity>=1 )
    opDesc[iNoOp]->gpuCodeStream << "OP1 = stack[--sp];\n      ";

  BEGIN GP_COPY_OPCODE_CODE;
 }

/*
  This section copy the code contained in the code part of the GP opcode rule
  It count the number of curly bracket, when it reaches 0, the code part is finished.
 */
<GP_COPY_OPCODE_CODE>"{" {
  accolade_counter++;
  opDesc[iNoOp]->cpuCodeStream << "{";
  opDesc[iNoOp]->gpuCodeStream << "{";
 }

<GP_COPY_OPCODE_CODE>"}" {
  accolade_counter--;
  if( accolade_counter==0 ){
    opDesc[iNoOp]->gpuCodeStream << "\n      stack[sp++] = RESULT;\n";

    BEGIN GP_RULE_ANALYSIS;
  }
  else{
    opDesc[iNoOp]->cpuCodeStream << "}";
    opDesc[iNoOp]->gpuCodeStream << "}";
  }
 }

<GP_COPY_OPCODE_CODE>"INPUT["[0-9]*"]" {
  char* endptr;
  unsigned no_input = strtol(yytext+strlen("INPUT["),&endptr,10);
418
//  printf("input no : %d\n",no_input);
419 420 421 422 423 424 425 426
  opDesc[iNoOp]->cpuCodeStream << "input["<< no_input <<"]" ;
  opDesc[iNoOp]->gpuCodeStream << "input["<< no_input << "]";  
 }

<GP_COPY_OPCODE_CODE>"ERC" {
  opDesc[iNoOp]->isERC = true;
  opDesc[iNoOp]->cpuCodeStream << "root->erc_value" ;
  opDesc[iNoOp]->gpuCodeStream << "k_progs[start_prog++];" ;
427
//  printf("ERC matched\n");
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
}

<GP_COPY_OPCODE_CODE>\n {
  opDesc[iNoOp]->cpuCodeStream << "\n  ";
  opDesc[iNoOp]->gpuCodeStream << "\n    ";
 }


<GP_COPY_OPCODE_CODE>. {
  opDesc[iNoOp]->cpuCodeStream << yytext;
  opDesc[iNoOp]->gpuCodeStream << yytext;
 }

<TEMPLATE_ANALYSIS>"\\INSERT_GENOME_EVAL_HDR" { 
  yyreset();
  rewind(fpGenomeFile);
  yyin = fpGenomeFile;
  bIsCopyingGPEval = false;
  if( bVERBOSE ) printf("Insert GP eval header\n");
  iCOPY_GP_EVAL_STATUS = EVAL_HDR;
  fprintf(fpOutputFile,"  ");
  BEGIN COPY_GP_EVAL;
 }

<TEMPLATE_ANALYSIS>"\\INSERT_GENOME_EVAL_BDY" {
  yyreset();
  rewind(fpGenomeFile);
  yyin = fpGenomeFile;
  bIsCopyingGPEval = false;
  iCOPY_GP_EVAL_STATUS = EVAL_BDY;
  if( bVERBOSE ) printf("Insert GP eval body\n");
  fprintf(fpOutputFile,"      ");
460
  bCOPY_GP_EVAL_GPU = false;
461 462 463
  BEGIN COPY_GP_EVAL;
 }

464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479


<TEMPLATE_ANALYSIS>"\\INSERT_GENOME_EVAL_BDY_GPU" {
  yyreset();
  rewind(fpGenomeFile);
  yyin = fpGenomeFile;
  bIsCopyingGPEval = false;
  iCOPY_GP_EVAL_STATUS = EVAL_BDY;
  if( bVERBOSE ) printf("Insert GP eval body\n");
  fprintf(fpOutputFile,"      ");
  bCOPY_GP_EVAL_GPU = true;
  BEGIN COPY_GP_EVAL;
 }



480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
<TEMPLATE_ANALYSIS>"\\INSERT_GENOME_EVAL_FTR" {
  yyreset();
  rewind(fpGenomeFile);
  yyin = fpGenomeFile;
  bIsCopyingGPEval = false;
  iCOPY_GP_EVAL_STATUS = EVAL_FTR;
  if( bVERBOSE ) printf("Insert GP eval footer\n");
  fprintf(fpOutputFile,"  ");
  BEGIN COPY_GP_EVAL;
 }

<TEMPLATE_ANALYSIS>"\\INSERT_GENOME_EVAL_FTR_GPU" {
  yyreset();
  rewind(fpGenomeFile);
  yyin = fpGenomeFile;
  bIsCopyingGPEval = false;
  iCOPY_GP_EVAL_STATUS = EVAL_FTR;
  if( bVERBOSE ) printf("Insert GP eval footer\n");
  fprintf(fpOutputFile,"  ");
  bCOPY_GP_EVAL_GPU = true;
  BEGIN COPY_GP_EVAL;
 }


<COPY_GP_EVAL><<EOF>> {
  switch(iCOPY_GP_EVAL_STATUS){
  case EVAL_HDR:
    fprintf(stderr,"Error, no evaluator header has been defined\n");
    exit(-1);
  case EVAL_BDY:
    fprintf(stderr,"Error, no evaluator body has been defined\n");
    exit(-1);
  case EVAL_FTR:
    fprintf(stderr,"Error, no evaluator footer has been defined\n");
    exit(-1);
  }
 }


<COPY_GP_EVAL>"\\GenomeClass::evaluator"[ \t]*"header"[ \t]*":" {
  if( iCOPY_GP_EVAL_STATUS==EVAL_HDR){
    bIsCopyingGPEval = true;
  }
 }

<COPY_GP_EVAL>"\\GenomeClass::evaluator"[ \t]*"for"[ \t]*"each"[ \t]*"fc"[ \t]*":" {
  if( iCOPY_GP_EVAL_STATUS==EVAL_BDY){
    bIsCopyingGPEval = true;
  }
 }



<COPY_GP_EVAL>"\\GenomeClass::evaluator"[ \t]*"accumulator"[ \t]*":" {
  if( iCOPY_GP_EVAL_STATUS==EVAL_FTR){
    bIsCopyingGPEval = true;
  }
 }

<COPY_GP_EVAL>"\\end" {
  if( bIsCopyingGPEval ){
    bIsCopyingGPEval = false;
    bCOPY_GP_EVAL_GPU = false;
    rewind(fpGenomeFile);
    yyin = fpTemplateFile;
    BEGIN TEMPLATE_ANALYSIS;
  }
 }

<COPY_GP_EVAL>. {
  if( bIsCopyingGPEval ) fprintf(fpOutputFile,"%s",yytext);
 }

<COPY_GP_EVAL>"OUTPUT" {
554 555 556 557 558
  if( bIsCopyingGPEval) 
    if( bCOPY_GP_EVAL_GPU )
      fprintf(fpOutputFile, "outputs[i*NUMTHREAD2+tid]" );
    else fprintf(fpOutputFile, "outputs[i]" );
  
559 560
 }

561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
<COPY_GP_EVAL>"OUTPUT["[0-9]+"]" {
  char* endptr;
  unsigned no_output = strtol(yytext+strlen("OUTPUT["),&endptr,10);
  if( bIsCopyingGPEval) 
    if( bCOPY_GP_EVAL_GPU )
      fprintf(fpOutputFile, "outputs[i*NUMTHREAD2+tid+%d]", no_output);
    else fprintf(fpOutputFile, "outputs[i+%d]", no_output );
  
 }

<COPY_GP_EVAL>"OUTPUT["[a-zA-Z][a-zA-Z0-9]*"]" {
	char *var;
	var = strndup(yytext+strlen("OUTPUT["), strlen(yytext) - strlen("OUTPUT[") - 1);
  if( bIsCopyingGPEval) 
    if( bCOPY_GP_EVAL_GPU )
      fprintf(fpOutputFile, "outputs[i*NUMTHREAD2+tid+%s]", var);
    else fprintf(fpOutputFile, "outputs[i+%s]", var);
  
 }

<COPY_GP_EVAL>"INPUT" {
  if( bIsCopyingGPEval) 
    if( bCOPY_GP_EVAL_GPU )
      fprintf(fpOutputFile, "k_inputs[i*NUMTHREAD2+tid]" );
    else fprintf(fpOutputFile, "inputs[i][0]" );
  
 }

<COPY_GP_EVAL>"INPUT["[0-9]+"]" {
  char* endptr;
  unsigned no_input = strtol(yytext+strlen("INPUT["),&endptr,10);
  if( bIsCopyingGPEval) 
    if( bCOPY_GP_EVAL_GPU )
      fprintf(fpOutputFile, "k_inputs[i*NUMTHREAD2+tid+%d]", no_input);
    else fprintf(fpOutputFile, "inputs[i][%d]", no_input );
  
 }

<COPY_GP_EVAL>"INPUT["[a-zA-Z][a-zA-Z0-9]*"]" {
	char *var;
	var = strndup(yytext+strlen("INPUT["), strlen(yytext) - strlen("INPUT[") - 1);
  if( bIsCopyingGPEval) 
    if( bCOPY_GP_EVAL_GPU )
      fprintf(fpOutputFile, "k_inputs[i*NUMTHREAD2+tid+%s]", var);
    else fprintf(fpOutputFile, "inputs[i][%s]", var);
  
 }

609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
<COPY_GP_EVAL>"return " {
  if( bIsCopyingGPEval )
    if( iCOPY_GP_EVAL_STATUS==EVAL_FTR )
      if( bCOPY_GP_EVAL_GPU ){
	fprintf(fpOutputFile,"k_results[index] =");
      }
      else fprintf(fpOutputFile,"%s",yytext);
 }




<COPY_GP_EVAL>\n {
  if( bIsCopyingGPEval )
    switch(iCOPY_GP_EVAL_STATUS){
    case EVAL_FTR:
    case EVAL_HDR:
      fprintf(fpOutputFile,"\n  ");
      break;
    case EVAL_BDY:
      fprintf(fpOutputFile,"\n      ");
      break;
    }
 }


<COPY_GP_EVAL>"return"	{
  if( bIsCopyingGPEval )
    fprintf(fpOutputFile,"return fitness = "); 
 }



642 643 644 645 646
<TEMPLATE_ANALYSIS>"\\INSTEAD_EVAL_FUNCTION"  {
  //DEBUG_PRT_PRT("insert beg");
  yyreset();
  yyin = fpGenomeFile;
  if (bVERBOSE) printf ("Evaluation population in a single function!!.\n");
Ogier Maitre's avatar
Ogier Maitre committed
647
  lineCounter = 1;
648 649 650
  BEGIN COPY_INSTEAD_EVAL;
 }

maitre's avatar
maitre committed
651 652 653 654 655 656
<TEMPLATE_ANALYSIS>"\\INSERT_END_GENERATION_FUNCTION"  {
  if (bVERBOSE) printf ("Inserting at the end of each generation function.\n");
  yyreset();
  yyin = fpGenomeFile;
  bEndGeneration = true;
  bBeginGeneration = false;
657
  BEGIN COPY_END_GENERATION_FUNCTION;
maitre's avatar
maitre committed
658 659
 }

maitre's avatar
maitre committed
660 661 662 663 664 665 666
<TEMPLATE_ANALYSIS>"\\INSERT_BOUND_CHECKING"  {
  if (bVERBOSE) printf ("Inserting Bound Checking function.\n");
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  BEGIN COPY_BOUND_CHECKING_FUNCTION;
 }

moh_lo's avatar
moh_lo committed
667
<TEMPLATE_ANALYSIS>"\\ANALYSE_USER_CLASSES"  {
maitre's avatar
maitre committed
668 669 670 671 672
  if (bVERBOSE) printf ("Analysing user classes.\n");
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  BEGIN ANALYSE_USER_CLASSES;
 }
maitre's avatar
maitre committed
673

moh_lo's avatar
moh_lo committed
674
<TEMPLATE_ANALYSIS>"\\INSERT_USER_CLASSES"  {
maitre's avatar
maitre committed
675
  if (bVERBOSE) printf ("Inserting User classes.\n");
maitre's avatar
maitre committed
676
  fprintf (fpOutputFile,"// User classes\n");
maitre's avatar
maitre committed
677 678 679
  CListItem<CSymbol*> *pSym;
  pGENOME->pSymbolList->reset();
  while (pSym=pGENOME->pSymbolList->walkToNextItem())
maitre's avatar
maitre committed
680
    if ((pSym->Object->pType->ObjectType==oUserClass)&&(!pSym->Object->pType->bAlreadyPrinted)){
kruger's avatar
kruger committed
681
      //DEBUG_PRT_PRT("%p",pSym->Object->pType);
maitre's avatar
maitre committed
682
      pSym->Object->pType->printClasses(fpOutputFile);
maitre's avatar
maitre committed
683 684 685
    }

  if( TARGET == CUDA ){
kruger's avatar
kruger committed
686
    //DEBUG_PRT_PRT("User classes are :");
maitre's avatar
maitre committed
687
    for( int i = nClasses_nb-1 ; i>=0 ; i-- ){
kruger's avatar
kruger committed
688
      //DEBUG_PRT_PRT(" %s, %p ,%d| ",pCLASSES[i]->sName,pCLASSES[i],pCLASSES[i]->bAlreadyPrinted);
maitre's avatar
maitre committed
689 690 691 692 693
      if( !pCLASSES[i]->bAlreadyPrinted ){
	fprintf(fpOutputFile,"// User class not refereced by the Genome");
	pCLASSES[i]->printClasses(fpOutputFile);
      }
    }
kruger's avatar
kruger committed
694
    //DEBUG_PRT_PRT("\n");
maitre's avatar
maitre committed
695
  }
maitre's avatar
maitre committed
696
 }
moh_lo's avatar
moh_lo committed
697
<TEMPLATE_ANALYSIS>"\\GENOME_CTOR"  {
maitre's avatar
maitre committed
698 699 700 701 702 703
  CListItem<CSymbol*> *pSym;
  if (bVERBOSE) printf ("Inserting default genome constructor.\n");
  pGENOME->pSymbolList->reset();
  while (pSym=pGENOME->pSymbolList->walkToNextItem()){
    if (pSym->Object->ObjectQualifier==1) continue; // 1=Static
    if (pSym->Object->ObjectType==oPointer){
maitre's avatar
maitre committed
704
      fprintf(fpOutputFile,"    %s=NULL;\n",pSym->Object->sName);
moh_lo's avatar
moh_lo committed
705
    }
maitre's avatar
maitre committed
706 707
  }
 }
maitre's avatar
maitre committed
708

maitre's avatar
maitre committed
709 710
<TEMPLATE_ANALYSIS>"\\GENOME_SIZE" {
  size_t size_of_genome=0;
maitre's avatar
maitre committed
711 712 713 714 715 716
  if (bVERBOSE) printf ("Inserting default genome size.\n");
  if( !genomeSizeValidity ){
    if (bVERBOSE) printf ("\tComputing default genome size.\n");  
    CListItem<CSymbol*> *pSym;
    pGENOME->pSymbolList->reset();
    while (pSym=pGENOME->pSymbolList->walkToNextItem()){
kruger's avatar
kruger committed
717
      //DEBUG_PRT_PRT("%s has size : %lu",pSym->Object->sName,pSym->Object->nSize);
maitre's avatar
maitre committed
718 719
      size_of_genome+=pSym->Object->nSize;
    }
kruger's avatar
kruger committed
720
    //DEBUG_PRT_PRT("Total genome size is %lu",size_of_genome); 
maitre's avatar
ok  
maitre committed
721
    genomeSize = size_of_genome;
maitre's avatar
maitre committed
722 723 724 725
    genomeSizeValidity=true;
  }
  else{
    size_of_genome = genomeSize;
maitre's avatar
maitre committed
726 727 728 729 730 731 732 733 734 735 736 737 738 739
  }
  fprintf(fpOutputFile,"%d",size_of_genome);
 }

<TEMPLATE_ANALYSIS>"\\COPY_CUDA_BUFFER" {
  CListItem<CSymbol*> *pSym;
  if (bVERBOSE) printf ("Inserting default genome constructor.\n");
  pGENOME->pSymbolList->reset();

  fprintf(fpOutputFile,"\tmemcpy(GENOME_ACCESS(id,buffer),this,Individual::sizeOfGenome);");

  while (pSym=pGENOME->pSymbolList->walkToNextItem()){
    if (pSym->Object->ObjectQualifier==1) continue; // 1=Static
    if (pSym->Object->ObjectType==oPointer){
maitre's avatar
maitre committed
740
      fprintf(fpOutputFile,"    %s=NULL;\n",pSym->Object->sName);
maitre's avatar
maitre committed
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
    }
  }
  
 }

/* <TEMPLATE_ANALYSIS>"\\GENOME_CUDA_MOTION" { */
/*   if (bVERBOSE) printf ("Inserting default genome cuda motion function.\n"); */
  
/*   CListItem<CSymbol*> *pSym; */
/*   if (bVERBOSE) printf ("Creating default copy constructor.\n"); */
/*   fprintf (fpOutputFile,"// Memberwise copy\n");              */
/*   pGENOME->pSymbolList->reset(); */
/*   while (pSym=pGENOME->pSymbolList->walkToNextItem()){ */
/*     if (pSym->Object->ObjectQualifier==1) continue; // 1=Static */
/*     if (pSym->Object->ObjectType==oObject) */
/*       fprintf(fpOutputFile,"    %s=genome.%s;\n",pSym->Object->sName,pSym->Object->sName); */
/*     if (pSym->Object->ObjectType==oPointer) */
/*       fprintf(fpOutputFile,"    %s=(genome.%s ? new %s(*(genome.%s)) : NULL);\n",pSym->Object->sName,pSym->Object->sName,pSym->Object->pType->sName,pSym->Object->sName); */
/*     if (pSym->Object->ObjectType==oArray){ */
/* /\*       fprintf(fpOutputFile,"    {for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)\n",pSym->Object->nSize/pSym->Object->pType->nSize); *\/ */
/* /\*       fprintf(fpOutputFile,"       %s[EASEA_Ndx]=genome.%s[EASEA_Ndx];}\n",pSym->Object->sName,pSym->Object->sName); *\/ */
      
/*     } */
/*   } */
/*  } */


maitre's avatar
maitre committed
768 769


moh_lo's avatar
moh_lo committed
770
<TEMPLATE_ANALYSIS>"\\INSERT_GENOME"  {        
maitre's avatar
maitre committed
771 772 773 774 775 776 777 778
  if (pGENOME->sString) {
    if (bVERBOSE) printf ("Inserting Methods into Genome Class.\n");
    fprintf(fpOutputFile,"// User-defined methods:\n\n");
    fprintf(fpOutputFile,"%s\n",pGENOME->sString);
  }
  if (bVERBOSE) printf ("Inserting genome.\n");
  pGENOME->print(fpOutputFile);
 }                                            
moh_lo's avatar
moh_lo committed
779
<TEMPLATE_ANALYSIS>"\\ASSIGNMENT_OP"  {
maitre's avatar
maitre committed
780 781 782 783 784 785 786 787 788 789 790 791 792
  CListItem<CSymbol*> *pSym;
  if (bVERBOSE) printf ("Creating default assignment constructor.\n");
  fprintf (fpOutputFile,"// Memberwise assignment\n");             
  pGENOME->pSymbolList->reset();                                      
  while (pSym=pGENOME->pSymbolList->walkToNextItem()){
    if (pSym->Object->ObjectQualifier==1) continue; // 1=Static
    if (pSym->Object->ObjectType==oObject)
      fprintf(fpOutputFile,"    %s=genome.%s;\n",pSym->Object->sName,pSym->Object->sName);
    if (pSym->Object->ObjectType==oPointer)
      fprintf(fpOutputFile,"    %s=new %s(*(genome.%s));\n",pSym->Object->sName,pSym->Object->pType->sName,pSym->Object->sName);
    if (pSym->Object->ObjectType==oArray){
      fprintf(fpOutputFile,"    {for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)\n",pSym->Object->nSize/pSym->Object->pType->nSize);
      fprintf(fpOutputFile,"       %s[EASEA_Ndx]=genome.%s[EASEA_Ndx];}\n",pSym->Object->sName,pSym->Object->sName);
moh_lo's avatar
moh_lo committed
793
    }
maitre's avatar
maitre committed
794 795
  }
 }
moh_lo's avatar
moh_lo committed
796
<TEMPLATE_ANALYSIS>"\\CLONE"  {
maitre's avatar
maitre committed
797 798 799 800 801 802 803 804 805 806 807 808 809
  CListItem<CSymbol*> *pSym;
  if (bVERBOSE) printf ("Creating default clone method.\n");
  fprintf (fpOutputFile,"// Memberwise Cloning\n");             
  pGENOME->pSymbolList->reset();
  while (pSym=pGENOME->pSymbolList->walkToNextItem()){
    if (pSym->Object->ObjectQualifier==1) continue; // 1=Static
      if (pSym->Object->ObjectType==oObject)
	fprintf(fpOutputFile,"    %s=genome.%s;\n",pSym->Object->sName,pSym->Object->sName);
      if (pSym->Object->ObjectType==oPointer)
	fprintf(fpOutputFile,"    %s=(genome.%s ? new %s(*(genome.%s)) : NULL);\n",pSym->Object->sName,pSym->Object->sName,pSym->Object->pType->sName,pSym->Object->sName);
      if (pSym->Object->ObjectType==oArray){
	fprintf(fpOutputFile,"    {for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)\n",pSym->Object->nSize/pSym->Object->pType->nSize);
	fprintf(fpOutputFile,"       %s[EASEA_Ndx]=genome.%s[EASEA_Ndx];}\n",pSym->Object->sName,pSym->Object->sName);
moh_lo's avatar
moh_lo committed
810
      }
maitre's avatar
maitre committed
811 812
  }
 }
moh_lo's avatar
moh_lo committed
813 814

<TEMPLATE_ANALYSIS>"\\COPY_CTOR"  {
maitre's avatar
maitre committed
815 816 817 818 819 820 821 822 823 824 825 826 827
  CListItem<CSymbol*> *pSym;
  if (bVERBOSE) printf ("Creating default copy constructor.\n");
  fprintf (fpOutputFile,"// Memberwise copy\n");             
  pGENOME->pSymbolList->reset();
  while (pSym=pGENOME->pSymbolList->walkToNextItem()){
    if (pSym->Object->ObjectQualifier==1) continue; // 1=Static
      if (pSym->Object->ObjectType==oObject)
	fprintf(fpOutputFile,"    %s=genome.%s;\n",pSym->Object->sName,pSym->Object->sName);
      if (pSym->Object->ObjectType==oPointer)
	fprintf(fpOutputFile,"    %s=(genome.%s ? new %s(*(genome.%s)) : NULL);\n",pSym->Object->sName,pSym->Object->sName,pSym->Object->pType->sName,pSym->Object->sName);
      if (pSym->Object->ObjectType==oArray){
	fprintf(fpOutputFile,"    {for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)\n",pSym->Object->nSize/pSym->Object->pType->nSize);
	fprintf(fpOutputFile,"       %s[EASEA_Ndx]=genome.%s[EASEA_Ndx];}\n",pSym->Object->sName,pSym->Object->sName);
moh_lo's avatar
moh_lo committed
828
      }
829 830 831 832 833 834 835 836 837
      else if( pSym->Object->ObjectType==oArrayPointer ){ 
	// here we handle array of pointer (developped for Tree GP)
	fprintf(fpOutputFile,"    for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)\n",pSym->Object->nSize/sizeof(char*));
	fprintf(fpOutputFile,"      if(genome.%s[EASEA_Ndx]) %s[EASEA_Ndx] = new %s(*(genome.%s[EASEA_Ndx]));\n",pSym->Object->sName,
		pSym->Object->sName,pSym->Object->pType->sName,pSym->Object->sName);
	fprintf(fpOutputFile,"      else %s[EASEA_Ndx] = NULL;\n",pSym->Object->sName);
	
      }
      
maitre's avatar
maitre committed
838 839
  }
 }
840

kruger's avatar
kruger committed
841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857
<TEMPLATE_ANALYSIS>"\\GENOME_SERIAL"  {
  CListItem<CSymbol*> *pSym;
  if (bVERBOSE) printf ("Inserting default genome serializer.\n");
  fprintf (fpOutputFile,"// Memberwise serialization\n");
  pGENOME->pSymbolList->reset();
  pGENOME->serializeIndividual(fpOutputFile, "this");
  //fprintf(fpOutputFile,"\tEASEA_Line << endl;\n");
 }

<TEMPLATE_ANALYSIS>"\\GENOME_DESERIAL"  {
  CListItem<CSymbol*> *pSym;
  if (bVERBOSE) printf ("Inserting default genome deserializer.\n");
  fprintf (fpOutputFile,"// Memberwise deserialization\n");
  pGENOME->pSymbolList->reset();
  pGENOME->deserializeIndividual(fpOutputFile, "this");
 }

858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873
<TEMPLATE_ANALYSIS>"\\COPY_CUDA_CTOR"  {
  CListItem<CSymbol*> *pSym;
  if (bVERBOSE) printf ("Creating default copy constructor.\n");
  fprintf (fpOutputFile,"// Memberwise copy\n");             
  pGENOME->pSymbolList->reset();
  while (pSym=pGENOME->pSymbolList->walkToNextItem()){
    if (pSym->Object->ObjectQualifier==1) continue; // 1=Static
      if (pSym->Object->ObjectType==oObject)
	fprintf(fpOutputFile,"    dest->%s=src->%s;\n",pSym->Object->sName,pSym->Object->sName);
      if (pSym->Object->ObjectType==oArray){
	fprintf(fpOutputFile,"    {for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)\n",pSym->Object->nSize/pSym->Object->pType->nSize);
	fprintf(fpOutputFile,"       dest->%s[EASEA_Ndx]=src->%s[EASEA_Ndx];}\n",pSym->Object->sName,pSym->Object->sName);
      }
  }
 }

moh_lo's avatar
moh_lo committed
874
<TEMPLATE_ANALYSIS>"\\GENOME_DTOR"  {
maitre's avatar
maitre committed
875 876 877 878
  CListItem<CSymbol*> *pSym;
  if (bVERBOSE) printf ("Creating default destructor.\n");
  fprintf (fpOutputFile,"// Destructing pointers\n");             
  pGENOME->pSymbolList->reset();
879
  while (pSym=pGENOME->pSymbolList->walkToNextItem()){
maitre's avatar
maitre committed
880
    if (pSym->Object->ObjectType==oPointer){
maitre's avatar
maitre committed
881
      fprintf(fpOutputFile,"  if (%s) delete %s;\n  %s=NULL;\n",pSym->Object->sName,pSym->Object->sName,pSym->Object->sName);
moh_lo's avatar
moh_lo committed
882
    }
883 884 885 886 887 888
    else if( pSym->Object->ObjectType==oArrayPointer ){ 
      // here we handle array of pointer (developped for Tree GP)
      fprintf(fpOutputFile,"    for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)\n",pSym->Object->nSize/sizeof(char*));
      fprintf(fpOutputFile,"      if(%s[EASEA_Ndx]) delete %s[EASEA_Ndx];\n",pSym->Object->sName,pSym->Object->sName,pSym->Object->pType->sName,pSym->Object->sName);
    }
  }
moh_lo's avatar
moh_lo committed
889
 }
890

moh_lo's avatar
moh_lo committed
891
<TEMPLATE_ANALYSIS>"\\EQUAL"  {       
maitre's avatar
maitre committed
892 893 894 895 896 897 898 899 900 901 902 903
  CListItem<CSymbol*> *pSym;
  if (bVERBOSE) printf ("Creating default diversity test.\n");
  fprintf (fpOutputFile,"// Default diversity test (required by GALib)\n");             
  pGENOME->pSymbolList->reset();
  while (pSym=pGENOME->pSymbolList->walkToNextItem()) {
    if (pSym->Object->ObjectType==oObject)
      fprintf(fpOutputFile,"  if (%s!=genome.%s) return 0;\n",pSym->Object->sName,pSym->Object->sName);
    if (pSym->Object->ObjectType==oPointer)
      fprintf(fpOutputFile,"  if (*%s!=*(genome.%s)) return 0;\n",pSym->Object->sName,pSym->Object->sName);
    if (pSym->Object->ObjectType==oArray){
      fprintf(fpOutputFile,"  {for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)\n",pSym->Object->nSize/pSym->Object->pType->nSize);
      fprintf(fpOutputFile,"     if (%s[EASEA_Ndx]!=genome.%s[EASEA_Ndx]) return 0;}\n",pSym->Object->sName,pSym->Object->sName);
moh_lo's avatar
moh_lo committed
904
    }
905 906 907 908 909 910
    else if( pSym->Object->ObjectType==oArrayPointer ){ 
      // here we handle array of pointer (developped for Tree GP)
      fprintf(fpOutputFile,"    for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)\n",pSym->Object->nSize/sizeof(char*));
      fprintf(fpOutputFile,"      if(%s[EASEA_Ndx] != genome.%s[EASEA_Ndx]) return 0;\n",pSym->Object->sName,pSym->Object->sName,pSym->Object->pType->sName,pSym->Object->sName);
    }
    
maitre's avatar
maitre committed
911 912
  }
 }
moh_lo's avatar
moh_lo committed
913
<TEMPLATE_ANALYSIS>"\\COMPARE"  {
maitre's avatar
maitre committed
914 915 916 917 918 919 920 921 922 923 924 925
  CListItem<CSymbol*> *pSym;
  if (bVERBOSE) printf ("Creating default genome comparator.\n");
  fprintf (fpOutputFile,"// Default genome comparator (required by GALib)\n");             
  pGENOME->pSymbolList->reset();
  while (pSym=pGENOME->pSymbolList->walkToNextItem()) {
    if (pSym->Object->ObjectType==oObject)
      fprintf(fpOutputFile,"  if (sis.%s!=bro.%s) diff++;\n",pSym->Object->sName,pSym->Object->sName);
    if (pSym->Object->ObjectType==oPointer)
      fprintf(fpOutputFile,"  if (*(sis.%s)!=*(bro.%s)) diff++;\n",pSym->Object->sName,pSym->Object->sName);
    if (pSym->Object->ObjectType==oArray){
      fprintf(fpOutputFile,"  {for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)\n",pSym->Object->nSize/pSym->Object->pType->nSize);
      fprintf(fpOutputFile,"     if (sis.%s[EASEA_Ndx]!=bro.%s[EASEA_Ndx]) diff++;}\n",pSym->Object->sName,pSym->Object->sName);
moh_lo's avatar
moh_lo committed
926
    }
maitre's avatar
maitre committed
927 928
  }
 }
moh_lo's avatar
moh_lo committed
929
<TEMPLATE_ANALYSIS>"\\READ"  {
maitre's avatar
maitre committed
930 931 932 933 934 935 936 937 938 939 940 941 942 943
  CListItem<CSymbol*> *pSym;
  if (bVERBOSE) printf ("Creating default read command.\n");
  fprintf (fpOutputFile,"// Default read command\n");             
  pGENOME->pSymbolList->reset();
  while (pSym=pGENOME->pSymbolList->walkToNextItem()){
    if (pSym->Object->ObjectQualifier==1) continue; // 1=Static
  }
 }
<TEMPLATE_ANALYSIS>"\\INSERT_DISPLAY"  {        
  if (bVERBOSE) printf ("Inserting genome display function.\n");
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  BEGIN COPY_DISPLAY;   
 }
944 945 946 947 948 949 950 951 952


<TEMPLATE_ANALYSIS>"\\INSERT_MAKEFILE_OPTION" {
  if( bVERBOSE ) printf("Inserting user LDFLAGS.\n");
  yyreset();
  yyin = fpGenomeFile;
  BEGIN COPY_MAKEFILE_OPTION;
 }

moh_lo's avatar
moh_lo committed
953
<TEMPLATE_ANALYSIS>"\\WRITE"  {
maitre's avatar
maitre committed
954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969
  CListItem<CSymbol*> *pSym;
  if (!bDisplayFunction){
    if (bVERBOSE) printf ("*** Creating default display function. ***\n");
    fprintf (fpOutputFile,"// Default display function\n");
    pGENOME->pSymbolList->reset();
    while (pSym=pGENOME->pSymbolList->walkToNextItem()){
      if (pSym->Object->ObjectQualifier==1) continue; // 1=Static
	if (pSym->Object->ObjectType==oObject){
	  if (bDisplayFunction) printf("//");
	}
	if (pSym->Object->ObjectType==oArray){
	  if (bDisplayFunction) printf("//");
	  if (bDisplayFunction) printf("//");
	  fprintf(fpOutputFile,"   for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)\n",pSym->Object->nSize/pSym->Object->pType->nSize);
	  if (bDisplayFunction) printf("//");
	  if (bDisplayFunction) printf("//");
maitre's avatar
maitre committed
970
	  fprintf(fpOutputFile,"  os << \"\\n\";\n",pSym->Object->sName);
maitre's avatar
maitre committed
971 972 973 974 975 976 977
	}         
	if (pSym->Object->ObjectType==oPointer){
	  if (bDisplayFunction) printf("//");
	}
    }
  }                      
 }    
moh_lo's avatar
moh_lo committed
978
<TEMPLATE_ANALYSIS>"\\INSERT_USER_FUNCTIONS"  {
maitre's avatar
maitre committed
979 980
  if (bVERBOSE) printf ("Inserting user functions.\n");
  yyreset();
981
  yyin = fpGenomeFile;                    
982
  lineCounter=2;                                 // switch to .ez file and analyser
maitre's avatar
maitre committed
983
  BEGIN COPY_USER_FUNCTIONS;
moh_lo's avatar
moh_lo committed
984
 }
moh_lo's avatar
moh_lo committed
985
<TEMPLATE_ANALYSIS>"\\INSERT_EO_INITIALISER"  {        
moh_lo's avatar
moh_lo committed
986
  yyreset();
maitre's avatar
maitre committed
987
  bWithinEO_Function=1;
988
  lineCounter=1;
989
  if( TARGET==CUDA || TARGET==STD) bWithinCUDA_Initializer = 1;
maitre's avatar
maitre committed
990 991
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  BEGIN COPY_EO_INITIALISER;                               // not implemented as a function !
moh_lo's avatar
moh_lo committed
992
 }
maitre's avatar
maitre committed
993

moh_lo's avatar
moh_lo committed
994
<TEMPLATE_ANALYSIS>"\\INSERT_INITIALISER"  {        
maitre's avatar
maitre committed
995 996
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
Ogier Maitre's avatar
Ogier Maitre committed
997
  lineCounter = 1;
maitre's avatar
maitre committed
998 999 1000 1001 1002 1003 1004
  BEGIN COPY_INITIALISER;   
 }

<TEMPLATE_ANALYSIS>"\\INSERT_FINALIZATION_FUNCTION"  {
  if (bVERBOSE) printf ("Inserting Finalization function.\n");
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
Ogier Maitre's avatar
Ogier Maitre committed
1005
  lineCounter=1;
maitre's avatar
maitre committed
1006 1007 1008
  BEGIN COPY_FINALIZATION_FUNCTION;
 }

moh_lo's avatar
moh_lo committed
1009
<TEMPLATE_ANALYSIS>"\\INSERT_CROSSOVER"  {        
maitre's avatar
maitre committed
1010 1011
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
1012
  lineCounter=1;
maitre's avatar
maitre committed
1013 1014
  BEGIN COPY_CROSSOVER;   
 }
moh_lo's avatar
moh_lo committed
1015
<TEMPLATE_ANALYSIS>"\\INSERT_MUTATOR"  {        
maitre's avatar
maitre committed
1016 1017
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
1018
  lineCounter=1;
maitre's avatar
maitre committed
1019 1020
  BEGIN COPY_MUTATOR;   
 }
moh_lo's avatar
moh_lo committed
1021
<TEMPLATE_ANALYSIS>"\\INSERT_EVALUATOR"  {        
maitre's avatar
maitre committed
1022 1023
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
1024
  lineCounter=1;
maitre's avatar
maitre committed
1025 1026
  BEGIN COPY_EVALUATOR;   
 }
1027 1028
<TEMPLATE_ANALYSIS>"\\INSERT_OPTIMISER"  {      
  if( bVERBOSE ) fprintf(stdout,"Inserting optimization function\n");
kruger's avatar
kruger committed
1029 1030
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
1031
  lineCounter=1;
kruger's avatar
kruger committed
1032 1033
  BEGIN COPY_OPTIMISER;   
 }
maitre's avatar
maitre committed
1034 1035 1036 1037
<TEMPLATE_ANALYSIS>"\\INSERT_CUDA_EVALUATOR"  {        
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  bWithinCUDA_Evaluator = 1;
1038
  lineCounter=1;
maitre's avatar
maitre committed
1039 1040
  BEGIN COPY_EVALUATOR;
 }
1041 1042
<TEMPLATE_ANALYSIS>"\\INSERT_CUDA_OPTIMISOR"  { 
  if( bVERBOSE ) fprintf(stdout,"Inserting cuda optimization function\n");
1043 1044 1045 1046 1047 1048
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  bWithinCUDA_Evaluator = 1;
  lineCounter=1;
  BEGIN COPY_OPTIMISER;
 }
maitre's avatar
maitre committed
1049

moh_lo's avatar
moh_lo committed
1050
<TEMPLATE_ANALYSIS>"\\ANALYSE_PARAMETERS"  {        
maitre's avatar
maitre committed
1051 1052 1053 1054
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  BEGIN PARAMETERS_ANALYSIS;   
 }
moh_lo's avatar
moh_lo committed
1055
<TEMPLATE_ANALYSIS>"\\INSERT_GEN_FCT_CALL"  {
maitre's avatar
maitre committed
1056
  if (bGenerationReplacementFunction) {
1057
    if( bVERBOSE ) fprintf(stdout,"Inserting generation function call\n");
1058 1059 1060 1061
    if( TARGET==CUDA || TARGET==STD ){
      fprintf(fpOutputFile,"\n\tEASEAGenerationFunction(this);");
    }
  }
1062
 }     
maitre's avatar
maitre committed
1063

1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082
<TEMPLATE_ANALYSIS>"\\INSERT_END_GEN_FCT_CALL"  {
  if( bEndGenerationFunction ) {
    if( bVERBOSE ) fprintf(stdout,"Inserting end generation function call\n");
    if( TARGET==CUDA || TARGET==STD ){
      fprintf(fpOutputFile,"\n\tEASEAEndGenerationFunction(this);");
    }
  }
 }     

<TEMPLATE_ANALYSIS>"\\INSERT_BEGINNING_GEN_FCT_CALL"  {
  if( bBeginGenerationFunction ) {
    if( bVERBOSE ) fprintf(stdout,"Inserting beginning generation function call\n");
    if( TARGET==CUDA || TARGET==STD ){
      fprintf(fpOutputFile,"\n\tEASEABeginningGenerationFunction(this);");
    }
  }
 }     


maitre's avatar
maitre committed
1083 1084 1085 1086 1087 1088 1089 1090
<TEMPLATE_ANALYSIS>"\\INSERT_BOUND_CHECKING_FCT_CALL"  {
  if (bBoundCheckingFunction) {
    if( TARGET==CUDA || TARGET==STD ){
      fprintf(fpOutputFile,"\n\tEASEABoundChecking(this);");
    }
  }
 }        

maitre's avatar
maitre committed
1091 1092 1093 1094 1095 1096 1097 1098
<TEMPLATE_ANALYSIS>"\\IS_PARENT_REDUCTION" {
    fprintf(fpOutputFile,"%d",bIsParentReduce);
 }

<TEMPLATE_ANALYSIS>"\\IS_OFFSPRING_REDUCTION" {
  fprintf(fpOutputFile,"%d",bIsOffspringReduce);
 }

moh_lo's avatar
moh_lo committed
1099
<TEMPLATE_ANALYSIS>"\\INSERT_INIT_FCT_CALL"  {
maitre's avatar
maitre committed
1100
  if (bInitFunction) fprintf(fpOutputFile,"\n  EASEAInitFunction(argc, argv);\n");
moh_lo's avatar
moh_lo committed
1101
 }
maitre's avatar
maitre committed
1102 1103 1104 1105 1106 1107

<TEMPLATE_ANALYSIS>"\\INSERT_FINALIZATION_FCT_CALL"  {
  if (bFinalizationFunction) fprintf(fpOutputFile,"\n  EASEAFinalization(pop);\n");
 }        

<TEMPLATE_ANALYSIS>"\\INSERT_USER_CLASSES_DEFINITIONS"  {
kruger's avatar
kruger committed
1108
  //DEBUG_PRT_PRT("Inserting user classe definitions");
maitre's avatar
maitre committed
1109 1110 1111 1112
  pGENOME->printUserClasses(fpOutputFile);
 }        

<TEMPLATE_ANALYSIS>"\\SELECTOR"  {
1113
  if( TARGET==CUDA || TARGET==STD){
kruger's avatar
kruger committed
1114
    //DEBUG_PRT_PRT("Selector is \"%s\" | Goal is %s",sSELECTOR,(nMINIMISE?"Minimize":"Maximize"));
maitre's avatar
maitre committed
1115 1116
    char* selectorClass = selectorDetermination(nMINIMISE,sSELECTOR);
    if( !selectorClass ){
1117
      fprintf(stderr,"Error %d : selection operator %s doesn't exist in CUDA/STD template\n",yylineno,sSELECTOR);
maitre's avatar
maitre committed
1118 1119
      return -1;
    }    
kruger's avatar
kruger committed
1120
    //DEBUG_PRT_PRT("Created class is %s",selectorClass);
maitre's avatar
maitre committed
1121 1122 1123 1124
    fprintf(fpOutputFile,"%s",selectorClass);
  }
  else fprintf(fpOutputFile,"%s",sSELECTOR);
}
maitre's avatar
maitre committed
1125 1126 1127 1128 1129 1130 1131 1132
<TEMPLATE_ANALYSIS>"\\SELECTOR_OPERATOR" {fprintf(fpOutputFile,"%s",sSELECTOR_OPERATOR);}
<TEMPLATE_ANALYSIS>"\\SELECT_PRM"  {fprintf(fpOutputFile,"%f",fSELECT_PRM);}
<TEMPLATE_ANALYSIS>"\\RED_PAR_OPERATOR" {fprintf(fpOutputFile,"%s",sRED_PAR_OPERATOR);}
<TEMPLATE_ANALYSIS>"\\RED_PAR_PRM"  {fprintf(fpOutputFile,"%f",fRED_PAR_PRM);}
<TEMPLATE_ANALYSIS>"\\RED_OFF_OPERATOR" {fprintf(fpOutputFile,"%s",sRED_OFF_OPERATOR);}
<TEMPLATE_ANALYSIS>"\\RED_OFF_PRM"  {fprintf(fpOutputFile,"%f",fRED_OFF_PRM);}
<TEMPLATE_ANALYSIS>"\\RED_FINAL_OPERATOR" {fprintf(fpOutputFile,"%s",sRED_FINAL_OPERATOR);}
<TEMPLATE_ANALYSIS>"\\RED_FINAL_PRM"  {fprintf(fpOutputFile,"%f",fRED_FINAL_PRM);}
moh_lo's avatar
moh_lo committed
1133 1134
<TEMPLATE_ANALYSIS>"\\POP_SIZE"  {fprintf(fpOutputFile,"%d",nPOP_SIZE);}
<TEMPLATE_ANALYSIS>"\\OFF_SIZE"  {fprintf(fpOutputFile,"%d",nOFF_SIZE);}
maitre's avatar
maitre committed
1135 1136
<TEMPLATE_ANALYSIS>"\\ELITE_SIZE"  {
  fprintf(fpOutputFile,"%d",nELITE);
kruger's avatar
kruger committed
1137
  ////DEBUG_PRT_PRT("elitism is %d, elite size is %d",bELITISM, nELITE);
maitre's avatar
maitre committed
1138 1139
 }

maitre's avatar
maitre committed
1140 1141
<TEMPLATE_ANALYSIS>"\\RED_PAR"  {
  if( TARGET==CUDA || TARGET==STD){
kruger's avatar
kruger committed
1142
    //DEBUG_PRT_PRT("Parent reduction is \"%s\" | Goal is %s",sSELECTOR,(nMINIMISE?"Minimize":"Maximize"));
maitre's avatar
maitre committed
1143 1144 1145 1146 1147
    char* selectorClass = selectorDetermination(nMINIMISE,sSELECTOR);
    if( !selectorClass ){
      fprintf(stderr,"Error %d : selection operator %s doesn't exist in CUDA/STD template\n",yylineno,sSELECTOR);
      return -1;
    }    
kruger's avatar
kruger committed
1148
    //DEBUG_PRT_PRT("Created class is %s",selectorClass);
maitre's avatar
maitre committed
1149 1150 1151 1152 1153 1154
    fprintf(fpOutputFile,"%s",selectorClass);
  }
  else fprintf(fpOutputFile,"%s",sRED_PAR);
 }
<TEMPLATE_ANALYSIS>"\\RED_OFF"  {
  if( TARGET==CUDA || TARGET==STD){
kruger's avatar
kruger committed
1155
    //DEBUG_PRT_PRT("Offspring reduction is \"%s\" | Goal is %s",sSELECTOR,(nMINIMISE?"Minimize":"Maximize"));
maitre's avatar
maitre committed
1156 1157 1158 1159 1160
    char* selectorClass = selectorDetermination(nMINIMISE,sSELECTOR);
    if( !selectorClass ){
      fprintf(stderr,"Error %d : selection operator %s doesn't exist in CUDA/STD template\n",yylineno,sSELECTOR);
      return -1;
    }    
kruger's avatar
kruger committed
1161
    //DEBUG_PRT_PRT("Created class is %s",selectorClass);
maitre's avatar
maitre committed
1162 1163 1164 1165
    fprintf(fpOutputFile,"%s",selectorClass);
  }
  else fprintf(fpOutputFile,"%s",sRED_OFF);
 }
maitre's avatar
maitre committed
1166
<TEMPLATE_ANALYSIS>"\\RED_FINAL"  {
1167
  if( TARGET==CUDA || TARGET==STD){
kruger's avatar
kruger committed
1168
    //DEBUG_PRT_PRT("Replacement selector is \"%s\" | Goal is %s",sRED_FINAL,(nMINIMISE?"Minimize":"Maximize"));
maitre's avatar
maitre committed
1169 1170
    char* selectorClass = selectorDetermination(nMINIMISE,sRED_FINAL);
    if( !selectorClass ){
1171
      fprintf(stderr,"Error %d : replacement operator %s doesn't exist in CUDA/TPL template\n",yylineno,sRED_FINAL);
maitre's avatar
maitre committed
1172 1173
      return -1;
    }    
kruger's avatar
kruger committed
1174
    //DEBUG_PRT_PRT("Created class is %s",selectorClass);
maitre's avatar
maitre committed
1175 1176 1177 1178
    fprintf(fpOutputFile,"%s",selectorClass);
  }
  else fprintf(fpOutputFile,"%s",sRED_FINAL);
 }
kruger's avatar
kruger committed
1179 1180 1181 1182
<TEMPLATE_ANALYSIS>"\\CUDA_RULE_DIR"  {
if(OPERATING_SYSTEM=WINDOWS)
	fprintf(fpOutputFile,"%s\\",getenv("NVSDKCUDA_ROOT"));
}
maitre's avatar
maitre committed
1183 1184
<TEMPLATE_ANALYSIS>"\\SURV_PAR_SIZE"  {if(fSURV_PAR_SIZE>=0.0)fprintf(fpOutputFile,"%f",fSURV_PAR_SIZE); else fprintf(fpOutputFile,"%f",(float)nPOP_SIZE);}
<TEMPLATE_ANALYSIS>"\\SURV_OFF_SIZE"  {if(fSURV_OFF_SIZE>=0.0)fprintf(fpOutputFile,"%f",fSURV_OFF_SIZE); else fprintf(fpOutputFile,"%f",(float)nOFF_SIZE);}
Frederic's avatar
Frederic committed
1185 1186
<TEMPLATE_ANALYSIS>"\\GENOME_NAME"  {fprintf(fpOutputFile,"%s",nGENOME_NAME);}
<TEMPLATE_ANALYSIS>"\\PROBLEM_DIM"  {fprintf(fpOutputFile,"%d",nPROBLEM_DIM);}
moh_lo's avatar
moh_lo committed
1187
<TEMPLATE_ANALYSIS>"\\NB_GEN"  {fprintf(fpOutputFile,"%d",nNB_GEN);}
maitre's avatar
maitre committed
1188 1189 1190
<TEMPLATE_ANALYSIS>"\\TIME_LIMIT" {fprintf(fpOutputFile,"%d",nTIME_LIMIT);}
<TEMPLATE_ANALYSIS>"\\MUT_PROB"  {fprintf(fpOutputFile,"%f",fMUT_PROB);}
<TEMPLATE_ANALYSIS>"\\XOVER_PROB"  {fprintf(fpOutputFile,"%f",fXOVER_PROB);}
kruger's avatar
kruger committed
1191 1192
<TEMPLATE_ANALYSIS>"\\MINIMAXI"  {fprintf(fpOutputFile,"%s",(nMINIMISE? "true" : "false")); }
<TEMPLATE_ANALYSIS>"\\ELITISM"  {fprintf(fpOutputFile,"%d",bELITISM);}
kruger's avatar
kruger committed
1193

kruger's avatar
kruger committed
1194 1195
<TEMPLATE_ANALYSIS>"\\NB_OPT_IT"  {fprintf(fpOutputFile,"%d",nNB_OPT_IT);}
<TEMPLATE_ANALYSIS>"\\BALDWINISM" {fprintf(fpOutputFile,"%d",bBALDWINISM);}
maitre's avatar
maitre committed
1196

kruger's avatar
kruger committed
1197
<TEMPLATE_ANALYSIS>"\\REMOTE_ISLAND_MODEL" {fprintf(fpOutputFile,"%d",bREMOTE_ISLAND_MODEL);}
kruger's avatar
kruger committed
1198
<TEMPLATE_ANALYSIS>"\\IP_FILE" {if(strlen(sIP_FILE)>0)fprintf(fpOutputFile,"%s",sIP_FILE); else fprintf(fpOutputFile,"NULL");}
1199
<TEMPLATE_ANALYSIS>"\\MIGRATION_PROBABILITY" {fprintf(fpOutputFile,"%f",fMIGRATION_PROBABILITY);}
kruger's avatar
kruger committed
1200

maitre's avatar
maitre committed
1201 1202
<TEMPLATE_ANALYSIS>"\\PRINT_STATS" {fprintf(fpOutputFile,"%d",bPRINT_STATS);}
<TEMPLATE_ANALYSIS>"\\PLOT_STATS" {fprintf(fpOutputFile,"%d",bPLOT_STATS);}
kruger's avatar
kruger committed
1203
<TEMPLATE_ANALYSIS>"\\GENERATE_CSV_FILE" {fprintf(fpOutputFile,"%d",bGENERATE_CSV_FILE);}
maitre's avatar
maitre committed
1204 1205
<TEMPLATE_ANALYSIS>"\\GENERATE_GNUPLOT_SCRIPT" {fprintf(fpOutputFile,"%d",bGENERATE_GNUPLOT_SCRIPT);}
<TEMPLATE_ANALYSIS>"\\GENERATE_R_SCRIPT" {fprintf(fpOutputFile,"%d",bGENERATE_R_SCRIPT);}
1206

kruger's avatar
kruger committed
1207 1208 1209
<TEMPLATE_ANALYSIS>"\\SAVE_POPULATION" {fprintf(fpOutputFile,"%d",bSAVE_POPULATION);}
<TEMPLATE_ANALYSIS>"\\START_FROM_FILE" {fprintf(fpOutputFile,"%d",bSTART_FROM_FILE);}

maitre's avatar
maitre committed
1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221
<TEMPLATE_ANALYSIS>"\\START_CUDA_GENOME_H_TPL"  {
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,"Individual.hpp");
  fpOutputFile=fopen(sFileName,"w");    
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
 }
<TEMPLATE_ANALYSIS>"\\START_CUDA_GENOME_CU_TPL"  {
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
1222 1223 1224
  if( TARGET==CUDA )
    strcat(sFileName,"Individual.cu");
  else if( TARGET==STD )
1225 1226 1227 1228
    if( TARGET_FLAVOR==CUDA_FLAVOR_GP )
      strcat(sFileName,"Individual.cu");
    else
      strcat(sFileName,"Individual.cpp");
maitre's avatar
maitre committed
1229 1230 1231
  fpOutputFile=fopen(sFileName,"w");    
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
 }
moh_lo's avatar
moh_lo committed
1232
<TEMPLATE_ANALYSIS>"\\START_EO_PARAM_TPL"  {
maitre's avatar
maitre committed
1233 1234 1235 1236 1237 1238 1239
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,".prm");
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
  fpOutputFile=fopen(sFileName,"w");
 }
moh_lo's avatar
moh_lo committed
1240
<TEMPLATE_ANALYSIS>"\\START_EO_MAKEFILE_TPL"  {
maitre's avatar
maitre committed
1241 1242 1243 1244 1245 1246 1247 1248
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,".mak");
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
  fpOutputFile=fopen(sFileName,"w");
 }

kruger's avatar
kruger committed
1249 1250 1251 1252 1253 1254 1255 1256 1257
<TEMPLATE_ANALYSIS>"\\START_VISUAL_TPL"  {
  char sFileName[1000];
 fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,".vcproj");
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
  fpOutputFile=fopen(sFileName,"w");
 }

maitre's avatar
maitre committed
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271
<TEMPLATE_ANALYSIS>"\\START_CUDA_MAKEFILE_TPL"  {
  char sFileName[1000];
  char sPathName[1000];
  char sFullFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,".mak");

  // get the path without fillename
  int fileNameLength = -1;
  for( int i=strlen(sRAW_PROJECT_NAME) ; i>=0 ; i-- )
    if( sRAW_PROJECT_NAME[i] == '/' ){
      fileNameLength = i;
      break;
moh_lo's avatar
moh_lo committed
1272
    }
maitre's avatar
maitre committed
1273 1274
  if( fileNameLength != -1 ){
    // add "Makefile" at the end of path
1275
    //char* cdn = get_current_dir_name();
kruger's avatar
kruger committed
1276 1277 1278 1279
    char cdn[4096];
    #ifdef WIN32 
    _getcwd(cdn,4096);
    #else
1280
    getcwd(cdn,4096);
kruger's avatar
kruger committed
1281
    #endif
maitre's avatar
maitre committed
1282 1283 1284 1285 1286 1287 1288 1289
    size_t cdnLength = strlen(cdn);
    strcpy(sFullFileName,cdn);
    strcat(sFullFileName,"/\0");
    strcat(sFullFileName,sFileName);
    
    strncpy(sPathName,sRAW_PROJECT_NAME,fileNameLength);
    strcpy(sPathName+fileNameLength,"/Makefile");
    
kruger's avatar
kruger committed
1290 1291
    //DEBUG_PRT_PRT("PathName is %s",sPathName);
    //DEBUG_PRT_PRT("FullFileName is %s",sFullFileName);
maitre's avatar
maitre committed
1292 1293 1294
    
  
    // create a symbolic link from Makefile to EASEA.mak
maitre's avatar
maitre committed
1295
#ifndef WIN32
maitre's avatar
maitre committed
1296
    symlink(sFullFileName,sPathName);
maitre's avatar
maitre committed
1297
#endif
maitre's avatar
maitre committed
1298
  }
maitre's avatar
maitre committed
1299
  else{
kruger's avatar
kruger committed
1300
    //DEBUG_PRT_PRT("file name : %s",sFileName);
maitre's avatar
maitre committed
1301
#ifndef WIN32
maitre's avatar
maitre committed
1302
    if( symlink(sFileName,"Makefile") ) perror("Symlink creation error ");
maitre's avatar
maitre committed
1303
#endif
maitre's avatar
maitre committed
1304
  }
maitre's avatar
maitre committed
1305 1306 1307 1308 1309 1310 1311 1312 1313
  if (bVERBOSE){
    printf("Creating %s...\n",sFileName);
    printf("Creating %s symbolic link...\n",sPathName);
  }
  fpOutputFile=fopen(sFileName,"w");
  if( !fpOutputFile ) {
    fprintf(stderr,"Error in %s creation\n",sFileName);
    exit(-1);
  }
kruger's avatar
kruger committed
1314
}
moh_lo's avatar
moh_lo committed
1315
<TEMPLATE_ANALYSIS>"\\TEMPLATE_END"  {
maitre's avatar
maitre committed
1316
  if (nWARNINGS) printf ("\nWARNING !!!\nTarget file(s) generation went through WITH %d WARNING(S) !\n",nWARNINGS);
1317 1318
  else printf ("\nCONGRATULATIONS !!!\nTarget file(s) generation succeeded without warnings.\n");
  printf ("You can now type \"make\" to compile your project.\n");
maitre's avatar
maitre committed
1319
  if (TARGET==CUDA || TARGET==STD) fprintf(fpOutputFile,"\n# That's all folks ! \n");
maitre's avatar
maitre committed
1320 1321 1322 1323 1324 1325
  else fprintf(fpOutputFile,"\n// That's all folks ! \n");
  fflush(fpOutputFile);
  fclose(fpOutputFile);
  fclose(fpTemplateFile);
  fclose(fpGenomeFile);
 }
moh_lo's avatar
moh_lo committed
1326 1327 1328 1329 1330 1331 1332 1333

<TEMPLATE_ANALYSIS>.|\n {putc(yytext[0],fpOutputFile);}                                      

//****************************************
//  use information found in .ez file
//****************************************

<COPY_EO_INITIALISER>"\\GenomeClass::initiali"[sz]"er"[ \t\n]*":" {
maitre's avatar
maitre committed
1334
  fprintf (fpOutputFile,"// Genome Initialiser\n"); 
1335 1336
  if( bLINE_NUM_EZ_FILE )
    fprintf(fpOutputFile,"#line %d \"%s.ez\"\n",lineCounter, sRAW_PROJECT_NAME);