EaseaParse.y 22.4 KB
Newer Older
moh_lo's avatar
moh_lo committed
1
2
3
4
5
6
7
8
9
10
11
12
%{
/****************************************************************************
EaseaLex.y
Parser for the EASEA language (EAsy Specification for Evolutionary Algorithms)

Pierre COLLET (Pierre.Collet@polytechnique.fr)
Ecole Polytechnique
Centre de Mathmatiques Appliques
91128 Palaiseau cedex
****************************************************************************/

#include "Easea.h"
moh_lo's avatar
moh_lo committed
13
#include "debug.h"
maitre's avatar
maitre committed
14
#include "EaseaYTools.h"
moh_lo's avatar
moh_lo committed
15
16
17
18
19

// Globals     
CSymbol *pCURRENT_CLASS;
CSymbol *pCURRENT_TYPE;
CSymbol *pGENOME;
maitre's avatar
maitre committed
20
CSymbol* pCLASSES[128];
moh_lo's avatar
moh_lo committed
21
char sRAW_PROJECT_NAME[1000];
maitre's avatar
maitre committed
22
int nClasses_nb = 0;
moh_lo's avatar
moh_lo committed
23
24
25
26
27
char sPROJECT_NAME[1000];
char sLOWER_CASE_PROJECT_NAME[1000];
char sEZ_FILE_NAME[1000];
char sEO_DIR[1000];
char sEZ_PATH[1000];
kruger's avatar
kruger committed
28
char sTPL_DIR[1000];
29
int TARGET,TARGET_FLAVOR;
moh_lo's avatar
moh_lo committed
30
31
32
int OPERATING_SYSTEM;
int nWARNINGS=0;
int nERRORS=0;
maitre's avatar
maitre committed
33
34
35
36
37
38
39
40
char sSELECTOR[50], sSELECTOR_OPERATOR[50];
float fSELECT_PRM=0.0;
char sRED_PAR[50], sRED_PAR_OPERATOR[50];
float fRED_PAR_PRM=0.0;//[50] = {0};
char sRED_OFF[50], sRED_OFF_OPERATOR[50];
float fRED_OFF_PRM;//[50] = {0};
char sRED_FINAL[50], sRED_FINAL_OPERATOR[50];
float fRED_FINAL_PRM=0.0;//[50];
moh_lo's avatar
moh_lo committed
41
int nMINIMISE=2;
kruger's avatar
kruger committed
42
int nELITE=0;
moh_lo's avatar
moh_lo committed
43
bool bELITISM=0;
maitre's avatar
maitre committed
44
bool bVERBOSE=0;
45
bool bLINE_NUM_EZ_FILE=1;
maitre's avatar
maitre committed
46
47
bool bPRINT_STATS=1;
bool bPLOT_STATS=0;
kruger's avatar
kruger committed
48
49
bool bGENERATE_CSV_FILE=0, bGENERATE_R_SCRIPT=0, bGENERATE_GNUPLOT_SCRIPT=0;
bool bBALDWINISM=0;
maitre's avatar
maitre committed
50
51
int nPOP_SIZE, nOFF_SIZE;
float fSURV_PAR_SIZE=-1.0, fSURV_OFF_SIZE=-1.0;
Frederic's avatar
Frederic committed
52
53
char *nGENOME_NAME;
int nPROBLEM_DIM;
kruger's avatar
kruger committed
54
55
int nNB_GEN=0;
int nNB_OPT_IT=0;
maitre's avatar
maitre committed
56
int nTIME_LIMIT=0;
moh_lo's avatar
moh_lo committed
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
float fMUT_PROB;
float fXOVER_PROB;
FILE *fpOutputFile, *fpTemplateFile, *fpGenomeFile;//, *fpExplodedGenomeFile;
%}

// include file
%include {
// forward references
class CSymbol;
}

// attribute type
%union {
  CSymbol* pSymbol;
  double dValue;
  int ObjectQualifier;
  int nValue;
  char *szString;
}

// nonterminals
%type <dValue> Expr
%type <ObjectQualifier> Qualifier
%type <pSymbol> BaseType
%type <pSymbol> UserType
%type <pSymbol> Symbol

// tokens
%right '='
%left '+', '-'
%left '*', '/'
%right UMINUS

// keywords

