Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

EaseaLex.l 96.8 KB
Newer Older
1

moh_lo's avatar
moh_lo committed
2
%{
maitre's avatar
maitre 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
  ****************************************************************************/
moh_lo's avatar
moh_lo committed
12
13
14

#include "Easea.h"
#include "EaseaParse.h"
maitre's avatar
maitre committed
15
16
17
#include <unistd.h>
#include "debug.h"

maitre's avatar
maitre committed
18
19
20
  size_t genomeSize;
  bool genomeSizeValidity=false;

maitre's avatar
maitre committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// local functions
  char* selectorDetermination(int nMINIMISE, char* sSELECTOR){

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

  if( mystricmp("tournament",sSELECTOR)==0 )
    strcat(selectorName,"Tournament(globalRandomGenerator)");
  else if( mystricmp("dettour",sSELECTOR)==0 )
    strcat(selectorName,"Tournament(globalRandomGenerator)");
36
37
38
39
40
  else if( mystricmp("Sequential",sSELECTOR)==0 )
    strcat(selectorName,"Deterministic()");
  else if( mystricmp("Random",sSELECTOR)==0 )
    strcat(selectorName,"Random(globalRandomGenerator)");

maitre's avatar
maitre committed
41
42
43
44
45
46
47
48
49
  else return NULL;
  
  char* ret = (char*)malloc((strlen(selectorName)+1)*sizeof(char));
  strcpy(ret,selectorName);

  return ret;
}

  %}
moh_lo's avatar
moh_lo committed
50
51
52

// include file
%include {
maitre's avatar
maitre committed
53
54
55
56
  // forward references
  class CEASEAParser;
  class CSymbolTable;
 }                                                     
moh_lo's avatar
moh_lo committed
57
58
59
60
                                         
%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
61
%start COPY COPY_INITIALISER COPY_CROSSOVER COPY_MUTATOR COPY_EVALUATOR COPY_FINALIZATION_FUNCTION
moh_lo's avatar
moh_lo committed
62
%start COPY_DISPLAY COPY_USER_FUNCTION COPY_USER_GENERATION PARAMETERS_ANALYSIS GET_PARAMETERS 
63
%start COPY_USER_FUNCTIONS COPY_GENERATION_FUNCTION GET_METHODS COPY_MAKEFILE_OPTION COPY_BOUND_CHECKING_FUNCTION COPY_BEG_GENERATION_FUNCTION COPY_END_GENERATION_FUNCTION
moh_lo's avatar
moh_lo committed
64

maitre's avatar
maitre committed
65
 // lexical analyser name and class definition
moh_lo's avatar
moh_lo committed
66
%name CEASEALexer {
maitre's avatar
maitre committed
67
 protected:
moh_lo's avatar
moh_lo committed
68
69
  CSymbolTable *pSymbolTable;   // the symbol table
  bool bSymbolInserted,bWithinEvaluator;  // used to change evalutor type from double to float 
maitre's avatar
maitre committed
70
71
  bool bInitFunction,bDisplayFunction,bFunction, bNotFinishedYet, bWithinEO_Function;
  bool bDoubleQuotes,bWithinDisplayFunction,bWithinInitialiser,bWithinMutator,bWithinXover;
moh_lo's avatar
moh_lo committed
72
  bool bWaitingForSemiColon,bFinishNB_GEN,bFinishMINIMISE,bFinishMINIMIZE,bGenerationFunction;
maitre's avatar
maitre committed
73
  bool bCatchNextSemiColon,bWaitingToClosePopulation, bMethodsInGenome, bFinalizationFunction;
maitre's avatar
maitre committed
74
  bool bWithinCUDA_Initializer, bWithinMAKEFILEOPTION, bWithinCUDA_Evaluator, bBoundCheckingFunction;
75
  bool bIsParentReduce, bIsOffspringReduce, bEndGeneration, bBeginGeneration, bEndGenerationFunction, bBeginGenerationFunction;
moh_lo's avatar
moh_lo committed
76
77
  CSymbol *pASymbol;

maitre's avatar
maitre committed
78
 public:
moh_lo's avatar
moh_lo committed
79
80
81
  int create(CEASEAParser* pParser, CSymbolTable* pSymbolTable);
  int yywrap();
  double myStrtod() const;                              
maitre's avatar
maitre committed
82
 }
moh_lo's avatar
moh_lo committed
83
84
85

// constructor
{                                
moh_lo's avatar
moh_lo committed
86
  bFunction=bWithinEvaluator=bDisplayFunction=bInitFunction=bNotFinishedYet=0;
maitre's avatar
maitre committed
87
  bSymbolInserted=bDoubleQuotes=bWithinDisplayFunction=bWithinInitialiser=bWithinMutator=bWithinXover=0;
moh_lo's avatar
moh_lo committed
88
  bWaitingForSemiColon=bFinishNB_GEN=bFinishMINIMISE=bFinishMINIMIZE=bGenerationFunction=0;
maitre's avatar
maitre committed
89
  bCatchNextSemiColon,bWaitingToClosePopulation=bMethodsInGenome=0;
maitre's avatar
maitre committed
90
  bBoundCheckingFunction = bWithinCUDA_Initializer=bWithinMAKEFILEOPTION =bWithinCUDA_Evaluator=0;
maitre's avatar
maitre committed
91
  bIsParentReduce = bIsOffspringReduce = false;
92
  bEndGeneration = bBeginGeneration = bEndGenerationFunction = bBeginGenerationFunction = false;
moh_lo's avatar
moh_lo committed
93
94
95
96
97
}

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

maitre's avatar
maitre committed
98
99


moh_lo's avatar
moh_lo committed
100
101
102
%%                                              

%{
maitre's avatar
maitre committed
103
104
105
  // extract yylval for use later on in actions
  YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
  %}
moh_lo's avatar
moh_lo committed
106
107
108
109
110
111

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

// switch immediately to TEMPLATE_ANALYSIS state
<INITIAL>.    {
maitre's avatar
maitre committed
112
113
  BEGIN TEMPLATE_ANALYSIS; yyless(yyleng-1);
 }
moh_lo's avatar
moh_lo committed
114
115
116
117
118
119

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

<TEMPLATE_ANALYSIS>"\\TEMPLATE_START"  {             
maitre's avatar
maitre committed
120
121
122
123
  char sFileName[1000];
  strcpy(sFileName, sRAW_PROJECT_NAME);
  switch (TARGET) {
  case DREAM : strcat(sFileName,".java"); break;
124
  case STD :
maitre's avatar
maitre committed
125
126
127
128
129
  case CUDA : strcat(sFileName,".cpp"); break;
  default : strcat(sFileName,".cpp");
  } 
  fpOutputFile=fopen(sFileName,"w");
 }
moh_lo's avatar
moh_lo committed
130
131
132
133
134
135
<TEMPLATE_ANALYSIS>"AESAE" {fprintf(fpOutputFile,"EASEA");}        
<TEMPLATE_ANALYSIS>"EASEA" {fprintf(fpOutputFile,"%s",sPROJECT_NAME);}        
<TEMPLATE_ANALYSIS>"\\EZ_PATH" {fprintf(fpOutputFile,"%s",sEZ_PATH);}        
<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
136
137
138
139
140
  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
141
<TEMPLATE_ANALYSIS>"\\INSERT_USER_DECLARATIONS"  {
maitre's avatar
maitre committed
142
143
144
145
146
  if (bVERBOSE) printf ("Inserting user declarations.\n");
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  BEGIN COPY_USER_DECLARATIONS;
 }
moh_lo's avatar
moh_lo committed
147
<TEMPLATE_ANALYSIS>"\\INSERT_INITIALISATION_FUNCTION"  {
maitre's avatar
maitre committed
148
149
150
151
152
  if (bVERBOSE) printf ("Inserting initialisation function.\n");
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  BEGIN COPY_INITIALISATION_FUNCTION;
 }
moh_lo's avatar
moh_lo committed
153
<TEMPLATE_ANALYSIS>"\\INSERT_GENERATION_FUNCTION"  {
maitre's avatar
maitre committed
154
155
156
157
158
  if (bVERBOSE) printf ("Inserting generation function.\n");
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  BEGIN COPY_GENERATION_FUNCTION;
 }
maitre's avatar
maitre committed
159

maitre's avatar
maitre committed
160
161

<TEMPLATE_ANALYSIS>"\\INSERT_BEGIN_GENERATION_FUNCTION"  {
162
  DEBUG_PRT("insert beg");
maitre's avatar
maitre committed
163
164
165
  if (bVERBOSE) printf ("Inserting at the begining of each generation function.\n");
  yyreset();
  yyin = fpGenomeFile;
166
167
168
  bBeginGeneration = true;
  bEndGeneration = false;
  BEGIN COPY_BEG_GENERATION_FUNCTION;
maitre's avatar
maitre committed
169
170
171
172
 }


<TEMPLATE_ANALYSIS>"\\INSERT_END_GENERATION_FUNCTION"  {
173
  DEBUG_PRT("insert end");
maitre's avatar
maitre committed
174
175
176
177
178
  if (bVERBOSE) printf ("Inserting at the end of each generation function.\n");
  yyreset();
  yyin = fpGenomeFile;
  bEndGeneration = true;
  bBeginGeneration = false;
179
  BEGIN COPY_END_GENERATION_FUNCTION;
maitre's avatar
maitre committed
180
181
182
183
 }



maitre's avatar
maitre committed
184
185
186
187
188
189
190
191
<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
192
<TEMPLATE_ANALYSIS>"\\ANALYSE_USER_CLASSES"  {
maitre's avatar
maitre committed
193
194
195
196
197
  if (bVERBOSE) printf ("Analysing user classes.\n");
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  BEGIN ANALYSE_USER_CLASSES;
 }
