EaseaLex.l 78.1 KB
Newer Older
1

moh_lo's avatar
moh_lo committed
2
%{
kruger's avatar
kruger committed
3
/****************************************************************************
moh_lo's avatar
moh_lo committed
4 5 6 7 8 9 10
EaseaLex.l
Lexical analyser for the EASEA language (EAsy Specification for Evolutionary Algorithms)

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

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

maitre's avatar
maitre committed
29
  // local functions
maitre's avatar
maitre committed
30 31 32 33 34 35 36 37 38 39
  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
40
  if( mystricmp("Tournament",sSELECTOR)==0 )
maitre's avatar
maitre committed
41 42 43
    strcat(selectorName,"Tournament(globalRandomGenerator)");
  else if( mystricmp("dettour",sSELECTOR)==0 )
    strcat(selectorName,"Tournament(globalRandomGenerator)");
maitre's avatar
maitre committed
44 45 46
  else if( mystricmp("Deterministic",sSELECTOR)==0 )
    strcat(selectorName,"Deterministic()");
  else if( mystricmp("deterministic",sSELECTOR)==0 )
47 48 49
    strcat(selectorName,"Deterministic()");
  else if( mystricmp("Random",sSELECTOR)==0 )
    strcat(selectorName,"Random(globalRandomGenerator)");
50 51
  else if( mystricmp("Roulette",sSELECTOR)==0 )
    strcat(selectorName,"Roulette(globalRandomGenerator)");
52

53
  else{
kruger's avatar
kruger committed
54
    //DEBUG_PRT_PRT("%s is not yet implemented",sSELECTOR);
55 56
    return NULL;
  }
maitre's avatar
maitre committed
57 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 71
  // forward references
  class CEASEAParser;
  class CSymbolTable;
 }                                                     
moh_lo's avatar
moh_lo committed
72 73 74 75
                                         
%start GENOME_ANALYSIS TEMPLATE_ANALYSIS MACRO_IDENTIFIER MACRO_DEFINITION 
%start COPY_USER_DECLARATIONS COPY_INITIALISATION_FUNCTION ANALYSE_USER_CLASSES
%start COPY_EO_INITIALISER 
maitre's avatar
maitre committed
76
%start COPY COPY_INITIALISER COPY_CROSSOVER COPY_MUTATOR COPY_EVALUATOR COPY_FINALIZATION_FUNCTION
moh_lo's avatar
moh_lo committed
77
%start COPY_DISPLAY COPY_USER_FUNCTION COPY_USER_GENERATION PARAMETERS_ANALYSIS GET_PARAMETERS 
maitre's avatar
maitre committed
78
%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
moh_lo's avatar
moh_lo committed
79

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

maitre's avatar
maitre committed
93
 public:
moh_lo's avatar
moh_lo committed
94 95 96
  int create(CEASEAParser* pParser, CSymbolTable* pSymbolTable);
  int yywrap();
  double myStrtod() const;                              
maitre's avatar
maitre committed
97
 }
moh_lo's avatar
moh_lo committed
98 99 100

// constructor
{                                
moh_lo's avatar
moh_lo committed
101
  bFunction=bWithinEvaluator=bDisplayFunction=bInitFunction=bNotFinishedYet=0;
maitre's avatar
maitre committed
102
  bSymbolInserted=bDoubleQuotes=bWithinDisplayFunction=bWithinInitialiser=bWithinMutator=bWithinXover=0;
maitre's avatar
maitre committed
103
  bWaitingForSemiColon=bFinishNB_GEN=bFinishMINIMISE=bFinishMINIMIZE=bGenerationReplacementFunction=0;
maitre's avatar
maitre committed
104
  bCatchNextSemiColon,bWaitingToClosePopulation=bMethodsInGenome=0;
maitre's avatar
maitre committed
105
  bBoundCheckingFunction = bWithinCUDA_Initializer=bWithinMAKEFILEOPTION =bWithinCUDA_Evaluator=0;
maitre's avatar
maitre committed
106
  bIsParentReduce = bIsOffspringReduce = false;
maitre's avatar
maitre committed
107
  bGenerationFunctionBeforeReplacement = bEndGeneration = bBeginGeneration = bEndGenerationFunction = bBeginGenerationFunction = false;
moh_lo's avatar
moh_lo committed
108 109 110 111 112
}

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

maitre's avatar
maitre committed
113 114


moh_lo's avatar
moh_lo committed
115 116 117
%%                                              

%{
maitre's avatar
maitre committed
118 119 120
  // extract yylval for use later on in actions
  YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
  %}
moh_lo's avatar
moh_lo committed
121 122 123 124 125 126

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

// switch immediately to TEMPLATE_ANALYSIS state
<INITIAL>.    {
maitre's avatar
maitre committed
127 128
  BEGIN TEMPLATE_ANALYSIS; yyless(yyleng-1);
 }
moh_lo's avatar
moh_lo committed
129 130 131 132 133 134

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

<TEMPLATE_ANALYSIS>"\\TEMPLATE_START"  {             
maitre's avatar
maitre committed
135 136 137
  char sFileName[1000];
  strcpy(sFileName, sRAW_PROJECT_NAME);
  switch (TARGET) {
138
  case STD :
maitre's avatar
maitre committed
139 140 141 142 143
  case CUDA : strcat(sFileName,".cpp"); break;
  default : strcat(sFileName,".cpp");
  } 
  fpOutputFile=fopen(sFileName,"w");
 }
moh_lo's avatar
moh_lo committed
144 145 146
<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
147
<TEMPLATE_ANALYSIS>"\\TPL_DIR" {fprintf(fpOutputFile,"%s",sTPL_DIR);}
moh_lo's avatar
moh_lo committed
148 149 150
<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
151 152 153 154 155
  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
156
<TEMPLATE_ANALYSIS>"\\INSERT_USER_DECLARATIONS"  {
maitre's avatar
maitre committed
157 158
  if (bVERBOSE) printf ("Inserting user declarations.\n");
  yyreset();
159 160
  yyin = fpGenomeFile;                                                    // switch to .ez file and analyser
  lineCounter=1;
maitre's avatar
maitre committed
161 162
  BEGIN COPY_USER_DECLARATIONS;
 }
moh_lo's avatar
moh_lo committed
163
<TEMPLATE_ANALYSIS>"\\INSERT_INITIALISATION_FUNCTION"  {
maitre's avatar
maitre committed
164 165 166 167 168
  if (bVERBOSE) printf ("Inserting initialisation function.\n");
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  BEGIN COPY_INITIALISATION_FUNCTION;
 }
maitre's avatar
maitre committed
169 170 171

<TEMPLATE_ANALYSIS>"\\INSERT_GENERATION_FUNCTION_BEFORE_REPLACEMENT"  {
  if (bVERBOSE) printf ("Inserting generation before reduce function.\n");
maitre's avatar
maitre committed
172 173
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
maitre's avatar
maitre committed
174 175
  bGenerationFunctionBeforeReplacement = true;
  BEGIN COPY_GENERATION_FUNCTION_BEFORE_REPLACEMENT;
maitre's avatar
maitre committed
176
 }
maitre's avatar
maitre committed
177

maitre's avatar
maitre committed
178 179

<TEMPLATE_ANALYSIS>"\\INSERT_BEGIN_GENERATION_FUNCTION"  {
kruger's avatar
kruger committed
180
  //DEBUG_PRT_PRT("insert beg");
maitre's avatar
maitre committed
181 182 183
  if (bVERBOSE) printf ("Inserting at the begining of each generation function.\n");
  yyreset();
  yyin = fpGenomeFile;
184 185 186
  bBeginGeneration = true;
  bEndGeneration = false;
  BEGIN COPY_BEG_GENERATION_FUNCTION;
maitre's avatar
maitre committed
187 188 189
 }


maitre's avatar
maitre committed
190 191 192 193 194 195 196 197 198
<TEMPLATE_ANALYSIS>"\\INSTEAD_EVAL_FUNCTION"  {
  //DEBUG_PRT_PRT("insert beg");
  yyreset();
  yyin = fpGenomeFile;
  if (bVERBOSE) printf ("Evaluation population in a single function!!.\n");
  BEGIN COPY_INSTEAD_EVAL;
 }


maitre's avatar
maitre committed
199
<TEMPLATE_ANALYSIS>"\\INSERT_END_GENERATION_FUNCTION"  {
kruger's avatar
kruger committed
200
  //DEBUG_PRT_PRT("insert end");
maitre's avatar
maitre committed
201 202 203 204 205
  if (bVERBOSE) printf ("Inserting at the end of each generation function.\n");
  yyreset();
  yyin = fpGenomeFile;
  bEndGeneration = true;
  bBeginGeneration = false;
206
  BEGIN COPY_END_GENERATION_FUNCTION;
maitre's avatar
maitre committed
207 208 209
 }


maitre's avatar
maitre committed
210 211 212 213 214 215 216 217
<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
218
<TEMPLATE_ANALYSIS>"\\ANALYSE_USER_CLASSES"  {
maitre's avatar
maitre committed
219 220 221 222 223
  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
224

moh_lo's avatar
moh_lo committed
225
<TEMPLATE_ANALYSIS>"\\INSERT_USER_CLASSES"  {
maitre's avatar
maitre committed
226
  if (bVERBOSE) printf ("Inserting User classes.\n");
maitre's avatar
maitre committed
227
  fprintf (fpOutputFile,"// User classes\n");
maitre's avatar
maitre committed
228 229 230
  CListItem<CSymbol*> *pSym;
  pGENOME->pSymbolList->reset();
  while (pSym=pGENOME->pSymbolList->walkToNextItem())
maitre's avatar
maitre committed
231
    if ((pSym->Object->pType->ObjectType==oUserClass)&&(!pSym->Object->pType->bAlreadyPrinted)){
kruger's avatar
kruger committed
232
      //DEBUG_PRT_PRT("%p",pSym->Object->pType);
maitre's avatar
maitre committed
233
      pSym->Object->pType->printClasses(fpOutputFile);
maitre's avatar
maitre committed
234 235 236 237
    }


  if( TARGET == CUDA ){
kruger's avatar
kruger committed
238
    //DEBUG_PRT_PRT("User classes are :");
maitre's avatar
maitre committed
239
    for( int i = nClasses_nb-1 ; i>=0 ; i-- ){
kruger's avatar
kruger committed
240
      //DEBUG_PRT_PRT(" %s, %p ,%d| ",pCLASSES[i]->sName,pCLASSES[i],pCLASSES[i]->bAlreadyPrinted);
maitre's avatar
maitre committed
241 242 243 244 245
      if( !pCLASSES[i]->bAlreadyPrinted ){
	fprintf(fpOutputFile,"// User class not refereced by the Genome");
	pCLASSES[i]->printClasses(fpOutputFile);
      }
    }
kruger's avatar
kruger committed
246
    //DEBUG_PRT_PRT("\n");
maitre's avatar
maitre committed
247
  }
maitre's avatar
maitre committed
248
 }
moh_lo's avatar
moh_lo committed
249
<TEMPLATE_ANALYSIS>"\\GENOME_CTOR"  {
maitre's avatar
maitre committed
250 251 252 253 254 255
  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
256
      fprintf(fpOutputFile,"    %s=NULL;\n",pSym->Object->sName);
moh_lo's avatar
moh_lo committed
257
    }
maitre's avatar
maitre committed
258 259
  }
 }
maitre's avatar
maitre committed
260

maitre's avatar
maitre committed
261 262
<TEMPLATE_ANALYSIS>"\\GENOME_SIZE" {
  size_t size_of_genome=0;
maitre's avatar
maitre committed
263 264 265 266 267 268
  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
269
      //DEBUG_PRT_PRT("%s has size : %lu",pSym->Object->sName,pSym->Object->nSize);
maitre's avatar
maitre committed
270 271
      size_of_genome+=pSym->Object->nSize;
    }
kruger's avatar
kruger committed
272
    //DEBUG_PRT_PRT("Total genome size is %lu",size_of_genome); 
maitre's avatar
ok  
maitre committed
273
    genomeSize = size_of_genome;
maitre's avatar
maitre committed
274 275 276 277
    genomeSizeValidity=true;
  }
  else{
    size_of_genome = genomeSize;
maitre's avatar
maitre committed
278 279 280 281 282 283 284 285 286 287 288 289 290 291
  }
  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
292
      fprintf(fpOutputFile,"    %s=NULL;\n",pSym->Object->sName);
maitre's avatar
maitre committed
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
    }
  }
  
 }

/* <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
320 321 322 323 324 325

<TEMPLATE_ANALYSIS>"\\GENOME_SERIAL"  {
  CListItem<CSymbol*> *pSym;
  if (bVERBOSE) printf ("Inserting default genome serializer.\n");
  pGENOME->pSymbolList->reset();
  while (pSym=pGENOME->pSymbolList->walkToNextItem()){
kruger's avatar
kruger committed
326
    //DEBUG_PRT_PRT("found new symbol %s",pSym->Object->sName);
maitre's avatar
maitre committed
327 328 329 330
    fprintf(fpOutputFile," ar & %s;\n",pSym->Object->sName);
  }
 }

moh_lo's avatar
moh_lo committed
331
<TEMPLATE_ANALYSIS>"\\INSERT_GENOME"  {        
maitre's avatar
maitre committed
332 333 334 335 336 337 338 339
  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
340
<TEMPLATE_ANALYSIS>"\\ASSIGNMENT_OP"  {
maitre's avatar
maitre committed
341 342 343 344 345 346 347 348 349 350 351 352 353
  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
354
    }
maitre's avatar
maitre committed
355 356
  }
 }
moh_lo's avatar
moh_lo committed
357
<TEMPLATE_ANALYSIS>"\\CLONE"  {
maitre's avatar
maitre committed
358 359 360 361 362 363 364 365 366 367 368 369 370
  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
371
      }
maitre's avatar
maitre committed
372 373
  }
 }
moh_lo's avatar
moh_lo committed
374 375

<TEMPLATE_ANALYSIS>"\\COPY_CTOR"  {
maitre's avatar
maitre committed
376 377 378 379 380 381 382 383 384 385 386 387 388
  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
389
      }
390 391 392 393 394 395 396 397 398
      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
399 400
  }
 }
moh_lo's avatar
moh_lo committed
401
<TEMPLATE_ANALYSIS>"\\GENOME_DTOR"  {
maitre's avatar
maitre committed
402 403 404 405
  CListItem<CSymbol*> *pSym;
  if (bVERBOSE) printf ("Creating default destructor.\n");
  fprintf (fpOutputFile,"// Destructing pointers\n");             
  pGENOME->pSymbolList->reset();
406
  while (pSym=pGENOME->pSymbolList->walkToNextItem()){
maitre's avatar
maitre committed
407
    if (pSym->Object->ObjectType==oPointer){
maitre's avatar
maitre committed
408
      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
409
    }
410 411 412 413 414 415
    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
416
 }
417

moh_lo's avatar
moh_lo committed
418
<TEMPLATE_ANALYSIS>"\\EQUAL"  {       
maitre's avatar
maitre committed
419 420 421 422 423 424 425 426 427 428 429 430
  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
431
    }
432 433 434 435 436 437
    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
438 439
  }
 }
moh_lo's avatar
moh_lo committed
440
<TEMPLATE_ANALYSIS>"\\COMPARE"  {
maitre's avatar
maitre committed
441 442 443 444 445 446 447 448 449 450 451 452
  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
453
    }
maitre's avatar
maitre committed
454 455
  }
 }
moh_lo's avatar
moh_lo committed
456
<TEMPLATE_ANALYSIS>"\\READ"  {
maitre's avatar
maitre committed
457 458 459 460 461 462 463 464 465 466 467 468 469 470
  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;   
 }
471 472 473 474 475 476 477 478 479


<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
480
<TEMPLATE_ANALYSIS>"\\WRITE"  {
maitre's avatar
maitre committed
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
  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
497
	  fprintf(fpOutputFile,"  os << \"\\n\";\n",pSym->Object->sName);
maitre's avatar
maitre committed
498 499 500 501 502 503 504
	}         
	if (pSym->Object->ObjectType==oPointer){
	  if (bDisplayFunction) printf("//");
	}
    }
  }                      
 }    
moh_lo's avatar
moh_lo committed
505
<TEMPLATE_ANALYSIS>"\\INSERT_USER_FUNCTIONS"  {
maitre's avatar
maitre committed
506 507
  if (bVERBOSE) printf ("Inserting user functions.\n");
  yyreset();
508
  yyin = fpGenomeFile;                    
maitre's avatar
maitre committed
509
  lineCounter=2;                                 // switch to .ez file and analyser
maitre's avatar
maitre committed
510
  BEGIN COPY_USER_FUNCTIONS;
moh_lo's avatar
moh_lo committed
511
 }
moh_lo's avatar
moh_lo committed
512
<TEMPLATE_ANALYSIS>"\\INSERT_EO_INITIALISER"  {        
moh_lo's avatar
moh_lo committed
513
  yyreset();
maitre's avatar
maitre committed
514
  bWithinEO_Function=1;
515
  lineCounter=1;
516
  if( TARGET==CUDA || TARGET==STD) bWithinCUDA_Initializer = 1;
maitre's avatar
maitre committed
517 518
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  BEGIN COPY_EO_INITIALISER;                               // not implemented as a function !
moh_lo's avatar
moh_lo committed
519
 }
maitre's avatar
maitre committed
520

moh_lo's avatar
moh_lo committed
521
<TEMPLATE_ANALYSIS>"\\INSERT_INITIALISER"  {        
maitre's avatar
maitre committed
522 523 524 525 526 527 528 529 530 531 532 533
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  BEGIN COPY_INITIALISER;   
 }

<TEMPLATE_ANALYSIS>"\\INSERT_FINALIZATION_FUNCTION"  {
  if (bVERBOSE) printf ("Inserting Finalization function.\n");
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  BEGIN COPY_FINALIZATION_FUNCTION;
 }

moh_lo's avatar
moh_lo committed
534
<TEMPLATE_ANALYSIS>"\\INSERT_CROSSOVER"  {        
maitre's avatar
maitre committed
535 536
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
537
  lineCounter=1;
maitre's avatar
maitre committed
538 539
  BEGIN COPY_CROSSOVER;   
 }
moh_lo's avatar
moh_lo committed
540
<TEMPLATE_ANALYSIS>"\\INSERT_MUTATOR"  {        
maitre's avatar
maitre committed
541 542
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
maitre's avatar
maitre committed
543
  lineCounter=1;
maitre's avatar
maitre committed
544 545
  BEGIN COPY_MUTATOR;   
 }
moh_lo's avatar
moh_lo committed
546
<TEMPLATE_ANALYSIS>"\\INSERT_EVALUATOR"  {        
maitre's avatar
maitre committed
547 548
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
maitre's avatar
maitre committed
549
  lineCounter=1;
maitre's avatar
maitre committed
550 551
  BEGIN COPY_EVALUATOR;   
 }
maitre's avatar
maitre committed
552 553 554 555 556

<TEMPLATE_ANALYSIS>"\\INSERT_CUDA_EVALUATOR"  {        
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  bWithinCUDA_Evaluator = 1;
maitre's avatar
maitre committed
557
  lineCounter=1;
maitre's avatar
maitre committed
558 559 560
  BEGIN COPY_EVALUATOR;
 }

moh_lo's avatar
moh_lo committed
561
<TEMPLATE_ANALYSIS>"\\ANALYSE_PARAMETERS"  {        
maitre's avatar
maitre committed
562 563 564 565
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  BEGIN PARAMETERS_ANALYSIS;   
 }
moh_lo's avatar
moh_lo committed
566
<TEMPLATE_ANALYSIS>"\\INSERT_GEN_FCT_CALL"  {
maitre's avatar
maitre committed
567
  if (bGenerationReplacementFunction) {
568
    if( bVERBOSE ) fprintf(stdout,"Inserting generation function call\n");
569 570 571 572
    if( TARGET==CUDA || TARGET==STD ){
      fprintf(fpOutputFile,"\n\tEASEAGenerationFunction(this);");
    }
  }
573
 }     
maitre's avatar
maitre committed
574

575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
<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
594 595 596 597 598 599 600 601
<TEMPLATE_ANALYSIS>"\\INSERT_BOUND_CHECKING_FCT_CALL"  {
  if (bBoundCheckingFunction) {
    if( TARGET==CUDA || TARGET==STD ){
      fprintf(fpOutputFile,"\n\tEASEABoundChecking(this);");
    }
  }
 }        

maitre's avatar
maitre committed
602 603 604 605 606 607 608 609
<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
610
<TEMPLATE_ANALYSIS>"\\INSERT_INIT_FCT_CALL"  {
maitre's avatar
maitre committed
611
  if (bInitFunction) fprintf(fpOutputFile,"\n  EASEAInitFunction(argc, argv);\n");
moh_lo's avatar
moh_lo committed
612
 }
maitre's avatar
maitre committed
613 614 615 616 617 618

<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
619
  //DEBUG_PRT_PRT("Inserting user classe definitions");
maitre's avatar
maitre committed
620 621 622 623
  pGENOME->printUserClasses(fpOutputFile);
 }        

<TEMPLATE_ANALYSIS>"\\SELECTOR"  {
624
  if( TARGET==CUDA || TARGET==STD){
kruger's avatar
kruger committed
625
    //DEBUG_PRT_PRT("Selector is \"%s\" | Goal is %s",sSELECTOR,(nMINIMISE?"Minimize":"Maximize"));
maitre's avatar
maitre committed
626 627
    char* selectorClass = selectorDetermination(nMINIMISE,sSELECTOR);
    if( !selectorClass ){
628
      fprintf(stderr,"Error %d : selection operator %s doesn't exist in CUDA/STD template\n",yylineno,sSELECTOR);
maitre's avatar
maitre committed
629 630
      return -1;
    }    
kruger's avatar
kruger committed
631
    //DEBUG_PRT_PRT("Created class is %s",selectorClass);
maitre's avatar
maitre committed
632 633 634 635
    fprintf(fpOutputFile,"%s",selectorClass);
  }
  else fprintf(fpOutputFile,"%s",sSELECTOR);
}
maitre's avatar
maitre committed
636 637 638 639 640 641 642 643
<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
644 645
<TEMPLATE_ANALYSIS>"\\POP_SIZE"  {fprintf(fpOutputFile,"%d",nPOP_SIZE);}
<TEMPLATE_ANALYSIS>"\\OFF_SIZE"  {fprintf(fpOutputFile,"%d",nOFF_SIZE);}
maitre's avatar
maitre committed
646 647
<TEMPLATE_ANALYSIS>"\\ELITE_SIZE"  {
  fprintf(fpOutputFile,"%d",nELITE);
kruger's avatar
kruger committed
648
  ////DEBUG_PRT_PRT("elitism is %d, elite size is %d",bELITISM, nELITE);
maitre's avatar
maitre committed
649 650
 }

maitre's avatar
maitre committed
651 652
<TEMPLATE_ANALYSIS>"\\RED_PAR"  {
  if( TARGET==CUDA || TARGET==STD){
kruger's avatar
kruger committed
653
    //DEBUG_PRT_PRT("Parent reduction is \"%s\" | Goal is %s",sSELECTOR,(nMINIMISE?"Minimize":"Maximize"));
maitre's avatar
maitre committed
654 655 656 657 658
    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
659
    //DEBUG_PRT_PRT("Created class is %s",selectorClass);
maitre's avatar
maitre committed
660 661 662 663 664 665
    fprintf(fpOutputFile,"%s",selectorClass);
  }
  else fprintf(fpOutputFile,"%s",sRED_PAR);
 }
<TEMPLATE_ANALYSIS>"\\RED_OFF"  {
  if( TARGET==CUDA || TARGET==STD){
kruger's avatar
kruger committed
666
    //DEBUG_PRT_PRT("Offspring reduction is \"%s\" | Goal is %s",sSELECTOR,(nMINIMISE?"Minimize":"Maximize"));
maitre's avatar
maitre committed
667 668 669 670 671
    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
672
    //DEBUG_PRT_PRT("Created class is %s",selectorClass);
maitre's avatar
maitre committed
673 674 675 676
    fprintf(fpOutputFile,"%s",selectorClass);
  }
  else fprintf(fpOutputFile,"%s",sRED_OFF);
 }
maitre's avatar
maitre committed
677
<TEMPLATE_ANALYSIS>"\\RED_FINAL"  {
678
  if( TARGET==CUDA || TARGET==STD){
kruger's avatar
kruger committed
679
    //DEBUG_PRT_PRT("Replacement selector is \"%s\" | Goal is %s",sRED_FINAL,(nMINIMISE?"Minimize":"Maximize"));
maitre's avatar
maitre committed
680 681
    char* selectorClass = selectorDetermination(nMINIMISE,sRED_FINAL);
    if( !selectorClass ){
682
      fprintf(stderr,"Error %d : replacement operator %s doesn't exist in CUDA/TPL template\n",yylineno,sRED_FINAL);
maitre's avatar
maitre committed
683 684
      return -1;
    }    
kruger's avatar
kruger committed
685
    //DEBUG_PRT_PRT("Created class is %s",selectorClass);
maitre's avatar
maitre committed
686 687 688 689
    fprintf(fpOutputFile,"%s",selectorClass);
  }
  else fprintf(fpOutputFile,"%s",sRED_FINAL);
 }
kruger's avatar
kruger committed
690 691 692 693
<TEMPLATE_ANALYSIS>"\\CUDA_RULE_DIR"  {
if(OPERATING_SYSTEM=WINDOWS)
	fprintf(fpOutputFile,"%s\\",getenv("NVSDKCUDA_ROOT"));
}
maitre's avatar
maitre committed
694 695
<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
696 697
<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
698
<TEMPLATE_ANALYSIS>"\\NB_GEN"  {fprintf(fpOutputFile,"%d",nNB_GEN);}
maitre's avatar
maitre committed
699 700 701
<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);}
maitre's avatar
maitre committed
702 703 704
<TEMPLATE_ANALYSIS>"\\MINIMAXI"  {
  switch (TARGET) { 
  case STD:
705 706
  //case CUDA: fprintf(fpOutputFile,"%s",(nMINIMISE? "false" : "true")); break;
  case CUDA: fprintf(fpOutputFile,"%s",(nMINIMISE? "true" : "false")); break;
maitre's avatar
maitre committed
707 708
  }
 }
maitre's avatar
maitre committed
709 710
<TEMPLATE_ANALYSIS>"\\ELITISM"  {
  switch (TARGET) { 
711
  case STD:
maitre's avatar
maitre committed
712 713
  case CUDA: fprintf(fpOutputFile,"%d",bELITISM);
  }                                 }
maitre's avatar
maitre committed
714 715 716 717 718 719

<TEMPLATE_ANALYSIS>"\\PRINT_STATS" {fprintf(fpOutputFile,"%d",bPRINT_STATS);}
<TEMPLATE_ANALYSIS>"\\PLOT_STATS" {fprintf(fpOutputFile,"%d",bPLOT_STATS);}
<TEMPLATE_ANALYSIS>"\\GENERATE_CVS_FILE" {fprintf(fpOutputFile,"%d",bGENERATE_CVS_FILE);}
<TEMPLATE_ANALYSIS>"\\GENERATE_GNUPLOT_SCRIPT" {fprintf(fpOutputFile,"%d",bGENERATE_GNUPLOT_SCRIPT);}
<TEMPLATE_ANALYSIS>"\\GENERATE_R_SCRIPT" {fprintf(fpOutputFile,"%d",bGENERATE_R_SCRIPT);}
720

maitre's avatar
maitre committed
721 722 723 724 725 726 727 728 729 730 731 732
<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);
733 734 735 736
  if( TARGET==CUDA )
    strcat(sFileName,"Individual.cu");
  else if( TARGET==STD )
    strcat(sFileName,"Individual.cpp");
maitre's avatar
maitre committed
737 738 739
  fpOutputFile=fopen(sFileName,"w");    
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
 }
moh_lo's avatar
moh_lo committed
740
<TEMPLATE_ANALYSIS>"\\START_EO_PARAM_TPL"  {
maitre's avatar
maitre committed
741 742 743 744 745 746 747
  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
748
<TEMPLATE_ANALYSIS>"\\START_EO_MAKEFILE_TPL"  {
maitre's avatar
maitre committed
749 750 751 752 753 754 755 756
  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
757 758 759 760 761 762 763 764 765
<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
766 767 768 769 770 771 772 773 774 775 776 777 778 779
<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
780
    }
maitre's avatar
maitre committed
781 782
  if( fileNameLength != -1 ){
    // add "Makefile" at the end of path
783
    //char* cdn = get_current_dir_name();
kruger's avatar
kruger committed
784 785 786 787
    char cdn[4096];
    #ifdef WIN32 
    _getcwd(cdn,4096);
    #else
788
    getcwd(cdn,4096);
kruger's avatar
kruger committed
789
    #endif
maitre's avatar
maitre committed
790 791 792 793 794 795 796 797
    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
798 799
    //DEBUG_PRT_PRT("PathName is %s",sPathName);
    //DEBUG_PRT_PRT("FullFileName is %s",sFullFileName);
maitre's avatar
maitre committed
800 801 802
    
  
    // create a symbolic link from Makefile to EASEA.mak
maitre's avatar
maitre committed
803
#ifndef WIN32
maitre's avatar
maitre committed
804
    symlink(sFullFileName,sPathName);
maitre's avatar
maitre committed
805
#endif
maitre's avatar
maitre committed
806
  }
maitre's avatar
maitre committed
807
  else{
kruger's avatar
kruger committed
808
    //DEBUG_PRT_PRT("file name : %s",sFileName);
maitre's avatar
maitre committed
809
#ifndef WIN32
maitre's avatar
maitre committed
810
    if( symlink(sFileName,"Makefile") ) perror("Symlink creation error ");
maitre's avatar
maitre committed
811
#endif
maitre's avatar
maitre committed
812
  }
maitre's avatar
maitre committed
813 814 815 816 817 818 819 820 821
  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
822
}
moh_lo's avatar
moh_lo committed
823
<TEMPLATE_ANALYSIS>"\\TEMPLATE_END"  {
maitre's avatar
maitre committed
824 825 826
  if (nWARNINGS) printf ("\nWARNING !!!\nTarget file(s) generation went through WITH %d WARNING(S) !\n",nWARNINGS);
  else printf ("\nCONGRATULATIONS !!!\nTarget file(s) generation succeeded with no warning.\n");
  printf ("Have a nice compile time.\n");
maitre's avatar
maitre committed
827
  if (TARGET==CUDA || TARGET==STD) fprintf(fpOutputFile,"\n# That's all folks ! \n");
maitre's avatar
maitre committed
828 829 830 831 832 833
  else fprintf(fpOutputFile,"\n// That's all folks ! \n");
  fflush(fpOutputFile);
  fclose(fpOutputFile);
  fclose(fpTemplateFile);
  fclose(fpGenomeFile);
 }
moh_lo's avatar
moh_lo committed
834 835 836 837 838 839 840 841

<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
842
  fprintf (fpOutputFile,"// Genome Initialiser\n"); 
843 844
  if( bLINE_NUM_EZ_FILE )
    fprintf(fpOutputFile,"#line %d \"%s.ez\"\n",lineCounter, sRAW_PROJECT_NAME);
maitre's avatar
maitre committed
845 846
  BEGIN COPY;
 }                                                               
moh_lo's avatar
moh_lo committed
847
<COPY_EO_INITIALISER><<EOF>> {
moh_lo's avatar
moh_lo committed
848 849 850 851 852 853
  if (bVERBOSE) printf("*** No genome initialiser was found. ***\n");
  rewind(fpGenomeFile);
  yyin = fpTemplateFile;
  BEGIN TEMPLATE_ANALYSIS;
  bNotFinishedYet=1;
 }
854 855
<COPY_EO_INITIALISER>. {}                                      
<COPY_EO_INITIALISER>\n {lineCounter++;}
moh_lo's avatar
moh_lo committed
856 857

<COPY_USER_DECLARATIONS>"\\User"[ \t\n]+"declarations"[ \t\n]*":" {
maitre's avatar
maitre committed
858
  fprintf (fpOutputFile,"// User declarations\n"); 
859 860
  if( bLINE_NUM_EZ_FILE )
    fprintf(fpOutputFile,"#line %d \"%s.ez\"\n",lineCounter, sRAW_PROJECT_NAME);
maitre's avatar
maitre committed
861 862
  BEGIN COPY;
 }                                                               
moh_lo's avatar
moh_lo committed
863
<COPY_USER_DECLARATIONS><<EOF>> {
moh_lo's avatar
moh_lo committed
864 865 866 867 868 869
  if (bVERBOSE) printf("*** No user declarations were found. ***\n");
  rewind(fpGenomeFile);
  yyin = fpTemplateFile;
  BEGIN TEMPLATE_ANALYSIS;
  bNotFinishedYet=1;
 }
870 871 872 873 874

<COPY_USER_DECLARATIONS>. {}
<COPY_USER_DECLARATIONS>\n {
  lineCounter++;
 }                
moh_lo's avatar
moh_lo committed
875 876

<COPY_USER_FUNCTIONS>"\\User"[ \t\n]+"functions"[ \t\n]*":" {
maitre's avatar
maitre committed
877
  fprintf (fpOutputFile,"// User functions\n\n"); 
878 879
  if( bLINE_NUM_EZ_FILE )
    fprintf(fpOutputFile,"#line %d \"%s.ez\"\n",lineCounter, sRAW_PROJECT_NAME);
maitre's avatar
maitre committed
880 881
  BEGIN COPY;
 }                                                               
moh_lo's avatar
moh_lo committed
882
<COPY_USER_FUNCTIONS><<EOF>> {
moh_lo's avatar
moh_lo committed
883 884 885 886 887 888
  if (bVERBOSE) printf("*** No user functions were found. ***\n");
  fprintf(fpOutputFile,"\n// No user functions.\n");
  rewind(fpGenomeFile);
  yyin = fpTemplateFile;
  BEGIN TEMPLATE_ANALYSIS;
  bNotFinishedYet=1;
moh_lo's avatar
moh_lo committed
889
 }
890 891 892 893
<COPY_USER_FUNCTIONS>. {}                                      
<COPY_USER_FUNCTIONS>\n {
  lineCounter++;
 }
moh_lo's avatar
moh_lo committed
894

maitre's avatar
maitre committed
895
<COPY_INITIALISATION_FUNCTION>"\\Before"[ \t\n]+"everything"[ \t\n]+"else"[ \t\n]+"function"[ \t\n]*":" {
maitre's avatar
maitre committed
896 897 898 899 900
    fprintf (fpOutputFile,"// Initialisation function\nvoid EASEAInitFunction(int argc, char *argv[]){");
  bFunction=1; bInitFunction=1;
      
  BEGIN COPY;
 }
901 902 903
<COPY_INITIALISATION_FUNCTION><<EOF>> {bInitFunction=0; // No before everything else function was found in the .ez file
  if (bVERBOSE) printf("*** No before everything else function was found. ***\n");
  fprintf(fpOutputFile,"\n// No before everything else function.\n");
maitre's avatar
maitre committed
904 905 906 907 908 909
  rewind(fpGenomeFile);
  yyin = fpTemplateFile;
  BEGIN TEMPLATE_ANALYSIS;
  bNotFinishedYet=1;
 }
<COPY_INITIALISATION_FUNCTION>.|\n {}                                      
moh_lo's avatar
moh_lo committed
910

maitre's avatar
maitre committed
911 912 913
//****************************************
//  Easea GPGPU & EO Finalization function
//****************************************
maitre's avatar
maitre committed
914
<COPY_FINALIZATION_FUNCTION>"\\After"[ \t\n]+"everything"[ \t\n]+"else"[ \t\n]+"function"[ \t\n]*":" {
maitre's avatar
maitre committed
915 916
  switch( TARGET ){

917
  case STD:
maitre's avatar
maitre committed
918
  case CUDA:
kruger's avatar
kruger committed
919
    fprintf (fpOutputFile,"// Finalization function\nvoid EASEAFinalization(CPopulation* population){");
maitre's avatar
maitre committed
920 921
    break;
  default:
maitre's avatar
maitre committed
922
    fprintf (stderr," Error this template doesn't support finalization function ");
maitre's avatar
maitre committed
923 924 925
    return -1;
  }
  bFunction=1; bFinalizationFunction=1;
moh_lo's avatar
moh_lo committed
926
  BEGIN COPY;
maitre's avatar
maitre committed
927
 }
moh_lo's avatar
moh_lo committed
928

929 930 931
<COPY_FINALIZATION_FUNCTION><<EOF>> {bFinalizationFunction=0; // No after everything else function was found in the .ez file
  if (bVERBOSE) printf("*** No after everything else function was found. ***\n");
  fprintf(fpOutputFile,"\n// No after eveything else function.\n");
moh_lo's avatar
moh_lo committed
932 933 934 935 936
  rewind(fpGenomeFile);
  yyin = fpTemplateFile;
  BEGIN TEMPLATE_ANALYSIS;
  bNotFinishedYet=1;
 }
maitre's avatar
maitre committed
937
<COPY_FINALIZATION_FUNCTION>.|\n {}                                      
moh_lo's avatar
moh_lo committed
938 939


940
<COPY_END_GENERATION_FUNCTION>"\\At"[ \t\n]+"the"[ \t\n]+"end"[ \t\n]+"of"[ \t\n]+"each"[ \t\n]+"generation"[ \t\n]+"function"[ \t\n]*":" {
kruger's avatar
kruger committed
941
  //DEBUG_PRT_PRT("at each end");
942
  if( (TARGET==CUDA || TARGET==STD)  ){
kruger's avatar
kruger committed
943 944
    fprintf (fpOutputFile,"{\n");
    //fprintf (fpOutputFile,"// Function called at each new generation\nvoid EASEAEndGenerationFunction(EvolutionaryAlgorithm* evolutionaryAlgorithm){\n");
945 946
    bFunction=1; 
    bEndGenerationFunction = 1;
maitre's avatar
maitre committed
947 948 949 950
    BEGIN COPY_USER_GENERATION;
  }
 }

951 952
<COPY_END_GENERATION_FUNCTION><<EOF>> {
  bEndGenerationFunction=0; // No Generation function was found in the .ez file
maitre's avatar
maitre committed
953
  if( bVERBOSE) printf("*** No end generation function was found. ***\n");
954 955 956 957 958 959 960 961 962 963 964
  fprintf(fpOutputFile,"\n// No at end of generation function.\n");

  rewind(fpGenomeFile);
  yyin = fpTemplateFile;
  BEGIN TEMPLATE_ANALYSIS;
  bNotFinishedYet=1;
 }
<COPY_END_GENERATION_FUNCTION>.|\n {}                                      


<COPY_BEG_GENERATION_FUNCTION>"\\At"[ \t\n]+"the"[ \t\n]+"beginning"[ \t\n]+"of"[ \t\n]+"each"[ \t\n]+"generation"[ \t\n]+"function"[ \t\n]*":" {
kruger's avatar
kruger committed
965
  //DEBUG_PRT_PRT("at each beg");
966
  if( (TARGET==CUDA || TARGET==STD)){
kruger's avatar
kruger committed
967
    fprintf (fpOutputFile,"{\n");
968 969 970 971 972 973 974
    bFunction=1;
    bBeginGeneration = 0;
    bBeginGenerationFunction = 1;
    BEGIN COPY_USER_GENERATION;
  }
 }

maitre's avatar
maitre committed
975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997
<COPY_INSTEAD_EVAL>"\\Instead"[ \t\n]+"evaluation"[ \t\n]+"function:" {
  //DEBUG_PRT_PRT("at each beg");
  if( (TARGET==CUDA || TARGET==STD)){
    fprintf (fpOutputFile,"{\n");
    bFunction=1;
    BEGIN COPY_USER_GENERATION;
  }
 }

<COPY_INSTEAD_EVAL>.|\n {}                                      

<COPY_INSTEAD_EVAL><<EOF>> {
  bBeginGenerationFunction=0; // No Generation function was found in the .ez file
  if (bVERBOSE) printf("*** No Instead evaluation step function was found. ***\n");
  fprintf(fpOutputFile,"\n// No Instead evaluation step function.\n");

  rewind(fpGenomeFile);
  yyin = fpTemplateFile;
  BEGIN TEMPLATE_ANALYSIS;
  bNotFinishedYet=1;
 }


998 999
<COPY_BEG_GENERATION_FUNCTION><<EOF>> {
  bBeginGenerationFunction=0; // No Generation function was found in the .ez file
maitre's avatar
maitre committed
1000
  if (bVERBOSE) printf("*** No beginning generation function was found. ***\n");
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010
  fprintf(fpOutputFile,"\n// No at beginning of generation function.\n");

  rewind(fpGenomeFile);
  yyin = fpTemplateFile;
  BEGIN TEMPLATE_ANALYSIS;
  bNotFinishedYet=1;
 }
<COPY_BEG_GENERATION_FUNCTION>.|\n {}                                      


moh_lo's avatar
moh_lo committed
1011

maitre's avatar
maitre committed
1012
<COPY_GENERATION_FUNCTION_BEFORE_REPLACEMENT>"\\At"[ \t\n]+"each"[ \t\n]+"generation"[ \t\n]+"before"[ \t\n]+"reduce"[ \t\n]+"function"[ \t\n]*":" {
kruger's avatar
kruger committed
1013
  //DEBUG_PRT_PRT("at each");
maitre's avatar
maitre committed
1014 1015 1016 1017
  if((TARGET==CUDA || TARGET==STD)){// && !bBeginGeneration && !bEndGeneration ){
      fprintf (fpOutputFile,"{\n");
      bFunction=1; 
      bGenerationReplacementFunction=1;
maitre's avatar
maitre committed
1018
      BEGIN COPY_USER_GENERATION;
1019
  }
maitre's avatar
maitre committed
1020
 }
maitre's avatar
maitre committed
1021 1022 1023 1024 1025

<COPY_GENERATION_FUNCTION_BEFORE_REPLACEMENT><<EOF>> {
  bGenerationFunctionBeforeReplacement=0; // No Generation function was found in the .ez file
  if (bVERBOSE) printf("*** No generation function was found. ***\n");
  fprintf(fpOutputFile,"\n// No generation function.\n");
maitre's avatar
maitre committed
1026 1027 1028 1029 1030
  rewind(fpGenomeFile);
  yyin = fpTemplateFile;
  BEGIN TEMPLATE_ANALYSIS;
  bNotFinishedYet=1;
 }
maitre's avatar
maitre committed
1031
<COPY_GENERATION_FUNCTION_BEFORE_REPLACEMENT>.|\n {}                                      
moh_lo's avatar
moh_lo committed
1032

maitre's avatar
maitre committed
1033 1034 1035 1036 1037 1038 1039 1040

<COPY_BOUND_CHECKING_FUNCTION>"\\Bound"[ \t\n]+"checking"[ \t\n]*":" {
  if(TARGET==CUDA || TARGET==STD){
    fprintf (fpOutputFile,"void EASEABoundChecking(EvolutionaryAlgorithm* evolutionaryAlgorithm){\n");
  }
  bFunction=1; bBoundCheckingFunction=1;
  BEGIN COPY_USER_GENERATION;
 }
1041
<COPY_BOUND_CHECKING_FUNCTION><<EOF>> {bBoundCheckingFunction=0; // No Generation function was found in the .ez file
maitre's avatar
maitre committed
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052
  if (bVERBOSE) printf("*** No bound checking function was found. ***\n");
  fprintf(fpOutputFile,"\n// No Bound checking function.\n");
  rewind(fpGenomeFile);
  yyin = fpTemplateFile;
  BEGIN TEMPLATE_ANALYSIS;
  bNotFinishedYet=1;
 }
<COPY_BOUND_CHECKING_FUNCTION>.|\n {}                                      



moh_lo's avatar
moh_lo committed
1053
<ANALYSE_USER_CLASSES>"\\User"[ \t\n]+"classes"[ \t\n]*":" {
moh_lo's avatar
moh_lo committed
1054
  BEGIN GENOME_ANALYSIS; return CLASSES;}
maitre's avatar
maitre committed
1055
<ANALYSE_USER_CLASSES>.|\n {}                                      
moh_lo's avatar
moh_lo committed
1056

moh_lo's avatar
moh_lo committed
1057 1058 1059 1060 1061 1062 1063 1064 1065
//****************************************
//  Basic copy to cpp file with minor changes
//****************************************

<COPY>"\""  {(bDoubleQuotes ? bDoubleQuotes=0:bDoubleQuotes=1); fprintf(fpOutputFile,"\"");}
<COPY>"\\\""  {fprintf(fpOutputFile,"\\\"");}

<COPY>"currentGeneration" |
<COPY>"currentGeneration"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"currentGeneration");
maitre's avatar
maitre committed
1066
  else switch  (TARGET) {
Frederic's avatar
Frederic committed
1067
    case STD : fprintf(fpOutputFile,"(*EZ_current_generation)"); break;
maitre's avatar
maitre committed
1068
    }} // local genome name
moh_lo's avatar
moh_lo committed
1069 1070
<COPY>"NB_GEN" |
<COPY>"NB_GEN"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"NB_GEN");
Frederic's avatar
NB_GEN  
Frederic committed
1071
  else fprintf(fpOutputFile,"(*EZ_NB_GEN)");} // local genome name
moh_lo's avatar
moh_lo committed
1072 1073
<COPY>"POP_SIZE" |
<COPY>"POP_SIZE"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"POP_SIZE");
maitre's avatar
maitre committed
1074
  else fprintf(fpOutputFile,"EZ_POP_SIZE");} // local genome name
moh_lo's avatar
moh_lo committed
1075
<COPY>"MUT_PROB" |
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085
<COPY>"MUT_PROB"/[ \t\n]*"==" {
  if (bDoubleQuotes) 
    fprintf(fpOutputFile,"MUT_PROB");
  else
    if( TARGET==STD || TARGET==CUDA){
      fprintf(fpOutputFile,"(*pEZ_MUT_PROB)");
    }
    else fprintf(fpOutputFile,"EZ_MUT_PROB");
  
 } // local genome name
moh_lo's avatar
moh_lo committed
1086
<COPY>"XOVER_PROB" |
maitre's avatar
maitre committed
1087 1088 1089 1090 1091 1092 1093
<COPY>"XOVER_PROB"/[ \t\n]*"==" {
  if (bDoubleQuotes) 
    fprintf(fpOutputFile,"XOVER_PROB");
  else if( TARGET==CUDA || TARGET==STD )
    fprintf(fpOutputFile,"(*pEZ_XOVER_PROB)");
  else fprintf(fpOutputFile,"EZ_XOVER_PROB");
 } // local genome name
moh_lo's avatar
moh_lo committed
1094 1095
<COPY>"REPL_PERC" |
<COPY>"REPL_PERC"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"REPL_PERC");
maitre's avatar
maitre committed
1096
  else fprintf(fpOutputFile,"EZ_REPL_PERC");} // local genome name
moh_lo's avatar
moh_lo committed
1097 1098
<COPY>"MINIMISE" |
<COPY>"MINIMISE"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"MINIMISE");
maitre's avatar
maitre committed
1099
  else fprintf(fpOutputFile,"EZ_MINIMISE");} // local genome name
moh_lo's avatar
moh_lo committed
1100 1101
<COPY>"MINIMIZE" |
<COPY>"MINIMIZE"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"MINIMIZE");
maitre's avatar
maitre committed
1102
  else fprintf(fpOutputFile,"EZ_MINIMIZE");} // local genome name
1103 1104 1105 1106 1107 1108
<COPY>"MAXIMISE" |
<COPY>"MAXIMISE"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"MAXIMISE");
  else fprintf(fpOutputFile,"EZ_MAXIMISE");} // local genome name
<COPY>"MAXIMIZE" |
<COPY>"MAXIMIZE"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"MAXIMIZE");
  else fprintf(fpOutputFile,"EZ_MAXIMIZE");} // local genome name
moh_lo's avatar
moh_lo committed
1109

maitre's avatar
maitre committed
1110 1111 1112 1113 1114 1115 1116
<COPY>"__device__" |
<COPY>"__host__" {
  if( TARGET==CUDA ){
    fprintf(fpOutputFile,"%s",yytext);
  }
 }

moh_lo's avatar
moh_lo committed
1117 1118 1119
<COPY>"currentGeneration"[ \t\n]*"="  {fprintf(stderr,"\n%s - Error line %d: The current generation number cannot be changed (not an l-value).\n",sEZ_FILE_NAME,yylineno); exit(1);}
<COPY>"NB_GEN"[ \t\n]*"="  {fprintf(stderr,"\n%s - Error line %d: The number of generations can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);}
<COPY>"POP_SIZE"[ \t\n]*"="  {fprintf(stderr,"\n%s - Error line %d: The size of the population can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);}
1120 1121 1122 1123 1124
<COPY>"MUT_PROB"[ \t\n]*"=" {
  fprintf(stderr,"\n%s - Error line %d: The mutation probability can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); 
  exit (1);
}

moh_lo's avatar
moh_lo committed
1125 1126 1127 1128
<COPY>"XOVER_PROB"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The crossover proability can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);}
<COPY>"REPL_PERC"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The replacement percentage can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);}
<COPY>"MINIMISE"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The evaluation goal can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);}
<COPY>"MINIMIZE"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The evaluation goal can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);}
1129 1130
<COPY>"MAXIMISE"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The evaluation goal can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);}
<COPY>"MAXIMIZE"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The evaluation goal can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);}
maitre's avatar
maitre committed
1131 1132 1133 1134 1135 1136
<COPY>"false"  {fprintf(fpOutputFile,"false");} // local name
<COPY>"true"  {fprintf(fpOutputFile,"true");} // local name
<COPY>[^a-zA-Z0-9_]"bool"[^a-zA-Z0-9_]  {
  fprintf(fpOutputFile,yytext);}
<COPY>"tossCoin"  { // local random name 
  fprintf(fpOutputFile,"globalRandomGenerator->tossCoin");}
maitre's avatar
maitre committed
1137
<COPY>"random"  {
maitre's avatar
maitre committed
1138
  fprintf(fpOutputFile,"globalRandomGenerator->random");}
moh_lo's avatar
moh_lo committed
1139
<COPY>"Genome" {
1140
  if (bWithinEO_Function && TARGET!=CUDA && TARGET!=STD) fprintf(fpOutputFile,"_genotype");
maitre's avatar
maitre committed
1141
  else if(bWithinEO_Function && bWithinCUDA_Initializer )fprintf(fpOutputFile,"(*this)");
moh_lo's avatar
moh_lo committed