// .ez file tokens
%token CLASSES
%token GENOME
%token USER_CTOR
%token USER_XOVER
%token USER_MUTATOR
%token USER_EVALUATOR                   
kruger's avatar
kruger committed
99
%token USER_OPTIMISER
100
%token MAKEFILE_OPTION
moh_lo's avatar
moh_lo committed
101
102
%token END_OF_FUNCTION                   
//%token DELETE
maitre's avatar
maitre committed
103
%token <szString> END_METHODS
moh_lo's avatar
moh_lo committed
104
105
106
107
108
109
110
111
112
113
%token <pSymbol> IDENTIFIER
%token <pSymbol> IDENTIFIER2
%token <pSymbol> BOOL
%token <pSymbol> INT
%token <pSymbol> DOUBLE
%token <pSymbol> FLOAT
%token <pSymbol> CHAR
%token <pSymbol> POINTER
%token <dValue> NUMBER
%token <dValue> NUMBER2
maitre's avatar
maitre committed
114
%token METHODS
moh_lo's avatar
moh_lo committed
115
116
%token STATIC       
%token NB_GEN       
kruger's avatar
kruger committed
117
118
%token NB_OPT_IT //Memetic 
%token BALDWINISM //Memetic
moh_lo's avatar
moh_lo committed
119
120
121
122
123
124
125
126
127
128
129
130
131
%token MUT_PROB
%token XOVER_PROB                       
%token POP_SIZE
%token SELECTOR
%token RED_PAR
%token RED_OFF
%token RED_FINAL
%token OFFSPRING
%token SURVPAR
%token SURVOFF
%token MINIMAXI
%token ELITISM
%token ELITE
maitre's avatar
maitre committed
132
133
%token PRINT_STATS
%token PLOT_STATS
kruger's avatar
kruger committed
134
%token GENERATE_CSV_FILE
maitre's avatar
maitre committed
135
136
137
%token GENERATE_GNUPLOT_SCRIPT
%token GENERATE_R_SCRIPT
%token TIME_LIMIT
moh_lo's avatar
moh_lo committed
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// include file
%include {
#include "EaseaSym.h"
#include "EaseaLex.h"
}

// parser name and class definition
%name CEASEAParser
{
protected:
  CEASEALexer EASEALexer;       // the lexical analyser
  
public:
  CSymbolTable SymbolTable;    // the symbol table

  int create();
  
  double assign(CSymbol* pIdentifier, double dValue);
  double divide(double dDividend, double dDivisor);
  CSymbol* insert() const;
}

// constructor
{
      CSymbol *pNewBaseType;

maitre's avatar
maitre committed
164
      pNewBaseType=new CSymbol("bool");
moh_lo's avatar
moh_lo committed
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
      pNewBaseType->nSize=sizeof(bool);   
      pNewBaseType->ObjectType=oBaseClass;
      SymbolTable.insert(pNewBaseType);

      pNewBaseType=new CSymbol("int");
      pNewBaseType->nSize=sizeof(int);   
      pNewBaseType->ObjectType=oBaseClass;
      SymbolTable.insert(pNewBaseType);

      pNewBaseType=new CSymbol("double");
      pNewBaseType->nSize=sizeof(double);   
      pNewBaseType->ObjectType=oBaseClass;
      SymbolTable.insert(pNewBaseType);

      pNewBaseType=new CSymbol("float");
      pNewBaseType->nSize=sizeof(float);   
      pNewBaseType->ObjectType=oBaseClass;
      SymbolTable.insert(pNewBaseType);

      pNewBaseType=new CSymbol("char");
      pNewBaseType->nSize=sizeof(char);   
      pNewBaseType->ObjectType=oBaseClass;
      SymbolTable.insert(pNewBaseType);

      pNewBaseType=new CSymbol("pointer");
      pNewBaseType->nSize=sizeof(char *);   
      pNewBaseType->ObjectType=oBaseClass;
      SymbolTable.insert(pNewBaseType);
}

%start EASEA
%%

EASEA :  RunParameters GenomeAnalysis;

GenomeAnalysis
    : ClassDeclarationsSection GenomeDeclarationSection {
maitre's avatar
maitre committed
202
203
        if (bVERBOSE){ printf("                    _______________________________________\n");
        printf ("\nGeneration of the C++ source file for %s.\n\n",sPROJECT_NAME);}
moh_lo's avatar
moh_lo committed
204
205
206
207
      }
      StandardFunctionsAnalysis
    | GenomeDeclarationSection {
        if (bVERBOSE) printf("                    _______________________________________\n");
maitre's avatar
maitre committed
208
        if (bVERBOSE) printf ("\nGeneration of the C++ source file for %s.\n\n",sPROJECT_NAME);
moh_lo's avatar
moh_lo committed
209
210
211
212
213
214
      }
      StandardFunctionsAnalysis
  ;

ClassDeclarationsSection
  : CLASSES {
maitre's avatar
maitre committed
215
    if (bVERBOSE) printf("Declaration of user classes :\n\n");} 
moh_lo's avatar
moh_lo committed
216
217
218
219
220
221
    ClassDeclarations
  | CLASSES {
      if (bVERBOSE) printf("No user class declaration found other than GenomeClass.\n");} 
  ;
  
ClassDeclarations
maitre's avatar
maitre committed
222
223
: ClassDeclaration 
| ClassDeclarations ClassDeclaration
moh_lo's avatar
moh_lo committed
224
225
226
227
228
229
230
  ;
  