moh_lo's avatar
moh_lo committed
198
<TEMPLATE_ANALYSIS>"\\INSERT_USER_CLASSES"  {
maitre's avatar
maitre committed
199
200
201
202
203
  if (bVERBOSE) printf ("Inserting User classes.\n");
  if (TARGET!=DREAM) fprintf (fpOutputFile,"// User classes\n");
  CListItem<CSymbol*> *pSym;
  pGENOME->pSymbolList->reset();
  while (pSym=pGENOME->pSymbolList->walkToNextItem())
maitre's avatar
maitre committed
204
205
    if ((pSym->Object->pType->ObjectType==oUserClass)&&(!pSym->Object->pType->bAlreadyPrinted)){
      DEBUG_PRT("%p",pSym->Object->pType);
maitre's avatar
maitre committed
206
      pSym->Object->pType->printClasses(fpOutputFile);
maitre's avatar
maitre committed
207
208
209
210
211
212
213
214
215
216
217
218
219
220
    }


  if( TARGET == CUDA ){
    DEBUG_PRT("User classes are :");
    for( int i = nClasses_nb-1 ; i>=0 ; i-- ){
      DEBUG_PRT(" %s, %p ,%d| ",pCLASSES[i]->sName,pCLASSES[i],pCLASSES[i]->bAlreadyPrinted);
      if( !pCLASSES[i]->bAlreadyPrinted ){
	fprintf(fpOutputFile,"// User class not refereced by the Genome");
	pCLASSES[i]->printClasses(fpOutputFile);
      }
    }
    DEBUG_PRT("\n");
  }
maitre's avatar
maitre committed
221
 }
moh_lo's avatar
moh_lo committed
222
<TEMPLATE_ANALYSIS>"\\GENOME_CTOR"  {
maitre's avatar
maitre committed
223
224
225
226
227
228
229
230
231
232
  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==oArray)&&(TARGET==DREAM))
      fprintf(fpOutputFile,"    %s = new %s[%d];\n",pSym->Object->sName,pSym->Object->pType->sName,pSym->Object->nSize/pSym->Object->pType->nSize);
    if (pSym->Object->ObjectType==oPointer){
      if (TARGET==DREAM) fprintf(fpOutputFile,"    %s=null;\n",pSym->Object->sName);
      else fprintf(fpOutputFile,"    %s=NULL;\n",pSym->Object->sName);
moh_lo's avatar
moh_lo committed
233
    }
maitre's avatar
maitre committed
234
235
  }
 }
maitre's avatar
maitre committed
236

maitre's avatar
maitre committed
237
238
<TEMPLATE_ANALYSIS>"\\GENOME_SIZE" {
  size_t size_of_genome=0;
maitre's avatar
maitre committed
239
240
241
242
243
244
245
246
247
248
  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()){
      DEBUG_PRT("%s has size : %lu",pSym->Object->sName,pSym->Object->nSize);
      size_of_genome+=pSym->Object->nSize;
    }
    DEBUG_PRT("Total genome size is %lu",size_of_genome); 
maitre's avatar
ok  
maitre committed
249
    genomeSize = size_of_genome;
maitre's avatar
maitre committed
250
251
252
253
    genomeSizeValidity=true;
  }
  else{
    size_of_genome = genomeSize;
maitre's avatar
maitre committed
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
  }
  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==oArray)&&(TARGET==DREAM))
      fprintf(fpOutputFile,"    %s = new %s[%d];\n",pSym->Object->sName,pSym->Object->pType->sName,pSym->Object->nSize/pSym->Object->pType->nSize);
    if (pSym->Object->ObjectType==oPointer){
      if (TARGET==DREAM) fprintf(fpOutputFile,"    %s=null;\n",pSym->Object->sName);
      else fprintf(fpOutputFile,"    %s=NULL;\n",pSym->Object->sName);
    }
  }
  
 }