ClassDeclaration
  : Symbol {
      pCURRENT_CLASS=SymbolTable.insert($1);  
      pCURRENT_CLASS->pSymbolList=new CLList<CSymbol *>();
      $1->ObjectType=oUserClass;
kruger's avatar
kruger committed
231
      //DEBUG_PRT("Yacc Symbol declaration %s %d",$1->sName,$1->nSize);
maitre's avatar
maitre committed
232
      pCLASSES[nClasses_nb++] = $1;
moh_lo's avatar
moh_lo committed
233
234
235
    }
  '{' VariablesDeclarations '}' {
      if (bVERBOSE) printf("Class %s declared for %d bytes.\n\n",$1->sName,$1->nSize);
kruger's avatar
kruger committed
236
      //DEBUG_PRT("Yacc variable declaration %s %d",$1->sName,$1->nSize);
moh_lo's avatar
moh_lo committed
237
238
239
240
241
242
243
244
245
246
247
248
    }                       
  ;

VariablesDeclarations
  : VariablesDeclaration    
  | VariablesDeclarations VariablesDeclaration    
  ;                             
  
// TypeSize initialisation in a separate rule to avoid reduce/reduce conflict
VariablesDeclaration
  : Qualifier BaseType {pCURRENT_TYPE=$2; pCURRENT_TYPE->ObjectQualifier=$1;} BaseObjects {}
  | Qualifier UserType {pCURRENT_TYPE=$2; pCURRENT_TYPE->ObjectQualifier=$1;} UserObjects {}
maitre's avatar
maitre committed
249
250
251
252
253
254
255
256
257
  | MethodsDeclaration
  ;

MethodsDeclaration
  : METHODS END_METHODS{
    pCURRENT_CLASS->sString = new char[strlen($2) + 1];
    strcpy(pCURRENT_CLASS->sString, $2);      
    if (bVERBOSE) printf("\n    The following methods have been declared:\n\n%s\n\n",pCURRENT_CLASS->sString);
    }
moh_lo's avatar
moh_lo committed
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
  ;

Qualifier
  : STATIC {$$=1;}  // 1=Static
  | {$$=0;} // 0=Normal
  ;
  
BaseObjects
  : Objects ';'
  | Objects ':' BaseConstructorParameters ';' {}
  ;

UserObjects
  : Objects ';' {}
  | Objects ':' UserConstructorParameters ';' {}
  ;
  
BaseType
  : BOOL
  | INT
  | DOUBLE
  | FLOAT
  | CHAR
  | POINTER
  ;
  
UserType
  : Symbol {  
      CSymbol *pSym=SymbolTable.find($1->sName);
      if (pSym==NULL) {
        fprintf(stderr,"\n%s - Error line %d: Class \"%s\" was not defined.\n",sEZ_FILE_NAME,EASEALexer.yylineno,$1->sName);
        fprintf(stderr,"Only base types (bool, int, float, double, char) or new user classes defined\nwithin the \"User classes\" sections are allowed.\n");
        exit(1);
      }       
      else $$=pSym;
    }
  ;

Objects
  : Object
  | Objects ',' Object
  ;

// Attention : il reste  grer correctement les tableaux de pointeurs
// les indirections multiples et les tableaux  plusieurs dimensions.
// Je sais, il faudrait aussi utiliser un peu de polymorphisme pour les symboles
  
Object
  : Symbol {
//      CSymbol *pSym;
//      pSym=$1;
        $1->nSize=pCURRENT_TYPE->nSize;
        $1->pClass=pCURRENT_CLASS;
        $1->pType=pCURRENT_TYPE;
        $1->ObjectType=oObject;
        $1->ObjectQualifier=pCURRENT_TYPE->ObjectQualifier;
        pCURRENT_CLASS->nSize+=$1->nSize;
        pCURRENT_CLASS->pSymbolList->addFirst((CSymbol *)($1));
        if (bVERBOSE) printf("    %s variable declared (%d bytes)\n",$1->sName,$1->nSize);
maitre's avatar
maitre committed
317
    } 
moh_lo's avatar
moh_lo committed
318
319
320
321
322
323
324
325
326
327
  | '*' Symbol {
      $2->nSize=sizeof (char *);
      $2->pClass=pCURRENT_CLASS;
      $2->pType=pCURRENT_TYPE;
      $2->ObjectType=oPointer;
      $2->ObjectQualifier=pCURRENT_TYPE->ObjectQualifier;
      pCURRENT_CLASS->nSize+=$2->nSize;
      pCURRENT_CLASS->pSymbolList->addFirst((CSymbol *)($2));
      if (bVERBOSE) printf("    %s pointer declared (%d bytes)\n",$2->sName,$2->nSize);
    }
maitre's avatar
maitre committed
328
329
330
331
332
333
334
335
336
337
338
339
340
  | '*''*' Symbol {
      $3->nSize=sizeof (char *);
      $3->pClass=pCURRENT_CLASS;
      $3->pType=pCURRENT_TYPE;
      $3->ObjectType=oPointer;
      $3->ObjectQualifier=pCURRENT_TYPE->ObjectQualifier;
      pCURRENT_CLASS->nSize+=$3->nSize;
      pCURRENT_CLASS->pSymbolList->addFirst((CSymbol *)($3));
      if (bVERBOSE) printf("    %s pointer of pointer declared (%d bytes)\n",$3->sName,$3->nSize);
      fprintf(stderr,"Pointer of pointer doesn't work properly yet\n");
      exit(-1);
    }

moh_lo's avatar
moh_lo committed
341
  | Symbol  '[' Expr ']' {
Frederic's avatar
Frederic committed
342
      if((TARGET_FLAVOR==STD_FLAVOR_CMAES || TARGET_FLAVOR==CUDA_FLAVOR_CMAES) && nPROBLEM_DIM==0 && strcmp(pCURRENT_CLASS->sName,"Genome")==0) { nGENOME_NAME=$1->sName; nPROBLEM_DIM=(int)$3;}
maitre's avatar
maitre committed
343
344
345

      printf("DEBUG : size of $3 %d nSize %d\n",(int)$3,pCURRENT_TYPE->nSize);

moh_lo's avatar
moh_lo committed
346
347
348
349
350
351
352
353
354
      $1->nSize=pCURRENT_TYPE->nSize*(int)$3;
      $1->pClass=pCURRENT_CLASS;
      $1->pType=pCURRENT_TYPE;
      $1->ObjectType=oArray;
      $1->ObjectQualifier=pCURRENT_TYPE->ObjectQualifier;
      pCURRENT_CLASS->nSize+=$1->nSize;
      pCURRENT_CLASS->pSymbolList->addFirst((CSymbol *)($1));
      if (bVERBOSE) printf("    %s array declared (%d bytes)\n",$1->sName,$1->nSize);
    }
maitre's avatar
maitre committed
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
  | '*' Symbol  '[' Expr ']' {

    // this is for support of pointer array. This should be done in a more generic way in a later version
      if((TARGET_FLAVOR==STD_FLAVOR_CMAES || TARGET_FLAVOR==CUDA_FLAVOR_CMAES) && nPROBLEM_DIM==0 && strcmp(pCURRENT_CLASS->sName,"Genome")==0) { 
	nGENOME_NAME=$2->sName; nPROBLEM_DIM=(int)$4;
      }
      
      //pCURRENT_CLASS->nSize

      $2->nSize=sizeof(char*)*(int)$4;
      $2->pClass=pCURRENT_CLASS;
      $2->pType=pCURRENT_TYPE;
      $2->ObjectType=oArrayPointer;
      $2->ObjectQualifier=pCURRENT_TYPE->ObjectQualifier;
      pCURRENT_CLASS->nSize+=$2->nSize;
      pCURRENT_CLASS->pSymbolList->addFirst((CSymbol *)($2));

      printf("DEBUG : size of $4 %d nSize %d\n",(int)$4,pCURRENT_TYPE->nSize);
      if (bVERBOSE) printf("    %s array of pointers declared (%d bytes)\n",$2->sName,$2->nSize);
    }
moh_lo's avatar
moh_lo committed
375
376
377
378
379
380
381
382
383
384
385
  ;  

BaseConstructorParameters                           
  : BaseConstructorParameter
  | BaseConstructorParameters BaseConstructorParameter
  ;                                                   

BaseConstructorParameter 
  : NUMBER {}
  ;
  
maitre's avatar
maitre committed
386
387
388
389
//Methods
//  : Method
//  | Methods Method
//  ;
moh_lo's avatar
moh_lo committed
390

maitre's avatar
maitre committed
391
392
393
//Method
//  : NUMBER {}
//  ;
moh_lo's avatar
moh_lo committed
394
395
396
  
GenomeDeclarationSection
  : GENOME {
kruger's avatar
kruger committed
397
    ////DEBUG_PRT("Yacc genome decl %s",$1.pSymbol->sName);
moh_lo's avatar
moh_lo committed
398
399
400
401
402
403
      if (bVERBOSE) printf ("\nGenome declaration analysis :\n\n");
      pGENOME=new CSymbol("Genome");
      pCURRENT_CLASS=SymbolTable.insert(pGENOME);  
      pGENOME->pSymbolList=new CLList<CSymbol *>();
      pGENOME->ObjectType=oUserClass;
      pGENOME->ObjectQualifier=0;
maitre's avatar
maitre committed
404
      pGENOME->sString=NULL;
moh_lo's avatar
moh_lo committed
405
    }
maitre's avatar
maitre committed
406
'{' VariablesDeclarations '}' {}
moh_lo's avatar
moh_lo committed
407
  ;
maitre's avatar
maitre committed
408
409
410
411
412
413
414
415
416

//GenomeMethodsDeclaration
//  : GENOME_METHODS GENOME_END_METHODS{
//    pCURRENT_CLASS->sString = new char[strlen($2) + 1];
//    strcpy(pCURRENT_CLASS->sString, $2);      
//    }
//  |
//  ;