/* <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
299
300
301
302
303
304
305
306
307
308
309

<TEMPLATE_ANALYSIS>"\\GENOME_SERIAL"  {
  CListItem<CSymbol*> *pSym;
  if (bVERBOSE) printf ("Inserting default genome serializer.\n");
  pGENOME->pSymbolList->reset();
  while (pSym=pGENOME->pSymbolList->walkToNextItem()){
    DEBUG_PRT("found new symbol %s",pSym->Object->sName);
    fprintf(fpOutputFile," ar & %s;\n",pSym->Object->sName);
  }
 }

moh_lo's avatar
moh_lo committed
310
<TEMPLATE_ANALYSIS>"\\INSERT_GENOME"  {        
maitre's avatar
maitre committed
311
312
313
314
315
316
317
318
  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
319
<TEMPLATE_ANALYSIS>"\\ASSIGNMENT_OP"  {
maitre's avatar
maitre committed
320
321
322
323
324
325
326
327
328
329
330
331
332
  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
333
    }
maitre's avatar
maitre committed
334
335
  }
 }
moh_lo's avatar
moh_lo committed
336
<TEMPLATE_ANALYSIS>"\\CLONE"  {
maitre's avatar
maitre committed
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
  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 (TARGET==DREAM){
      if (pSym->Object->ObjectType==oObject)
	fprintf(fpOutputFile,"    %s=EZ_genome.%s;\n",pSym->Object->sName,pSym->Object->sName);
      if (pSym->Object->ObjectType==oPointer)
	fprintf(fpOutputFile,"    %s=((EZ_genome.%s!=null) ? new %s(EZ_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);
	if (pSym->Object->pType->ObjectType==oUserClass) fprintf(fpOutputFile,"       this.%s[EASEA_Ndx]=new %s(EZ_genome.%s[EASEA_Ndx]);}\n",pSym->Object->sName, pSym->Object->pType->sName, pSym->Object->sName);
	else fprintf(fpOutputFile,"       this.%s[EASEA_Ndx]=EZ_genome.%s[EASEA_Ndx];}\n",pSym->Object->sName,pSym->Object->sName);
      }
    } 
    else {
      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
362
363
      }
    }
maitre's avatar
maitre committed
364
365
  }
 }
moh_lo's avatar
moh_lo committed
366
367

<TEMPLATE_ANALYSIS>"\\COPY_CTOR"  {
maitre's avatar
maitre committed
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
  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 (TARGET==DREAM){
      if (pSym->Object->ObjectType==oObject)
	fprintf(fpOutputFile,"    EZ_genome.%s=%s;\n",pSym->Object->sName,pSym->Object->sName);
      if (pSym->Object->ObjectType==oPointer)
	fprintf(fpOutputFile,"    EZ_genome.%s=(%s!=null ? new %s(%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);
	if (pSym->Object->pType->ObjectType==oUserClass) fprintf(fpOutputFile,"       EZ_genome.%s[EASEA_Ndx]=new %s(this.%s[EASEA_Ndx]);}\n",pSym->Object->sName, pSym->Object->pType->sName, pSym->Object->sName);
	else fprintf(fpOutputFile,"       EZ_genome.%s[EASEA_Ndx]=this.%s[EASEA_Ndx];}\n",pSym->Object->sName, pSym->Object->sName);
      }
    }
    else {
      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
393
394
      }
    }
maitre's avatar
maitre committed
395
396
  }
 }
moh_lo's avatar
moh_lo committed
397
<TEMPLATE_ANALYSIS>"\\GENOME_DTOR"  {
maitre's avatar
maitre committed
398
399
400
401
402
403
404
405
  CListItem<CSymbol*> *pSym;
  if (bVERBOSE) printf ("Creating default destructor.\n");
  fprintf (fpOutputFile,"// Destructing pointers\n");             
  pGENOME->pSymbolList->reset();
  while (pSym=pGENOME->pSymbolList->walkToNextItem())
    if (pSym->Object->ObjectType==oPointer){
      if (TARGET==DREAM) fprintf(fpOutputFile,"  if (%s) delete %s;\n  %s=null;\n",pSym->Object->sName,pSym->Object->sName,pSym->Object->sName);
      else 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
406
    }
moh_lo's avatar
moh_lo committed
407
 }
moh_lo's avatar
moh_lo committed
408
<TEMPLATE_ANALYSIS>"\\EQUAL"  {       
maitre's avatar
maitre committed
409
410
411
412
413
414
415
416
417
418
419
420
  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
421
    }
maitre's avatar
maitre committed
422
423
  }
 }
moh_lo's avatar
moh_lo committed
424
<TEMPLATE_ANALYSIS>"\\COMPARE"  {
maitre's avatar
maitre committed
425
426
427
428
429
430
431
432
433
434
435
436
  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
437
    }
maitre's avatar
maitre committed
438
439
  }
 }
moh_lo's avatar
moh_lo committed
440
<TEMPLATE_ANALYSIS>"\\READ"  {
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 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
    if (TARGET==GALIB) {
      if ((pSym->Object->ObjectType==oObject)&&(strcmp(pSym->Object->pType->sName, "bool")))
	fprintf(fpOutputFile,"  is >> %s;\n",pSym->Object->sName);                                  
      if ((pSym->Object->ObjectType==oArray)&&(strcmp(pSym->Object->pType->sName, "bool"))){
	fprintf(fpOutputFile,"  {for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)\n",pSym->Object->nSize/pSym->Object->pType->nSize);
	fprintf(fpOutputFile,"     is >> %s[EASEA_Ndx];}\n",pSym->Object->sName);
moh_lo's avatar
moh_lo committed
453
      }
maitre's avatar
maitre committed
454
455
      if (pSym->Object->ObjectType==oPointer)
	fprintf(fpOutputFile,"  is >> *%s;\n",pSym->Object->sName);
moh_lo's avatar
moh_lo committed
456
    }
maitre's avatar
maitre committed
457
458
459
460
461
462
463
464
465
    if (TARGET==EO) {
      if (pSym->Object->ObjectType==oObject)
	fprintf(fpOutputFile,"  is >> %s;\n",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,"     is >> %s[EASEA_Ndx];}\n",pSym->Object->sName);
      }
      if (pSym->Object->ObjectType==oPointer)
	fprintf(fpOutputFile,"  is >> *(%s);\n",pSym->Object->sName);
moh_lo's avatar
moh_lo committed
466
    }
maitre's avatar
maitre committed
467
468
469
470
471
472
473
474
  }
 }
<TEMPLATE_ANALYSIS>"\\INSERT_DISPLAY"  {        
  if (bVERBOSE) printf ("Inserting genome display function.\n");
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  BEGIN COPY_DISPLAY;   
 }
475
476
477
478
479
480
481
482
483


<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
484
<TEMPLATE_ANALYSIS>"\\WRITE"  {
maitre's avatar
maitre committed
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
  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 (TARGET==DREAM) {
	if (pSym->Object->ObjectType==oObject){
	  if (bDisplayFunction) printf("//");
	  fprintf(fpOutputFile,"  EASEA_S = EASEA_S + \"%s:\" + %s + \"\\n\";\n",pSym->Object->sName,pSym->Object->sName);
	}
	if (pSym->Object->ObjectType==oArray){
	  if (bDisplayFunction) printf("//");
	  fprintf(fpOutputFile,"  {EASEA_S = \"Array %s : \";\n",pSym->Object->sName);
	  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("//");
	  fprintf(fpOutputFile,"     EASEA_S = EASEA_S + \"\\t\"+ %s[EASEA_Ndx];}\n",pSym->Object->sName);
	  if (bDisplayFunction) printf("//");
	}         
	if (pSym->Object->ObjectType==oPointer){
	  if (bDisplayFunction) printf("//");
	  fprintf(fpOutputFile,"  if (%s!=null) EASEA_S = EASEA_S + \"%s:\" + %s + \"\\n\";\n",pSym->Object->sName,pSym->Object->sName,pSym->Object->sName);
	}
      }
      else {
	if (pSym->Object->ObjectType==oObject){
	  if (bDisplayFunction) printf("//");
	  if (TARGET==GALIB) fprintf(fpOutputFile,"  os << \"%s:\" << %s << \"\\n\";\n",pSym->Object->sName,pSym->Object->sName);
	  if (TARGET==EO) fprintf(fpOutputFile,"  os << \"%s:\" << %s << \"\\n\";\n",pSym->Object->sName,pSym->Object->sName);
	}
	if (pSym->Object->ObjectType==oArray){
	  if (bDisplayFunction) printf("//");
	  if (TARGET == GALIB) fprintf(fpOutputFile,"  {os << \"Array %s : \";\n",pSym->Object->sName);
	  if (TARGET == DREAM) fprintf(fpOutputFile,"  {EASEA_S = \"Array %s : \";\n",pSym->Object->sName);
	  if (TARGET == EO) fprintf(fpOutputFile,"  {",pSym->Object->sName);
	  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 (TARGET==GALIB) fprintf(fpOutputFile,"     os << \"[\" << EASEA_Ndx << \"]:\" << %s[EASEA_Ndx] << \"\\t\";}\n",pSym->Object->sName);
	  if (TARGET==EO) fprintf(fpOutputFile,"     os << %s[EASEA_Ndx];}\n",pSym->Object->sName);
	  if (TARGET==DREAM) fprintf(fpOutputFile,"     EASEA_S = EASEA_S + \"\\t\"+ %s[EASEA_Ndx];}\n",pSym->Object->sName);
	  if (bDisplayFunction) printf("//");
	  if (TARGET!=DREAM) fprintf(fpOutputFile,"  os << \"\\n\";\n",pSym->Object->sName);
	}         
	if (pSym->Object->ObjectType==oPointer){
	  if (bDisplayFunction) printf("//");
	  if (TARGET==GALIB) fprintf(fpOutputFile,"  os << \"%s:\" << *%s << \"\\n\";\n",pSym->Object->sName,pSym->Object->sName);
	  if (TARGET==EO) fprintf(fpOutputFile,"  os << \"%s:\" << *%s << \"\\n\";\n",pSym->Object->sName,pSym->Object->sName);
	}
      }
    }
  }                      
 }    
moh_lo's avatar
moh_lo committed
540
<TEMPLATE_ANALYSIS>"\\INSERT_USER_FUNCTIONS"  {
maitre's avatar
maitre committed
541
542
543
544
  if (bVERBOSE) printf ("Inserting user functions.\n");
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  BEGIN COPY_USER_FUNCTIONS;
moh_lo's avatar
moh_lo committed
545
 }
moh_lo's avatar
moh_lo committed
546
<TEMPLATE_ANALYSIS>"\\INSERT_EO_INITIALISER"  {        
moh_lo's avatar
moh_lo committed
547
  yyreset();
maitre's avatar
maitre committed
548
  bWithinEO_Function=1;
549
  if( TARGET==CUDA || TARGET==STD) bWithinCUDA_Initializer = 1;
maitre's avatar
maitre committed
550
551
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  BEGIN COPY_EO_INITIALISER;                               // not implemented as a function !
moh_lo's avatar
moh_lo committed
552
 }
maitre's avatar
maitre committed
553

moh_lo's avatar
moh_lo committed
554
<TEMPLATE_ANALYSIS>"\\INSERT_INITIALISER"  {        
maitre's avatar
maitre committed
555
556
557
558
559
560
561
562
563
564
565
566
  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
567
<TEMPLATE_ANALYSIS>"\\INSERT_CROSSOVER"  {        
maitre's avatar
maitre committed
568
569
570
571
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  BEGIN COPY_CROSSOVER;   
 }
moh_lo's avatar
moh_lo committed
572
<TEMPLATE_ANALYSIS>"\\INSERT_MUTATOR"  {        
maitre's avatar
maitre committed
573
574
575
576
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  BEGIN COPY_MUTATOR;   
 }
moh_lo's avatar
moh_lo committed
577
<TEMPLATE_ANALYSIS>"\\INSERT_EVALUATOR"  {        
maitre's avatar
maitre committed
578
579
580
581
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  BEGIN COPY_EVALUATOR;   
 }
maitre's avatar
maitre committed
582
583
584
585
586
587
588
589

<TEMPLATE_ANALYSIS>"\\INSERT_CUDA_EVALUATOR"  {        
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  bWithinCUDA_Evaluator = 1;
  BEGIN COPY_EVALUATOR;
 }

moh_lo's avatar
moh_lo committed
590
<TEMPLATE_ANALYSIS>"\\ANALYSE_PARAMETERS"  {        
maitre's avatar
maitre committed
591
592
593
594
  yyreset();
  yyin = fpGenomeFile;                                                     // switch to .ez file and analyser
  BEGIN PARAMETERS_ANALYSIS;   
 }
moh_lo's avatar
moh_lo committed
595
<TEMPLATE_ANALYSIS>"\\INSERT_GEN_FCT_CALL"  {
596
  if (bGenerationFunction) {
597
    if( bVERBOSE ) fprintf(stdout,"Inserting generation function call\n");
598

599
600
601
602
603
    if( TARGET==CUDA || TARGET==STD ){
      fprintf(fpOutputFile,"\n\tEASEAGenerationFunction(this);");
    }
    else fprintf(fpOutputFile,"\n    EASEAGenerationFunction(ga);\n");
  }
604
 }     
maitre's avatar
maitre committed
605

606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
<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
625
626
627
628
629
630
631
632
<TEMPLATE_ANALYSIS>"\\INSERT_BOUND_CHECKING_FCT_CALL"  {
  if (bBoundCheckingFunction) {
    if( TARGET==CUDA || TARGET==STD ){
      fprintf(fpOutputFile,"\n\tEASEABoundChecking(this);");
    }
  }
 }        

maitre's avatar
maitre committed
633
634
635
636
637
638
639
640
<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
641
<TEMPLATE_ANALYSIS>"\\INSERT_INIT_FCT_CALL"  {
maitre's avatar
maitre committed
642
  if (bInitFunction) fprintf(fpOutputFile,"\n  EASEAInitFunction(argc, argv);\n");
moh_lo's avatar
moh_lo committed
643
 }
maitre's avatar
maitre committed
644
645
646
647
648
649
650
651
652
653
654

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

<TEMPLATE_ANALYSIS>"\\INSERT_USER_CLASSES_DEFINITIONS"  {
  DEBUG_PRT("Inserting user classe definitions");
  pGENOME->printUserClasses(fpOutputFile);
 }        

<TEMPLATE_ANALYSIS>"\\SELECTOR"  {
655
  if( TARGET==CUDA || TARGET==STD){
maitre's avatar
maitre committed
656
657
658
    DEBUG_PRT("Selector is \"%s\" | Goal is %s",sSELECTOR,(nMINIMISE?"Minimize":"Maximize"));
    char* selectorClass = selectorDetermination(nMINIMISE,sSELECTOR);
    if( !selectorClass ){
659
      fprintf(stderr,"Error %d : selection operator %s doesn't exist in CUDA/STD template\n",yylineno,sSELECTOR);
maitre's avatar
maitre committed
660
661
662
663
664
665
666
667
668
      return -1;
    }    
    DEBUG_PRT("Created class is %s",selectorClass);
    fprintf(fpOutputFile,"%s",selectorClass);
  }
  else fprintf(fpOutputFile,"%s",sSELECTOR);
}
//<TEMPLATE_ANALYSIS>"\\GEN_SELECTOR"  {fprintf(fpOutputFile,"%s(%s,%d)",sGEN_SELECTOR);}
<TEMPLATE_ANALYSIS>"\\SELECT_PRM"  {fprintf(fpOutputFile,"%s",sSELECT_PRM);}
moh_lo's avatar
moh_lo committed
669
670
<TEMPLATE_ANALYSIS>"\\POP_SIZE"  {fprintf(fpOutputFile,"%d",nPOP_SIZE);}
<TEMPLATE_ANALYSIS>"\\OFF_SIZE"  {fprintf(fpOutputFile,"%d",nOFF_SIZE);}
maitre's avatar
maitre committed
671
672
<TEMPLATE_ANALYSIS>"\\ELITE_SIZE"  {
  fprintf(fpOutputFile,"%d",nELITE);
673
  //DEBUG_PRT("elitism is %d, elite size is %d",bELITISM, nELITE);
maitre's avatar
maitre committed
674
675
 }

maitre's avatar
maitre committed
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
<TEMPLATE_ANALYSIS>"\\RED_PAR"  {
  if( TARGET==CUDA || TARGET==STD){
    DEBUG_PRT("Parent reduction is \"%s\" | Goal is %s",sSELECTOR,(nMINIMISE?"Minimize":"Maximize"));
    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;
    }    
    DEBUG_PRT("Created class is %s",selectorClass);
    fprintf(fpOutputFile,"%s",selectorClass);
  }
  else fprintf(fpOutputFile,"%s",sRED_PAR);
 }
<TEMPLATE_ANALYSIS>"\\RED_PAR_PRM"  {
  if( (TARGET==CUDA || TARGET==STD) && strlen(sRED_PAR_PRM)==0)
    fprintf(fpOutputFile,"0");
  else
    fprintf(fpOutputFile,"%s",sRED_PAR_PRM);
 }
<TEMPLATE_ANALYSIS>"\\RED_OFF"  {
  if( TARGET==CUDA || TARGET==STD){
    DEBUG_PRT("Offspring reduction is \"%s\" | Goal is %s",sSELECTOR,(nMINIMISE?"Minimize":"Maximize"));
    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;
    }    
    DEBUG_PRT("Created class is %s",selectorClass);
    fprintf(fpOutputFile,"%s",selectorClass);
  }
  else fprintf(fpOutputFile,"%s",sRED_OFF);
 }
<TEMPLATE_ANALYSIS>"\\RED_OFF_PRM"  {
  if( (TARGET==CUDA || TARGET==STD ) && strlen(sRED_OFF_PRM)==0 )
    fprintf(fpOutputFile,"0");
  else
    fprintf(fpOutputFile,"%s",sRED_OFF_PRM);}
maitre's avatar
maitre committed
713
<TEMPLATE_ANALYSIS>"\\RED_FINAL"  {
714
  if( TARGET==CUDA || TARGET==STD){
maitre's avatar
maitre committed
715
716
717
    DEBUG_PRT("Replacement selector is \"%s\" | Goal is %s",sRED_FINAL,(nMINIMISE?"Minimize":"Maximize"));
    char* selectorClass = selectorDetermination(nMINIMISE,sRED_FINAL);
    if( !selectorClass ){
718
      fprintf(stderr,"Error %d : replacement operator %s doesn't exist in CUDA/TPL template\n",yylineno,sRED_FINAL);
maitre's avatar
maitre committed
719
720
721
722
723
724
725
      return -1;
    }    
    DEBUG_PRT("Created class is %s",selectorClass);
    fprintf(fpOutputFile,"%s",selectorClass);
  }
  else fprintf(fpOutputFile,"%s",sRED_FINAL);
 }
moh_lo's avatar
moh_lo committed
726
727
728
<TEMPLATE_ANALYSIS>"\\RED_FINAL_PRM"  {fprintf(fpOutputFile,"%s",sRED_FINAL_PRM);}
<TEMPLATE_ANALYSIS>"\\SURV_PAR_SIZE"  {fprintf(fpOutputFile,"%d",nSURV_PAR_SIZE);}
<TEMPLATE_ANALYSIS>"\\SURV_OFF_SIZE"  {fprintf(fpOutputFile,"%d",nSURV_OFF_SIZE);}
Frederic's avatar
Frederic committed
729
730
<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
731
732
733
734
<TEMPLATE_ANALYSIS>"\\NB_GEN"  {fprintf(fpOutputFile,"%d",nNB_GEN);}
<TEMPLATE_ANALYSIS>"\\NB_ISLANDS"  {fprintf(fpOutputFile,"%d",nNB_ISLANDS);}
<TEMPLATE_ANALYSIS>"\\PROP_OR_SEQ"  {fprintf(fpOutputFile,"%s",bPROP_SEQ?"Prop":"Seq");}
<TEMPLATE_ANALYSIS>"\\MUT_PROB"  {if (TARGET==GALIB)fprintf(fpOutputFile,"(float)%f",fMUT_PROB);
maitre's avatar
maitre committed
735
  else fprintf(fpOutputFile,"%f",fMUT_PROB);}
moh_lo's avatar
moh_lo committed
736
<TEMPLATE_ANALYSIS>"\\XOVER_PROB"  {if (TARGET==GALIB)fprintf(fpOutputFile,"(float)%f",fXOVER_PROB);
maitre's avatar
maitre committed
737
  else fprintf(fpOutputFile,"%f",fXOVER_PROB);}
moh_lo's avatar
moh_lo committed
738
739
740
741
<TEMPLATE_ANALYSIS>"\\REPLACEMENT"  {fprintf(fpOutputFile,"%s",sREPLACEMENT);}
<TEMPLATE_ANALYSIS>"\\REPL_PERC"  {fprintf(fpOutputFile,"(float)%f/100",fREPL_PERC);}
<TEMPLATE_ANALYSIS>"\\DISCARD_PRM"  {fprintf(fpOutputFile,"%s",sDISCARD_PRM);}
<TEMPLATE_ANALYSIS>"\\STEADYSTATE"  {if ((fREPL_PERC==0)||(!strcmp(sREPLACEMENT,"Incremental"))||(!strcmp(sREPLACEMENT,"Simple")))
maitre's avatar
maitre committed
742
     fprintf(fpOutputFile,"// undefined ");}
moh_lo's avatar
moh_lo committed
743
<TEMPLATE_ANALYSIS>"\\COMMENT"  {if (mystricmp(sREPLACEMENT,"SSGA")) fprintf(fpOutputFile,"//");}
maitre's avatar
maitre committed
744
745
746
<TEMPLATE_ANALYSIS>"\\MINIMAXI"  {
  switch (TARGET) { 
  case GALIB : fprintf(fpOutputFile,"%d",nMINIMISE? -1:1); break;
moh_lo's avatar
moh_lo committed
747
  case EO : fprintf(fpOutputFile,"%s",nMINIMISE? "eoMinimizingFitness" : "eoMaximizingFitness"); break;
748
749
  //case DREAM : fprintf(fpOutputFile,"%s",nMINIMISE? "false" : "true"); break;
  case DREAM : fprintf(fpOutputFile,"%s",nMINIMISE? "true" : "false"); break;
maitre's avatar
maitre committed
750
751
    
  case STD:
752
753
  //case CUDA: fprintf(fpOutputFile,"%s",(nMINIMISE? "false" : "true")); break;
  case CUDA: fprintf(fpOutputFile,"%s",(nMINIMISE? "true" : "false")); break;
maitre's avatar
maitre committed
754
755
  }
 }
moh_lo's avatar
moh_lo committed
756
<TEMPLATE_ANALYSIS>"\\ELITIST_REPLACE_NAME"  {if (TARGET==EO) {if (bELITISM) fprintf(fpOutputFile,"standardR");
maitre's avatar
maitre committed
757
758
759
760
761
762
763
764
    else fprintf(fpOutputFile,"r");}}
<TEMPLATE_ANALYSIS>"\\ELITISM"  {
  switch (TARGET) { 
  case GALIB : if (!mystricmp(sREPLACEMENT,"simple"))
      if (bELITISM) fprintf(fpOutputFile,"  ga.elitist(gaTrue);\n");
      else fprintf(fpOutputFile,"  ga.elitist(gaFalse);\n");
    break;
  case EO :  fprintf(fpOutputFile,"%d",bELITISM);
765
766
    break;
  case STD:
maitre's avatar
maitre committed
767
768
  case CUDA: fprintf(fpOutputFile,"%d",bELITISM);
  }                                 }
moh_lo's avatar
moh_lo committed
769
770
771
772
773
774
775
776
777
<TEMPLATE_ANALYSIS>"\\IMMIG_SEL" {fprintf(fpOutputFile,"%s",sIMMIG_SEL);}
<TEMPLATE_ANALYSIS>"\\IMMIG_REPL" {fprintf(fpOutputFile,"%d",nIMMIG_REPL);}
<TEMPLATE_ANALYSIS>"\\MIGRATOR" {fprintf(fpOutputFile,"%s",sMIGRATOR);}
<TEMPLATE_ANALYSIS>"\\MIG_SEL" {fprintf(fpOutputFile,"%s",sMIG_SEL);}
<TEMPLATE_ANALYSIS>"\\MIG_CLONE" {fprintf(fpOutputFile,"%d",nMIG_CLONE);}
<TEMPLATE_ANALYSIS>"\\NB_MIG" {fprintf(fpOutputFile,"%d",nNB_MIG);}
<TEMPLATE_ANALYSIS>"\\MIG_FREQ" {fprintf(fpOutputFile,"%f",fMIG_FREQ);}
<TEMPLATE_ANALYSIS>"\\MIG_TARGET_SELECTOR" {fprintf(fpOutputFile,"%s",sMIG_TARGET_SELECTOR);}

maitre's avatar
maitre committed
778
779
780
781
782
783
784
785
<TEMPLATE_ANALYSIS>"\\START_EO_GENOME_H_TPL"  {
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,"Genome.h");
  fpOutputFile=fopen(sFileName,"w");    
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
 }
786

maitre's avatar
maitre committed
787
788
789
790
791
792
793
794
<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);
 }
795

maitre's avatar
maitre committed
796
797
798
799
800
801
802
803
<TEMPLATE_ANALYSIS>"\\START_CUDA_USER_CLASSES_H_TPL"  {
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,"UserClasses.hpp");
  fpOutputFile=fopen(sFileName,"w");    
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
 }
804
805


maitre's avatar
maitre committed
806
807
808
809
<TEMPLATE_ANALYSIS>"\\START_CUDA_GENOME_CU_TPL"  {
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
810
811
812
813
  if( TARGET==CUDA )
    strcat(sFileName,"Individual.cu");
  else if( TARGET==STD )
    strcat(sFileName,"Individual.cpp");
maitre's avatar
maitre committed
814
815
816
  fpOutputFile=fopen(sFileName,"w");    
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
 }
817

maitre's avatar
maitre committed
818
819
820
821
822
823
824
825
<TEMPLATE_ANALYSIS>"\\START_CUDA_TOOLS_CPP_TPL"  {
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,"Tools.cpp");
  fpOutputFile=fopen(sFileName,"w");    
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
 }
826

maitre's avatar
maitre committed
827
828
829
830
831
832
833
834
<TEMPLATE_ANALYSIS>"\\START_CUDA_TOOLS_H_TPL"  {
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,"Tools.hpp");
  fpOutputFile=fopen(sFileName,"w");    
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
 }
835
836


maitre's avatar
maitre committed
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
<TEMPLATE_ANALYSIS>"\\START_CUDA_POPULATION_CPP_TPL"  {
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,"Population.cpp");
  fpOutputFile=fopen(sFileName,"w");    
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
 }

<TEMPLATE_ANALYSIS>"\\START_CUDA_POPULATION_H_TPL"  {
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,"Population.hpp");
  fpOutputFile=fopen(sFileName,"w");    
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
 }
moh_lo's avatar
moh_lo committed
854

855

moh_lo's avatar
moh_lo committed
856
<TEMPLATE_ANALYSIS>"\\START_EO_EVAL_TPL"  {
maitre's avatar
maitre committed
857
858
859
860
861
862
863
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,"EvalFunc.h");
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
  fpOutputFile=fopen(sFileName,"w");
 }
moh_lo's avatar
moh_lo committed
864
<TEMPLATE_ANALYSIS>"\\START_EO_INITER_TPL"  {
maitre's avatar
maitre committed
865
866
867
868
869
870
871
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,"Init.h");
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
  fpOutputFile=fopen(sFileName,"w");
 }
moh_lo's avatar
moh_lo committed
872
<TEMPLATE_ANALYSIS>"\\START_EO_MUT_TPL"  {
maitre's avatar
maitre committed
873
874
875
876
877
878
879
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,"Mutation.h");
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
  fpOutputFile=fopen(sFileName,"w");
 }
moh_lo's avatar
moh_lo committed
880
<TEMPLATE_ANALYSIS>"\\START_EO_QUAD_XOVER_TPL"  {
maitre's avatar
maitre committed
881
882
883
884
885
886
887
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,"QuadCrossover.h");
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
  fpOutputFile=fopen(sFileName,"w");
 }
moh_lo's avatar
moh_lo committed
888
<TEMPLATE_ANALYSIS>"\\START_EO_CONTINUE_TPL"  {
maitre's avatar
maitre committed
889
890
891
892
893
894
895
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,"_make_continue.h");
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
  fpOutputFile=fopen(sFileName,"w");
 }
moh_lo's avatar
moh_lo committed
896
<TEMPLATE_ANALYSIS>"\\START_EO_MAKE_GENOTYPE_TPL"  {
maitre's avatar
maitre committed
897
898
899
900
901
902
903
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,"_make_genotype.h");
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
  fpOutputFile=fopen(sFileName,"w");
 }
moh_lo's avatar
moh_lo committed
904
<TEMPLATE_ANALYSIS>"\\START_EO_MAKE_OPERATORS_TPL"  {
maitre's avatar
maitre committed
905
906
907
908
909
910
911
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,"_make_operators.h");
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
  fpOutputFile=fopen(sFileName,"w");
 }
moh_lo's avatar
moh_lo committed
912
<TEMPLATE_ANALYSIS>"\\START_EO_PARAM_TPL"  {
maitre's avatar
maitre committed
913
914
915
916
917
918
919
  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
920
<TEMPLATE_ANALYSIS>"\\START_EO_MAKEFILE_TPL"  {
maitre's avatar
maitre committed
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,".mak");
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
  fpOutputFile=fopen(sFileName,"w");
 }

<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
943
    }
maitre's avatar
maitre committed
944
945
  if( fileNameLength != -1 ){
    // add "Makefile" at the end of path
946
947
948
    //char* cdn = get_current_dir_name();
    char cdn[4096]; 
    getcwd(cdn,4096);
maitre's avatar
maitre committed
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
    size_t cdnLength = strlen(cdn);
    strcpy(sFullFileName,cdn);
    strcat(sFullFileName,"/\0");
    strcat(sFullFileName,sFileName);
    
    strncpy(sPathName,sRAW_PROJECT_NAME,fileNameLength);
    strcpy(sPathName+fileNameLength,"/Makefile");
    
    DEBUG_PRT("PathName is %s",sPathName);
    DEBUG_PRT("FullFileName is %s",sFullFileName);
    
  
    // create a symbolic link from Makefile to EASEA.mak
    symlink(sFullFileName,sPathName);
  }
maitre's avatar
maitre committed
964
965
966
967
968
  else{
    DEBUG_PRT("file name : %s",sFileName);
    if( symlink(sFileName,"Makefile") ) perror("Symlink creation error ");
  }

maitre's avatar
maitre committed
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989

  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);
  }
 }


<TEMPLATE_ANALYSIS>"\\START_EVAL_TPL"  {
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,"Evaluator.java");
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
  fpOutputFile=fopen(sFileName,"w");
 }
moh_lo's avatar
moh_lo committed
990
<TEMPLATE_ANALYSIS>"\\START_INITER_TPL"  {
maitre's avatar
maitre committed
991
992
993
994
995
996
997
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,"Initer.java");
  fpOutputFile=fopen(sFileName,"w");    
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
 }
moh_lo's avatar
moh_lo committed
998
<TEMPLATE_ANALYSIS>"\\START_GENOME_TPL"  {
maitre's avatar
maitre committed
999
1000
1001
1002
1003
1004
1005
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,"Genome.java");
  fpOutputFile=fopen(sFileName,"w");    
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
 }
moh_lo's avatar
moh_lo committed
1006
<TEMPLATE_ANALYSIS>"\\START_MUT_TPL"  {
maitre's avatar
maitre committed
1007
1008
1009
1010
1011
1012
1013
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,"Mutator.java");
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
  fpOutputFile=fopen(sFileName,"w");
 }
moh_lo's avatar
moh_lo committed
1014
<TEMPLATE_ANALYSIS>"\\START_RECOMB_TPL"  {
maitre's avatar
maitre committed
1015
1016
1017
1018
1019
1020
1021
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,"Recombine.java");
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
  fpOutputFile=fopen(sFileName,"w");
 }
moh_lo's avatar
moh_lo committed
1022
<TEMPLATE_ANALYSIS>"\\START_IHDEF_TPL"  {
maitre's avatar
maitre committed
1023
1024
1025
1026
1027
1028
1029
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,"IHDefIniter.java");
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
  fpOutputFile=fopen(sFileName,"w");
 }
moh_lo's avatar
moh_lo committed
1030
<TEMPLATE_ANALYSIS>"\\START_FITINIT_TPL"  {
maitre's avatar
maitre committed
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,"FitnessIniter.java");
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
  fpOutputFile=fopen(sFileName,"w");
 }
<TEMPLATE_ANALYSIS>"\\START_ISLAND_TPL"  {
  char sFileName[1000];
  fclose(fpOutputFile);
  strcpy(sFileName, sRAW_PROJECT_NAME);
  strcat(sFileName,"Island.java");
  if (bVERBOSE) printf("Creating %s...\n",sFileName);
  fpOutputFile=fopen(sFileName,"w");
 }
moh_lo's avatar
moh_lo committed
1046
<TEMPLATE_ANALYSIS>"\\TEMPLATE_END"  {
maitre's avatar
maitre committed
1047
1048
1049
1050
1051
1052
  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");
  if (OPERATING_SYSTEM==UNIX){
    if (TARGET==GALIB) {
      printf ("\nYou may now compile your file with:\n");
      printf ("\ng++ %s.cpp -o %s %sgdc.o %sgdchart.o %sprice_conv.o -lga -L%sgdchart0.94b/gd1.3 -lgd -lm\n\n",sPROJECT_NAME,sPROJECT_NAME,sEZ_PATH,sEZ_PATH,sEZ_PATH,sEZ_PATH);
moh_lo's avatar
moh_lo committed
1053
    }
maitre's avatar
maitre committed
1054
1055
1056
1057
1058
1059
1060
    if (TARGET==EO) {
      printf ("\nYou may now compile your file with:\n");
      printf ("\nmake -f %s.mak\n\n",sPROJECT_NAME);
      printf ("and run it with:\n\n",sPROJECT_NAME);
      printf ("%s @%s.prm\n\n",sPROJECT_NAME,sPROJECT_NAME);
    } }
  printf ("Have a nice compile time.\n");
1061
  if (TARGET==EO || TARGET==CUDA || TARGET==STD) fprintf(fpOutputFile,"\n# That's all folks ! \n");
maitre's avatar
maitre committed
1062
1063
1064
1065
1066
1067
  else fprintf(fpOutputFile,"\n// That's all folks ! \n");
  fflush(fpOutputFile);
  fclose(fpOutputFile);
  fclose(fpTemplateFile);
  fclose(fpGenomeFile);
 }
moh_lo's avatar
moh_lo committed
1068
1069
1070
1071
1072
1073
1074
1075

<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
1076
1077
1078
  fprintf (fpOutputFile,"// Genome Initialiser\n"); 
  BEGIN COPY;
 }                                                               
moh_lo's avatar
moh_lo committed
1079
<COPY_EO_INITIALISER><<EOF>> {
moh_lo's avatar
moh_lo committed
1080
1081
1082
1083
1084
1085
  if (bVERBOSE) printf("*** No genome initialiser was found. ***\n");
  rewind(fpGenomeFile);
  yyin = fpTemplateFile;
  BEGIN TEMPLATE_ANALYSIS;
  bNotFinishedYet=1;
 }
moh_lo's avatar
moh_lo committed
1086
1087
1088
<COPY_EO_INITIALISER>.|\n {}                                      

<COPY_USER_DECLARATIONS>"\\User"[ \t\n]+"declarations"[ \t\n]*":" {
maitre's avatar
maitre committed
1089
1090
1091
  fprintf (fpOutputFile,"// User declarations\n"); 
  BEGIN COPY;
 }                                                               
moh_lo's avatar
moh_lo committed
1092
<COPY_USER_DECLARATIONS><<EOF>> {
moh_lo's avatar
moh_lo committed
1093
1094
1095
1096
1097
1098
  if (bVERBOSE) printf("*** No user declarations were found. ***\n");
  rewind(fpGenomeFile);
  yyin = fpTemplateFile;
  BEGIN TEMPLATE_ANALYSIS;
  bNotFinishedYet=1;
 }
moh_lo's avatar
moh_lo committed
1099
1100
1101
<COPY_USER_DECLARATIONS>.|\n {}                                      

<COPY_USER_FUNCTIONS>"\\User"[ \t\n]+"functions"[ \t\n]*":" {
maitre's avatar
maitre committed
1102
1103
1104
  fprintf (fpOutputFile,"// User functions\n\n"); 
  BEGIN COPY;
 }                                                               
moh_lo's avatar
moh_lo committed
1105
<COPY_USER_FUNCTIONS><<EOF>> {
moh_lo's avatar
moh_lo committed
1106
1107
1108
1109
1110
1111
  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
1112
 }
moh_lo's avatar
moh_lo committed
1113
1114
<COPY_USER_FUNCTIONS>.|\n {}                                      

1115
<COPY_INITIALISATION_FUNCTION>"\\before"[ \t\n]+"everything"[ \t\n]+"else"[ \t\n]+"function"[ \t\n]*":" {
maitre's avatar
maitre committed
1116
1117
1118
1119
1120
1121
1122
1123
  if (TARGET==DREAM)
    fprintf (fpOutputFile,"// Evaluator Constructor\n\n  public %sEvaluator(){",sPROJECT_NAME);
  else 
    fprintf (fpOutputFile,"// Initialisation function\nvoid EASEAInitFunction(int argc, char *argv[]){");
  bFunction=1; bInitFunction=1;
      
  BEGIN COPY;
 }
1124
1125
1126
<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
1127
1128
1129
1130
1131
1132
  rewind(fpGenomeFile);
  yyin = fpTemplateFile;
  BEGIN TEMPLATE_ANALYSIS;
  bNotFinishedYet=1;
 }
<COPY_INITIALISATION_FUNCTION>.|\n {}                                      
moh_lo's avatar
moh_lo committed
1133

maitre's avatar
maitre committed
1134
1135
1136
//****************************************
//  Easea GPGPU & EO Finalization function
//****************************************
1137
<COPY_FINALIZATION_FUNCTION>"\\after"[ \t\n]+"everything"[ \t\n]+"else"[ \t\n]+"function"[ \t\n]*":" {
maitre's avatar
maitre committed
1138
1139
1140
1141
1142
  switch( TARGET ){

  case EO:
    fprintf (fpOutputFile,"// Finalization function\n\nvoid EASEAFinalFunction(eoPop<Indi>& population){");
    break;
1143
  case STD:
maitre's avatar
maitre committed
1144
  case CUDA:
1145
    fprintf (fpOutputFile,"// Finalization function\nvoid EASEAFinalization(Population* population){");
maitre's avatar
maitre committed
1146
1147
    break;
  default:
maitre's avatar
maitre committed
1148
    fprintf (stderr," Error this template doesn't support finalization function ");
maitre's avatar
maitre committed
1149
1150
1151
    return -1;
  }
  bFunction=1; bFinalizationFunction=1;
moh_lo's avatar
moh_lo committed
1152
  BEGIN COPY;
maitre's avatar
maitre committed
1153
 }
moh_lo's avatar
moh_lo committed
1154

1155
1156
1157
<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
1158
1159
1160
1161
1162
  rewind(fpGenomeFile);
  yyin = fpTemplateFile;
  BEGIN TEMPLATE_ANALYSIS;
  bNotFinishedYet=1;
 }
maitre's avatar
maitre committed
1163
<COPY_FINALIZATION_FUNCTION>.|\n {}                                      
moh_lo's avatar
moh_lo committed
1164
1165


1166
1167
1168
<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]*":" {
  DEBUG_PRT("at each end");
  if( (TARGET==CUDA || TARGET==STD)  ){
maitre's avatar
maitre committed
1169
    fprintf (fpOutputFile,"// Function called at each new generation\nvoid EASEAEndGenerationFunction(EvolutionaryAlgorithm* evolutionaryAlgorithm){\n");
1170
1171
    bFunction=1; 
    bEndGenerationFunction = 1;
maitre's avatar
maitre committed
1172
1173
1174
1175
    BEGIN COPY_USER_GENERATION;
  }
 }

1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
<COPY_END_GENERATION_FUNCTION><<EOF>> {
  bEndGenerationFunction=0; // No Generation function was found in the .ez file
  printf("*** No end generation function was found. ***\n");
  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]*":" {
  DEBUG_PRT("at each beg");
  if( (TARGET==CUDA || TARGET==STD)){
    fprintf (fpOutputFile,"// Function called at each new generation\nvoid EASEABeginningGenerationFunction(EvolutionaryAlgorithm* evolutionaryAlgorithm){\n");
    bFunction=1;
    bBeginGeneration = 0;
    bBeginGenerationFunction = 1;
    BEGIN COPY_USER_GENERATION;
  }
 }

<COPY_BEG_GENERATION_FUNCTION><<EOF>> {
  bBeginGenerationFunction=0; // No Generation function was found in the .ez file
  printf("*** No beginning generation function was found. ***\n");
  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
1213
1214

<COPY_GENERATION_FUNCTION>"\\At"[ \t\n]+"each"[ \t\n]+"new"[ \t\n]+"generation"[ \t\n]*":" {
1215
1216
  DEBUG_PRT("at each");
  if( TARGET==GALIB ){
maitre's avatar
maitre committed
1217
1218
1219
1220
1221
  fprintf (fpOutputFile,"// Function called at each new generation\n\nvoid EASEAGenerationFunction(GAGeneticAlgorithm & g){\n");
  fprintf(fpOutputFile,"  const GAPopulation *pPopulation;\n",sPROJECT_NAME);
  fprintf(fpOutputFile,"  pPopulation=&(g.population());  // to circumvent a bug in GALib\n",sPROJECT_NAME);
  bFunction=1; bGenerationFunction=1;
  BEGIN COPY_USER_GENERATION;
1222
  }
1223
1224
1225
  else if((TARGET==CUDA || TARGET==STD) && !bBeginGeneration && !bEndGeneration ){
      fprintf (fpOutputFile,"// Function called at each new generation\nvoid EASEAGenerationFunction(EvolutionaryAlgorithm* evolutionaryAlgorithm){\n");
      bFunction=1; bGenerationFunction=1;
maitre's avatar
maitre committed
1226
      BEGIN COPY_USER_GENERATION;
1227
  }
maitre's avatar
maitre committed
1228
 }
1229
1230
<COPY_GENERATION_FUNCTION><<EOF>> {
  bGenerationFunction=0; // No Generation function was found in the .ez file
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
  if( bBeginGeneration ){
    if( bVERBOSE ) printf("*** No generation function was found. ***\n");
    fprintf(fpOutputFile,"\n// No at begining of generation function.\n");
  }
  else if ( bEndGeneration ){
    printf("*** No generation function was found. ***\n");
    fprintf(fpOutputFile,"\n// No at end of generation function.\n");
  }
  else{
    printf("*** No generation function was found. ***\n");
    fprintf(fpOutputFile,"\n// No generation function.\n");
  }
maitre's avatar
maitre committed
1243
1244
1245
1246
1247
  rewind(fpGenomeFile);
  yyin = fpTemplateFile;
  BEGIN TEMPLATE_ANALYSIS;
  bNotFinishedYet=1;
 }
moh_lo's avatar
moh_lo committed
1248
1249
<COPY_GENERATION_FUNCTION>.|\n {}                                      

maitre's avatar
maitre committed
1250
1251
1252
1253
1254
1255
1256
1257

<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;
 }
1258
<COPY_BOUND_CHECKING_FUNCTION><<EOF>> {bBoundCheckingFunction=0; // No Generation function was found in the .ez file
maitre's avatar
maitre committed
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
  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
1270
<ANALYSE_USER_CLASSES>"\\User"[ \t\n]+"classes"[ \t\n]*":" {
moh_lo's avatar
moh_lo committed
1271
  BEGIN GENOME_ANALYSIS; return CLASSES;}
maitre's avatar
maitre committed
1272
<ANALYSE_USER_CLASSES>.|\n {}                                      
moh_lo's avatar
moh_lo committed
1273

moh_lo's avatar
moh_lo committed
1274
1275
1276
1277
1278
1279
1280
1281
1282
//****************************************
//  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
1283
1284
  else switch  (TARGET) {
    case GALIB : fprintf(fpOutputFile,"EZ_currentGeneration"); break;
Frederic's avatar
Frederic committed
1285
1286
    case EO : fprintf(fpOutputFile,"generationCounter.value()"); break;
    case STD : fprintf(fpOutputFile,"(*EZ_current_generation)"); break;
maitre's avatar
maitre committed
1287
    }} // local genome name
moh_lo's avatar
moh_lo committed
1288
1289
<COPY>"NB_GEN" |
<COPY>"NB_GEN"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"NB_GEN");
Frederic's avatar
NB_GEN  
Frederic committed
1290
  else fprintf(fpOutputFile,"(*EZ_NB_GEN)");} // local genome name
moh_lo's avatar
moh_lo committed
1291
1292
<COPY>"POP_SIZE" |
<COPY>"POP_SIZE"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"POP_SIZE");
maitre's avatar
maitre committed
1293
  else fprintf(fpOutputFile,"EZ_POP_SIZE");} // local genome name
moh_lo's avatar
moh_lo committed
1294
<COPY>"MUT_PROB" |
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
<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
1305
<COPY>"XOVER_PROB" |
maitre's avatar
maitre committed
1306
1307
1308
1309
1310
1311
1312
<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
1313
1314
<COPY>"REPL_PERC" |
<COPY>"REPL_PERC"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"REPL_PERC");
maitre's avatar
maitre committed
1315
  else fprintf(fpOutputFile,"EZ_REPL_PERC");} // local genome name
moh_lo's avatar
moh_lo committed
1316
1317
<COPY>"MINIMISE" |
<COPY>"MINIMISE"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"MINIMISE");
maitre's avatar
maitre committed
1318
  else fprintf(fpOutputFile,"EZ_MINIMISE");} // local genome name
moh_lo's avatar
moh_lo committed
1319
1320
<COPY>"MINIMIZE" |
<COPY>"MINIMIZE"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"MINIMIZE");
maitre's avatar
maitre committed
1321
  else fprintf(fpOutputFile,"EZ_MINIMIZE");} // local genome name
1322
1323
1324
1325
1326
1327
<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
1328

maitre's avatar
maitre committed
1329
1330
1331
1332
1333
1334
1335
<COPY>"__device__" |
<COPY>"__host__" {
  if( TARGET==CUDA ){
    fprintf(fpOutputFile,"%s",yytext);
  }
 }

moh_lo's avatar
moh_lo committed
1336
1337
1338
<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);}
1339
1340
1341
1342
1343
<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
1344
1345
1346
1347
<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);}
1348
1349
1350
1351
<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);}
<COPY>"false"  {if (TARGET==GALIB) fprintf(fpOutputFile,"gaFalse");
  else fprintf(fpOutputFile,"false");} // local name
moh_lo's avatar
moh_lo committed
1352
<COPY>"false"  {if (TARGET==GALIB) fprintf(fpOutputFile,"gaFalse");
maitre's avatar
maitre committed
1353
  else fprintf(fpOutputFile,"false");} // local name
moh_lo's avatar
moh_lo committed
1354
<COPY>"true"  {if (TARGET==GALIB) fprintf(fpOutputFile,"gaTrue");
maitre's avatar
maitre committed
1355
1356
  else fprintf(fpOutputFile,"true");} // local name
<COPY>[^a-zA-Z0-9_]"bool"[^a-zA-Z0-9_]  {if (TARGET==DREAM) fprintf(fpOutputFile," boolean ");
moh_lo's avatar
moh_lo committed
1357
  else fprintf(fpOutputFile,yytext);}
maitre's avatar
maitre committed
1358
<COPY>"tossCoin"  {if (TARGET==GALIB) fprintf(fpOutputFile,"tossCoin");
moh_lo's avatar
moh_lo committed
1359
1360
1361
  if (TARGET==EO) fprintf(fpOutputFile,"rng.flip");
  if (TARGET==DREAM) fprintf(fpOutputFile,"Math.random()<");
 } // local random name 
maitre's avatar
maitre committed
1362
1363
<COPY>"random"  {
  if (TARGET==DREAM) fprintf(fpOutputFile,"%s.random",sPROJECT_NAME);
1364
  else if( TARGET==CUDA || TARGET==STD) fprintf(fpOutputFile,"globalRandomGenerator->random");
maitre's avatar
maitre committed
1365
  else fprintf(fpOutputFile,"random");}
moh_lo's avatar
moh_lo committed
1366
<COPY>"Genome" {
1367
  if (bWithinEO_Function && TARGET!=CUDA && TARGET!=STD) fprintf(fpOutputFile,"_genotype");
maitre's avatar
maitre committed
1368
  else if(bWithinEO_Function && bWithinCUDA_Initializer )fprintf(fpOutputFile,"(*this)");
moh_lo's avatar
moh_lo committed
1369
  else fprintf(fpOutputFile,"Genome");} // local genome name
moh_lo's avatar
moh_lo committed
1370
1371
<COPY>"identicalGenome"  {fprintf(fpOutputFile,"genome._evaluated");} // local name
<COPY>"#define"[ \t]*  {fprintf(fpOutputFile,"%s",yytext); BEGIN MACRO_IDENTIFIER;} 
maitre's avatar
maitre committed
1372
1373
1374
1375
1376
1377
1378
1379
<COPY>[a-zA-Z0-9_]*[ \t]+"GenomeClass::" {
  int i;
  for (i=0;(yytext[i]!=' ')&&(yytext[i]!=' ');i++);
  yytext[i]=0;
  fprintf(fpOutputFile,"template <class fitT> %s %sGenome<fitT>::",yytext,sPROJECT_NAME);}         
<COPY>"GenomeClass::"  {fprintf(fpOutputFile,"template <class fitT> %sGenome<fitT>::",sPROJECT_NAME);}
<COPY>"GenomeClass"  {
  if (TARGET==EO) fprintf(fpOutputFile,"Indi");
1380
  else if( TARGET==CUDA || TARGET==STD) fprintf(fpOutputFile,"Individual");
maitre's avatar
maitre committed
1381
1382
  else fprintf(fpOutputFile,"%sGenome",sPROJECT_NAME);} // local name
<COPY>"population" {
1383
  if( (TARGET == CUDA || TARGET==STD) && bFinalizationFunction ){
maitre's avatar
maitre committed
1384
1385
1386
1387
    fprintf(fpOutputFile,"(*population)");
  }
  else fprintf(fpOutputFile,"population");
 }
moh_lo's avatar
moh_lo committed
1388
<COPY>"\\end"  {
1389
  if (bFunction==1 && bWithinCUDA_Initializer==0) {
maitre's avatar
maitre committed
1390
1391
    fprintf (fpOutputFile,"}\n"); 
    bFunction=0;
1392
    bWithinCUDA_Initializer=0;
maitre's avatar
maitre committed
1393
  }
moh_lo's avatar
moh_lo committed
1394
1395
  bWithinEO_Function=0;
  rewind(fpGenomeFile); 
1396
1397
  yyin = fpTemplateFile; 
  BEGIN TEMPLATE_ANALYSIS;} // Back to the template file
moh_lo's avatar
moh_lo committed
1398
1399
1400
1401
<COPY>.|\n {putc(yytext[0],fpOutputFile);}                                      

// Looking for an identifier
<MACRO_IDENTIFIER>[a-zA-Z0-9_]* {fprintf(fpOutputFile,"%s",yytext);
maitre's avatar
maitre committed
1402
1403
  pASymbol = new CSymbol(yytext); pASymbol->ObjectType=oMacro;
  BEGIN MACRO_DEFINITION; }
moh_lo's avatar
moh_lo committed
1404
1405
1406
1407
1408
1409
<MACRO_IDENTIFIER>/.|\n {BEGIN COPY;} // If no identifier was found, we're not interested
// Looking for the first number following the macro definition
<MACRO_DEFINITION>[ \t]*  {fprintf(fpOutputFile,"%s",yytext);} // gobbles up spaces and tabs
<MACRO_DEFINITION>[0-9]+"."[0-9]*{exponent}?  |
<MACRO_DEFINITION>"."[0-9]+{exponent}?  |
<MACRO_DEFINITION>[0-9]+{exponent} {fprintf(fpOutputFile,"%s",yytext);
maitre's avatar
maitre committed
1410
1411
1412
1413
1414
1415
1416
1417
1418
  pASymbol->dValue = myStrtod();
  pSymbolTable->insert(pASymbol);
  bSymbolInserted=1;
  BEGIN COPY;}
<MACRO_DEFINITION>[0-9]+           {fprintf(fpOutputFile,"%s",yytext);
  pASymbol->dValue = atoi(yytext);
  pSymbolTable->insert(pASymbol);
  bSymbolInserted=1;
  BEGIN COPY;}
moh_lo's avatar
moh_lo committed
1419
<MACRO_DEFINITION>/.|\n {if (!bSymbolInserted) delete pASymbol;
maitre's avatar
maitre committed
1420
1421
  else bSymbolInserted=0;
  BEGIN COPY;} // If no number was found, we're not interested
moh_lo's avatar
moh_lo committed
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439

//****************************************
//  GENOME_ANALYSIS lexer
//****************************************

// takes care of C++-like comments
<GENOME_ANALYSIS>\/\/[^\n]* ;         // blah blah on a line containing sth else
<GENOME_ANALYSIS>^[ \t]*\/\/[^\n]*\n ; // blah blah on its own on a single line
<GENOME_ANALYSIS>\/\*[^\*]*\*\/ ;  /* blah blah on a line containing sth else */
<GENOME_ANALYSIS>^[ \t]*\/\*[^\*]*\*\/[ \t]*\n ; /* blah blah with nothing before the comment */

// gobbles up white spaces, tabs or carriage returns
<GENOME_ANALYSIS>[ \t]             { /* do nothing */ }
<GENOME_ANALYSIS>^[ \t]*\n      { /*return '\n';*/ }
<GENOME_ANALYSIS>\n                 { /*return '\n';*/ }

// keywords
<GENOME_ANALYSIS>"bool"                  {if (TARGET!=DREAM) yylval.pSymbol = pSymbolTable->find("bool");
maitre's avatar
maitre committed
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
  else yylval.pSymbol = pSymbolTable->find("boolean");
  return BOOL;}
<GENOME_ANALYSIS>"boolean"            {if (TARGET==DREAM){
    yylval.pSymbol = pSymbolTable->find("boolean");
    return BOOL;
  }
  else {
    yylval.pSymbol = new CSymbol(yytext);
    return IDENTIFIER;
  }  }
moh_lo's avatar
moh_lo committed
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
<GENOME_ANALYSIS>"static"                  {return STATIC;}
<GENOME_ANALYSIS>"int"                  {yylval.pSymbol = pSymbolTable->find("int"); return INT;}
<GENOME_ANALYSIS>"double"                  {yylval.pSymbol = pSymbolTable->find("double"); return DOUBLE;}
<GENOME_ANALYSIS>"float"                  {yylval.pSymbol = pSymbolTable->find("float"); return FLOAT;}
<GENOME_ANALYSIS>"char"                  {yylval.pSymbol = pSymbolTable->find("char"); return CHAR;}
<GENOME_ANALYSIS>"pointer"                  {yylval.pSymbol = pSymbolTable->find("pointer"); return POINTER;}
<GENOME_ANALYSIS>"\\end"   {rewind(fpGenomeFile);yyin = fpTemplateFile;BEGIN TEMPLATE_ANALYSIS;} // Back to the template file
  