moh_lo's avatar
moh_lo committed
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
UserConstructorParameters
  : UserConstructorParameter
  | UserConstructorParameters UserConstructorParameter
  ;

UserConstructorParameter
  : Symbol {}
  ;
                         
Symbol                                        
  : IDENTIFIER {$$=$1;}
  ;                                             
  
StandardFunctionsAnalysis
  : StandardFunctionAnalysis
  | StandardFunctionsAnalysis StandardFunctionAnalysis
  ;
  
StandardFunctionAnalysis
  : USER_CTOR {         
      if (bVERBOSE) printf("Inserting genome initialiser (taken from .ez file).\n");
maitre's avatar
maitre committed
438
439
    } 
    END_OF_FUNCTION {} 
moh_lo's avatar
moh_lo committed
440
441
  | USER_XOVER {
      if (bVERBOSE) printf("Inserting user genome crossover (taken from .ez file).\n");
maitre's avatar
maitre committed
442
443
    } 
    END_OF_FUNCTION {} 
moh_lo's avatar
moh_lo committed
444
445
  | USER_MUTATOR {
      if (bVERBOSE) printf("Inserting user genome mutator (taken from .ez file).\n");
maitre's avatar
maitre committed
446
447
    } 
    END_OF_FUNCTION {}
moh_lo's avatar
moh_lo committed
448
449
  | USER_EVALUATOR { 
      if (bVERBOSE) printf("Inserting user genome evaluator (taken from .ez file).\n");
maitre's avatar
maitre committed
450
    } 
451
    END_OF_FUNCTION {}
kruger's avatar
kruger committed
452
453
454
  | USER_OPTIMISER { 
      if (bVERBOSE) printf("Inserting user genome optimiser (taken from .ez file).\n");
    } 
455
    END_OF_FUNCTION {}
456
   | MAKEFILE_OPTION END_OF_FUNCTION {
kruger's avatar
kruger committed
457
     //DEBUG_PRT("User makefile options have been reduced");
458
459
     }
   | MAKEFILE_OPTION {}
moh_lo's avatar
moh_lo committed
460
461
462
  ;

RunParameters
maitre's avatar
maitre committed
463
464
465
  : Parameter
  | RunParameters Parameter
  ;           
moh_lo's avatar
moh_lo committed
466
467
  
Parameter
maitre's avatar
maitre committed
468
469
  :  NB_GEN NUMBER2
      {nNB_GEN=(int)$2;}
kruger's avatar
kruger committed
470
471
  |  NB_OPT_IT NUMBER2
      {nNB_OPT_IT=(int)$2;}
maitre's avatar
maitre committed
472
473
  |  TIME_LIMIT NUMBER2
      {nTIME_LIMIT=(int)$2;}
maitre's avatar
maitre committed
474
475
476
477
478
479
480
481
  |  MUT_PROB NUMBER2
      {fMUT_PROB=(float)$2;}
  |  XOVER_PROB NUMBER2
      {fXOVER_PROB=(float)$2;}
  |  POP_SIZE NUMBER2
      {nPOP_SIZE=(int)$2;}
  |  SELECTOR IDENTIFIER2{
      strcpy(sSELECTOR, $2->sName);
maitre's avatar
maitre committed
482
      strcpy(sSELECTOR_OPERATOR, $2->sName);
maitre's avatar
maitre committed
483
      switch (TARGET) {
484
485
      case CUDA:
      case STD:
maitre's avatar
maitre committed
486
	pickupSTDSelector(sSELECTOR,&fSELECT_PRM,sEZ_FILE_NAME,&EASEALexer);
maitre's avatar
maitre committed
487
	break;
moh_lo's avatar
moh_lo committed
488
      }
maitre's avatar
maitre committed
489
    }
maitre's avatar
maitre committed
490
491
  |  SELECTOR IDENTIFIER2 NUMBER2 {
      sprintf(sSELECTOR, $2->sName);   
maitre's avatar
maitre committed
492
      sprintf(sSELECTOR_OPERATOR, $2->sName);   
maitre's avatar
maitre committed
493
494
      switch (TARGET) {
      case CUDA:
495
      case STD:
maitre's avatar
maitre committed
496
	pickupSTDSelectorArgument(sSELECTOR,&fSELECT_PRM,sEZ_FILE_NAME,(float)$3,&EASEALexer);
maitre's avatar
maitre committed
497
498
499
	break;
      }
    }
maitre's avatar
maitre committed
500
501
  |  RED_PAR IDENTIFIER2{
        sprintf(sRED_PAR, $2->sName);
maitre's avatar
maitre committed
502
	sprintf(sRED_PAR_OPERATOR, $2->sName);
maitre's avatar
maitre committed
503
        switch (TARGET) {
maitre's avatar
maitre committed
504
505
	case CUDA:
	case STD:
maitre's avatar
maitre committed
506
	  pickupSTDSelector(sRED_PAR,&fRED_PAR_PRM,sEZ_FILE_NAME,&EASEALexer);
maitre's avatar
maitre committed
507
508
509
510
	  break;
	}
    }