<GENOME_ANALYSIS>"GenomeClass"        {return GENOME; }                         

maitre's avatar
maitre committed
1460
1461
1462
1463
<GENOME_ANALYSIS>"Methods:" {BEGIN GET_METHODS;
  yylval.szString=yytext;  
  bMethodsInGenome=1;
  return METHODS;}
moh_lo's avatar
moh_lo committed
1464
1465
1466
1467
1468
1469
1470
1471
// number
<GENOME_ANALYSIS>[0-9]+"."[0-9]*{exponent}?  |
<GENOME_ANALYSIS>"."[0-9]+{exponent}?  |
<GENOME_ANALYSIS>[0-9]+{exponent}     { yylval.dValue = myStrtod(); return NUMBER; }
<GENOME_ANALYSIS>[0-9]+ {yylval.dValue=atoi(yytext); return NUMBER;}

// identifier
<GENOME_ANALYSIS>[a-zA-Z_][a-zA-Z0-9_]*    { yylval.pSymbol = new CSymbol(yytext);
maitre's avatar
maitre committed
1472
1473
  return IDENTIFIER; }
<GET_METHODS>[^\}]*   {BEGIN GENOME_ANALYSIS; return END_METHODS;}
moh_lo's avatar
moh_lo committed
1474
1475
1476
1477
1478
1479