|  RED_PAR IDENTIFIER2 NUMBER2 {
maitre's avatar
maitre committed
511
        sprintf(sRED_PAR, $2->sName);
maitre's avatar
maitre committed
512
	sprintf(sRED_PAR_OPERATOR, $2->sName);
maitre's avatar
maitre committed
513
514
        switch (TARGET) {
	case CUDA :
515
	case STD:
maitre's avatar
maitre committed
516
	  pickupSTDSelectorArgument(sRED_PAR,&fRED_PAR_PRM,sEZ_FILE_NAME,(float)$3,&EASEALexer);
maitre's avatar
maitre committed
517
518
519
	  break;
	}
    }
maitre's avatar
maitre committed
520
  |  RED_OFF IDENTIFIER2{
maitre's avatar
maitre committed
521
522
	sprintf(sRED_OFF, $2->sName);
	sprintf(sRED_OFF_OPERATOR, $2->sName);
maitre's avatar
maitre committed
523
      switch (TARGET) {
maitre's avatar
maitre committed
524
525
      case STD:
      case CUDA:
maitre's avatar
maitre committed
526
	pickupSTDSelector(sRED_OFF,&fRED_OFF_PRM,sEZ_FILE_NAME,&EASEALexer);
maitre's avatar
maitre committed
527
528
529
	break;
      }
    }
maitre's avatar
maitre committed
530
  |  RED_OFF IDENTIFIER2 NUMBER2 {
maitre's avatar
maitre committed
531
532
        sprintf(sRED_OFF, $2->sName);
	sprintf(sRED_OFF_OPERATOR, $2->sName);
maitre's avatar
maitre committed
533
        switch (TARGET) {
maitre's avatar
maitre committed
534
535
	case STD:
	case CUDA:
maitre's avatar
maitre committed
536
	  pickupSTDSelectorArgument(sRED_OFF,&fRED_OFF_PRM,sEZ_FILE_NAME,$3,&EASEALexer);
moh_lo's avatar
moh_lo committed
537
538
       }}
  |  RED_FINAL IDENTIFIER2{
maitre's avatar
maitre committed
539
540
        sprintf(sRED_FINAL, $2->sName);
        sprintf(sRED_FINAL_OPERATOR, $2->sName);
moh_lo's avatar
moh_lo committed
541
        switch (TARGET) {
542
543
	case CUDA:
	case STD:
maitre's avatar
maitre committed
544
	  pickupSTDSelector(sRED_FINAL,&fRED_FINAL_PRM,sEZ_FILE_NAME,&EASEALexer);
maitre's avatar
maitre committed
545
	  break;
moh_lo's avatar
moh_lo committed
546
       }}
maitre's avatar
maitre committed
547
  |  RED_FINAL IDENTIFIER2 NUMBER2 {
maitre's avatar
maitre committed
548
549
        sprintf(sRED_FINAL, $2->sName);
        sprintf(sRED_FINAL_OPERATOR, $2->sName);
maitre's avatar
maitre committed
550
551
        switch (TARGET) {
	case CUDA :
552
	case STD:
maitre's avatar
maitre committed
553
	  pickupSTDSelectorArgument(sRED_FINAL,&fRED_FINAL_PRM,sEZ_FILE_NAME,$3,&EASEALexer);
maitre's avatar
maitre committed
554
	  break;
maitre's avatar
maitre committed
555
556
557
	}}
  |  OFFSPRING NUMBER2 {nOFF_SIZE=(int)$2;}
  |  OFFSPRING NUMBER2 '%' {nOFF_SIZE=(int)($2*nPOP_SIZE/100);}
maitre's avatar
maitre committed
558
559
560
561
  |  SURVPAR NUMBER2 {fSURV_PAR_SIZE=(float)$2;}
  |  SURVPAR NUMBER2 '%' {fSURV_PAR_SIZE=(float)($2/100);}
  |  SURVOFF NUMBER2 {fSURV_OFF_SIZE=(float)$2;}
  |  SURVOFF NUMBER2 '%' {fSURV_OFF_SIZE=(float)($2/100);}
moh_lo's avatar
moh_lo committed
562
  |  MINIMAXI IDENTIFIER2 {
maitre's avatar
maitre committed
563
564
      if ((!mystricmp($2->sName,"Maximise")) || (!mystricmp($2->sName,"Maximize"))) nMINIMISE=0;
      else if ((!mystricmp($2->sName,"Minimise")) || (!mystricmp($2->sName,"Minimize"))) nMINIMISE=1;
moh_lo's avatar
moh_lo committed
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
      else {
         fprintf(stderr,"\n%s - Error line %d: The evaluator goal default parameter can only take\n",sEZ_FILE_NAME,EASEALexer.yylineno);
         fprintf(stderr,"two values : maximi[sz]e or minimi[sz]e.\n",sEZ_FILE_NAME,EASEALexer.yylineno);
         exit(1);
       }
      }
  |  ELITE NUMBER2 {
        if ($2!=0) bELITISM=1;
        else bELITISM=0;
        nELITE=(int)$2;
        }
  |  ELITE NUMBER2 '%' {
        if ($2!=0) bELITISM=1;
        else bELITISM=0;
        nELITE=(int)$2*nPOP_SIZE/100;
        }
  |  ELITISM IDENTIFIER2{
maitre's avatar
maitre committed
582
583
      if (!mystricmp($2->sName,"Weak")) bELITISM=0;
      else if (!mystricmp($2->sName,"Strong")) bELITISM=1;
moh_lo's avatar
moh_lo committed
584
      else {
maitre's avatar
maitre committed
585
         fprintf(stderr,"\n%s - Warning line %d: Elitism must be \"Strong\" or \"Weak\".\nDefault value \"Strong\" inserted.\n.",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
moh_lo's avatar
moh_lo committed
586
587
         bELITISM=1;
       }}
kruger's avatar
kruger committed
588
589
590
591
592
593
594
595
  | BALDWINISM IDENTIFIER2{
      if (!mystricmp($2->sName,"False")) bELITISM=0;
      else if (!mystricmp($2->sName,"True")) bELITISM=1;
      else {
         fprintf(stderr,"\n%s - Warning line %d: Lamarckism must be \"True\" or \"False\".\nDefault value \"True\" inserted.\n.",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
         bELITISM=1;
       }}
     
maitre's avatar
maitre committed
596
597
598
599
600
601
602
603
604
605
606
607
  | PRINT_STATS NUMBER2{
      if((int)$2>=1)
	 bPRINT_STATS=1;
      else
	 bPRINT_STATS=0;
    }
  | PLOT_STATS NUMBER2{
      if((int)$2>=1)
	 bPLOT_STATS=1;
      else
	 bPLOT_STATS=0;
    }
kruger's avatar
kruger committed
608
  | GENERATE_CSV_FILE NUMBER2{
maitre's avatar
maitre committed
609
      if((int)$2>=1)
kruger's avatar
kruger committed
610
	 bGENERATE_CSV_FILE=1;
maitre's avatar
maitre committed
611
      else
kruger's avatar
kruger committed
612
	 bGENERATE_CSV_FILE=0;
maitre's avatar
maitre committed
613
614
615
616
617
618
619
620
621
622
623
624
625
    }
  | GENERATE_GNUPLOT_SCRIPT NUMBER2{
      if((int)$2>=1)
	 bGENERATE_GNUPLOT_SCRIPT=1;
      else
	 bGENERATE_GNUPLOT_SCRIPT=0;
    }
  | GENERATE_R_SCRIPT NUMBER2{
      if((int)$2>=1)
	 bGENERATE_R_SCRIPT=1;
      else
	 bGENERATE_R_SCRIPT=0;
    }
moh_lo's avatar
moh_lo committed
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
  ;
  
Expr
  : IDENTIFIER '=' Expr { 
      if (SymbolTable.find($1->sName)==NULL){
         fprintf(stderr,"\n%s - Error line %d: Symbol \"%s\" not found.\n",sEZ_FILE_NAME,EASEALexer.yylineno,$1->sName);
         exit(1);
      }
      $$ = assign(SymbolTable.find($1->sName), $3);
    }
  | Expr '+' Expr                    { $$ = $1 + $3; }
  | Expr '-' Expr                     { $$ = $1 - $3; }
  | Expr '*' Expr                     { $$ = $1 * $3; }
  | Expr '/' Expr                     { $$ = divide($1, $3); }
  | '(' Expr ')'                          { $$ = $2; }
  | '-' Expr %prec UMINUS { $$ = -$2; }
  | NUMBER                         { $$ = $1; }
  | IDENTIFIER{
      if (SymbolTable.find($1->sName)==NULL){
         fprintf(stderr,"\n%s - Error line %d: Symbol \"%s\" not found.\n",sEZ_FILE_NAME,EASEALexer.yylineno,$1->sName);
         exit(1);
      }
      $$ = (SymbolTable.find($1->sName))->dValue;
    }
  ;

%%
                       
/////////////////////////////////////////////////////////////////////////////
// main

int main(int argc, char *argv[]){
  int n = YYEXIT_FAILURE;
  int nParamNb=0;
maitre's avatar
maitre committed
660
661
  char *sTemp;
  int i=0;
moh_lo's avatar
moh_lo committed
662
663
664
665
666
  
  TARGET=bVERBOSE=0;
  sRAW_PROJECT_NAME[0]=0; // used to ask for a filename if no filename is found on the command line.

  while ((++nParamNb) < argc) {
maitre's avatar
maitre committed
667
668
    sTemp=&(argv[nParamNb][0]);
    if ((argv[nParamNb][0]=='-')||(argv[nParamNb][0]=='/')) sTemp=&(argv[nParamNb][1]);
maitre's avatar
maitre committed
669
    if (!mystricmp(sTemp,"cuda")){
maitre's avatar
maitre committed
670
671
672
673
674
675
676
      TARGET=CUDA;
      TARGET_FLAVOR = CUDA_FLAVOR_SO;
    }
    else if( !mystricmp(sTemp,"cuda_mo") ){
      TARGET=CUDA;
      TARGET_FLAVOR = CUDA_FLAVOR_MO;
    }
maitre's avatar
maitre committed
677
678
679
680
    else if( !mystricmp(sTemp,"cuda_gp") ){
      TARGET=STD;
      TARGET_FLAVOR = CUDA_FLAVOR_GP;
    }
681
682
683
684
685
686
687
688
    else if (!mystricmp(sTemp,"std"))  {
      TARGET=STD;
      TARGET_FLAVOR = STD_FLAVOR_SO;
    }
    else if (!mystricmp(sTemp,"std_mo")) {
      TARGET=STD;
      TARGET_FLAVOR = STD_FLAVOR_MO;
    }
Frederic's avatar
Frederic committed
689
690
    else if (!mystricmp(sTemp,"cmaes"))  {
      TARGET=STD;
691
      TARGET_FLAVOR = STD_FLAVOR_CMAES;
Frederic's avatar
Frederic committed
692
    }
Frederic's avatar
Frederic committed
693
694
695
696
    else if (!mystricmp(sTemp,"cmaes_cuda"))  {
      TARGET=CUDA;
      TARGET_FLAVOR = CUDA_FLAVOR_CMAES;
    }
kruger's avatar
kruger committed
697
698
699
700
    else if (!mystricmp(sTemp,"memetic"))  {
      TARGET=STD;
      TARGET_FLAVOR = STD_FLAVOR_MEMETIC;
    }
701
702
703
704
    else if (!mystricmp(sTemp,"memetic_cuda"))  {
      TARGET=CUDA;
      TARGET_FLAVOR = CUDA_FLAVOR_MEMETIC;
    }
maitre's avatar
maitre committed
705

maitre's avatar
maitre committed
706
    else if (!mystricmp(sTemp,"v"))  bVERBOSE=true;
maitre's avatar
maitre committed
707
708
709
    else if (!mystricmp(sTemp,"tl")){
      bLINE_NUM_EZ_FILE=false;
    }
maitre's avatar
maitre committed
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
    else if (!mystricmp(sTemp,"path"))  {
      if (argv[++nParamNb][0]=='"') {
        strcpy(sEZ_PATH,&(argv[nParamNb][1]));
        while (argv[++nParamNb][strlen(argv[nParamNb])]!='"')
          strcat(sEZ_PATH,argv[nParamNb]);
          argv[nParamNb][strlen(argv[nParamNb])]=0;
          strcat(sEZ_PATH,argv[nParamNb]);
      }
      else {
        if (argv[nParamNb][strlen(argv[nParamNb])-1]=='"') argv[nParamNb][strlen(argv[nParamNb])-1]=0;
        strcpy(sEZ_PATH,argv[nParamNb]);
      }
    }
    else if (!mystricmp(sTemp,"eo_dir"))  {
      if (argv[++nParamNb][0]=='"') {
        strcpy(sEO_DIR,&(argv[nParamNb][1]));
        while (argv[++nParamNb][strlen(argv[nParamNb])]!='"')
          strcat(sEO_DIR,argv[nParamNb]);
          argv[nParamNb][strlen(argv[nParamNb])]=0;
          strcat(sEO_DIR,argv[nParamNb]);
      }
      else {
        if (argv[nParamNb][strlen(argv[nParamNb])-1]=='"') argv[nParamNb][strlen(argv[nParamNb])-1]=0;
        strcpy(sEO_DIR,argv[nParamNb]);
      }
    }
moh_lo's avatar
moh_lo committed
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
    else strcpy(sRAW_PROJECT_NAME,argv[nParamNb]);
  }

  CEASEAParser Parser;
  if (Parser.create())  n = Parser.yyparse();
  exit(n);
  return n;
}

/////////////////////////////////////////////////////////////////////////////
// EASEAParser commands

int CEASEAParser::create()
{
  if (!yycreate(&EASEALexer)) {
    return 0;
  }
  if (!EASEALexer.create(this, &SymbolTable)) {
    return 0;
  }
  return 1; // success
}

/////////////////////////////////////////////////////////////////////////////
// calc_parser attribute commands

double CEASEAParser::assign(CSymbol* spIdentifier, double dValue)
{
  assert(spIdentifier != NULL);

  spIdentifier->dValue = dValue;
  return spIdentifier->dValue;
}

double CEASEAParser::divide(double a, double b)
{
  if (b == 0) {
    printf("division by zero\n");
    yyforceerror();   // causes a syntax error
    return 0;
  }
  else {
    return a / b;
  }
}