//****************************************
//  Looking for a user-supplied display function.
//****************************************

<COPY_DISPLAY>"\\GenomeClass::display"[ \t\n]*":" { 
maitre's avatar
maitre committed
1480
1481
/*   DEBUG_PRT("Display function is at %d line in %s.ez",yylineno,sRAW_PROJECT_NAME); */
/*   fprintf(fpOutputFile,"\n#line %d \"%s.ez\"\n",yylineno,sRAW_PROJECT_NAME); */
maitre's avatar
maitre committed
1482
1483
1484
  bDisplayFunction=bWithinDisplayFunction=1;
  BEGIN COPY_USER_FUNCTION;
 }
moh_lo's avatar
moh_lo committed
1485
<COPY_DISPLAY><<EOF>> {bDisplayFunction=0; // No display function was found in the .ez file
maitre's avatar
maitre committed
1486
1487
1488
1489
1490
1491
  if (bVERBOSE) printf("*** No display function was found. ***\n");
  rewind(fpGenomeFile);
  yyin = fpTemplateFile;
  BEGIN TEMPLATE_ANALYSIS;
  bNotFinishedYet=1;
 }
moh_lo's avatar
moh_lo committed
1492
1493
<COPY_DISPLAY>.|\n {}                                      

1494
1495
1496
1497
1498
1499
1500
<COPY_MAKEFILE_OPTION>"\\User"[ \t\n]+[Mm]"akefile"[ \t\n]+"options"[ \t\n]*":" {
  DEBUG_PRT("LDFLAGS is beg: %s",yytext); 
  bWithinMAKEFILEOPTION=1;
  return MAKEFILE_OPTION;
 }


moh_lo's avatar
moh_lo committed
1501
//****************************************
1502
1503
//  Looks for Makefile options (like 
//  LDFLAGS+= or CPPFLAGS...)
moh_lo's avatar
moh_lo committed
1504
//****************************************
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
<COPY_MAKEFILE_OPTION>"\\end" {
  if( bWithinMAKEFILEOPTION ){
    DEBUG_PRT("end of makefile options");
    yyin = fpTemplateFile;
    bWithinMAKEFILEOPTION = 0;
    BEGIN TEMPLATE_ANALYSIS;
    return END_OF_FUNCTION;
  }
 }

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

<COPY_MAKEFILE_OPTION>\n {
  if( bWithinMAKEFILEOPTION );
 }

<COPY_MAKEFILE_OPTION><<EOF>> { 
  DEBUG_PRT("No makefile options defined.");
moh_lo's avatar
moh_lo committed
1527

1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
  yyin = fpTemplateFile;
  bWithinMAKEFILEOPTION = 0;
  BEGIN TEMPLATE_ANALYSIS;

  return MAKEFILE_OPTION;
 }

//****************************************
//  Looks for standard and user functions in the .ez file
//****************************************
moh_lo's avatar
moh_lo committed
1538
<COPY_INITIALISER>"\\GenomeClass::initiali"[sz]"er"[ \t\n]*":" {
maitre's avatar
maitre committed
1539
1540
  bWithinInitialiser=1;
  BEGIN COPY_USER_FUNCTION;
1541
  BEGIN TEMPLATE_ANALYSIS;
maitre's avatar
maitre committed
1542
1543
  return USER_CTOR;
 }
moh_lo's avatar
moh_lo committed
1544
1545
<COPY_INITIALISER>.|\n {}                                      
<COPY_CROSSOVER>"\\GenomeClass::crossover"[ \t\n]*":" {
maitre's avatar
maitre committed
1546
1547
1548
1549
  bWithinXover=1;
  BEGIN COPY_USER_FUNCTION;
  return USER_XOVER;
 }
moh_lo's avatar
moh_lo committed
1550
1551
<COPY_CROSSOVER>.|\n {}                                      
<COPY_MUTATOR>"\\GenomeClass::mutator"[ \t\n]*":" {
maitre's avatar
maitre committed
1552
1553
1554
1555
  bWithinMutator=1;
  BEGIN COPY_USER_FUNCTION;
  return USER_MUTATOR;
 }
moh_lo's avatar
moh_lo committed
1556
1557
<COPY_MUTATOR>.|\n {}                                      
<COPY_EVALUATOR>"\\GenomeClass::evaluator"[ \t\n]*":" {
moh_lo's avatar
moh_lo committed
1558
1559
1560
1561
  BEGIN COPY_USER_FUNCTION;            
  bWithinEvaluator=1;
  return USER_EVALUATOR;
 }
moh_lo's avatar
moh_lo committed
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
<COPY_EVALUATOR>.|\n {}                                      

//****************************************
//  Basic copy to .cpp file with major changes
//****************************************

<COPY_USER_GENERATION>\/\/[^\n]* {fprintf(fpOutputFile,yytext);}         // blah blah on a line containing sth else
<COPY_USER_GENERATION>^[ \t]*\/\/[^\n]*\n {fprintf(fpOutputFile,yytext);} // blah blah on its own on a single line
<COPY_USER_GENERATION>\/\*[^\*]*\*\/ {fprintf(fpOutputFile,yytext);}  /* blah blah on a line containing sth else */
<COPY_USER_GENERATION>^[ \t]*\/\*[^\*]*\*\/[ \t]*\n {fprintf(fpOutputFile,yytext);} /* blah blah with nothing before the comment */
<COPY_USER_GENERATION>"Genome"  {fprintf(fpOutputFile,"genome");} // local genome name
<COPY_USER_GENERATION>"\""  {(bDoubleQuotes ? bDoubleQuotes=0:bDoubleQuotes=1); fprintf(fpOutputFile,"\"");}
<COPY_USER_GENERATION>"\\\""  {fprintf(fpOutputFile,"\\\"");}

<COPY_USER_GENERATION>"pPopulation"[ \t\n]*"[" {bWaitingToClosePopulation=true;
maitre's avatar
maitre committed
1577
1578
  switch (TARGET) {
  case EO: fprintf(fpOutputFile,"pPopulation ["); break;
1579
1580
1581
1582
1583
  case GALIB: 
    fprintf(fpOutputFile,"((%sGenome *)&(pPopulation->individual(",sPROJECT_NAME); 
    break;
  case CUDA:
  case STD:
maitre's avatar
maitre committed
1584
1585
    //fprintf(fpOutputFile,"(*evolutionaryAlgorithm->getPopulation())");
    fprintf(fpOutputFile,"pPopulation[");
maitre's avatar
maitre committed
1586
1587
  }
 }
moh_lo's avatar
moh_lo committed
1588
<COPY_USER_GENERATION>"]" {if (!bWaitingToClosePopulation) fprintf(fpOutputFile,"]");