Commit 6af42808 authored by Thomas Kuntz's avatar Thomas Kuntz

transition from alex and ayac to flex++ and yacc

(it may still need some improvement but it pass regression test for non cuda test)
parent 96e438ca
#ifndef _EASEA__H
#define _EASEA__H
/****************************************************************************
Easea.h
General header for the EASEA language (EAsy Specification for Evolutionary Algorithms)
Pierre COLLET (Pierre.Collet@polytechnique.fr)
Ecole Polytechnique
Centre de Mathmatiques Appliques
Centre de Math?matiques Appliqu?es
91128 Palaiseau cedex
****************************************************************************/
......@@ -34,6 +37,7 @@ Centre de Math
#define WINDOWS 2
#define UNKNOWN_OS 3
#define YYTEXT_SIZE 10000
class CSymbol;
extern CSymbol *pCURRENT_CLASS, *pCURRENT_TYPE, *pGENOME, *pCLASSES[128];
......@@ -65,3 +69,5 @@ extern unsigned iMAX_INIT_TREE_D,iMIN_INIT_TREE_D,iMAX_TREE_D,iNB_GPU,iPRG_BUF_S
// Prototypes
extern int mystricmp(const char *, const char *);
#endif
This diff is collapsed.
#ifndef _EASEALEX_H
#define _EASEALEX_H
#include <clex.h>
#line 158 "EaseaLex.l"
#include "EaseaSym.h"
// forward references
class CEASEAParser;
class CSymbolTable;
class OPCodeDesc;
#line 14 "EaseaLex.h"
#define GENOME_ANALYSIS 2
#define TEMPLATE_ANALYSIS 4
#define MACRO_IDENTIFIER 6
#define MACRO_DEFINITION 8
#define COPY_USER_DECLARATIONS 10
#define COPY_USER_CUDA 12
#define COPY_INITIALISATION_FUNCTION 14
#define ANALYSE_USER_CLASSES 16
#define COPY_EO_INITIALISER 18
#define COPY_GP_OPCODE 20
#define COPY 22
#define COPY_INITIALISER 24
#define COPY_CROSSOVER 26
#define COPY_MUTATOR 28
#define COPY_EVALUATOR 30
#define COPY_OPTIMISER 32
#define COPY_FINALIZATION_FUNCTION 34
#define COPY_DISPLAY 36
#define COPY_USER_FUNCTION 38
#define COPY_USER_GENERATION 40
#define PARAMETERS_ANALYSIS 42
#define GET_PARAMETERS 44
#define COPY_USER_FUNCTIONS 46
#define COPY_GENERATION_FUNCTION_BEFORE_REPLACEMENT 48
#define GET_METHODS 50
#define COPY_MAKEFILE_OPTION 52
#define COPY_BOUND_CHECKING_FUNCTION 54
#define COPY_BEG_GENERATION_FUNCTION 56
#define COPY_END_GENERATION_FUNCTION 58
#define COPY_INSTEAD_EVAL 60
#define GP_RULE_ANALYSIS 62
#define GP_COPY_OPCODE_CODE 64
#define COPY_GP_EVAL 66
/////////////////////////////////////////////////////////////////////////////
// CEASEALexer
#ifndef YYDECLSPEC
#define YYDECLSPEC
#endif
class YYFAR YYDECLSPEC CEASEALexer : public yyflexer {
public:
CEASEALexer();
protected:
void yytables();
virtual int yyaction(int action);
public:
#line 173 "EaseaLex.l"
protected:
CSymbolTable *pSymbolTable; // the symbol table
bool bSymbolInserted,bWithinEvaluator, bWithinOptimiser; // used to change evalutor type from double to float
bool bInitFunction,bDisplayFunction,bFunction, bNotFinishedYet, bWithinEO_Function;
bool bDoubleQuotes,bWithinDisplayFunction,bWithinInitialiser,bWithinMutator,bWithinXover;
bool bWaitingForSemiColon,bFinishNB_GEN,bFinishMINIMISE,bFinishMINIMIZE,bGenerationReplacementFunction;
bool bCatchNextSemiColon,bWaitingToClosePopulation, bMethodsInGenome, bFinalizationFunction;
bool bWithinCUDA_Initializer, bWithinMAKEFILEOPTION, bWithinCUDA_Evaluator, bBoundCheckingFunction;
bool bIsParentReduce, bIsOffspringReduce, bEndGeneration, bBeginGeneration, bEndGenerationFunction, bBeginGenerationFunction, bGenerationFunctionBeforeReplacement;
bool bGPOPCODE_ANALYSIS,bCOPY_GP_EVAL_GPU;
CSymbol *pASymbol;
unsigned iGP_OPCODE_FIELD, accolade_counter;
OPCodeDesc* opDesc[128];
unsigned iNoOp;
enum COPY_GP_EVAL_STATUS {EVAL_HDR,EVAL_BDY,EVAL_FTR};
unsigned iCOPY_GP_EVAL_STATUS;
bool bIsCopyingGPEval;
public:
int create(CEASEAParser* pParser, CSymbolTable* pSymbolTable);
int yywrap();
double myStrtod() const;
#line 91 "EaseaLex.h"
};
#ifndef YYLEXNAME
#define YYLEXNAME CEASEALexer
#endif
#ifndef INITIAL
#define INITIAL 0
#endif
int CEASEALexer_create(CSymbolTable* pSymbolTable);
double myStrtod();
#endif
This diff is collapsed.
This diff is collapsed.
#ifndef _EASEAPARSE_H
#define _EASEAPARSE_H
#include <cyacc.h>
#line 70 "EaseaParse.y"
// forward references
class CSymbol;
#line 12 "EaseaParse.h"
#ifndef YYSTYPE
union tagYYSTYPE {
#line 76 "EaseaParse.y"
CSymbol* pSymbol;
double dValue;
int ObjectQualifier;
int nValue;
char *szString;
#line 23 "EaseaParse.h"
};
#define YYSTYPE union tagYYSTYPE
#endif
#define UMINUS 257
#define CLASSES 258
#define GENOME 259
#define USER_CTOR 260
#define USER_XOVER 261
#define USER_MUTATOR 262
#define USER_EVALUATOR 263
#define USER_OPTIMISER 264
#define MAKEFILE_OPTION 265
#define END_OF_FUNCTION 266
#define END_METHODS 267
#define IDENTIFIER 268
#define IDENTIFIER2 269
#define BOOL 270
#define INT 271
#define DOUBLE 272
#define FLOAT 273
#define GPNODE 274
#define CHAR 275
#define POINTER 276
#define NUMBER 277
#define NUMBER2 278
#define METHODS 279
#define STATIC 280
#define NB_GEN 281
#define NB_OPT_IT 282
#define BALDWINISM 283
#define MUT_PROB 284
#define XOVER_PROB 285
#define POP_SIZE 286
#define SELECTOR 287
#define RED_PAR 288
#define RED_OFF 289
#define RED_FINAL 290
#define OFFSPRING 291
#define SURVPAR 292
#define SURVOFF 293
#define MINIMAXI 294
#define ELITISM 295
#define ELITE 296
#define REMOTE_ISLAND_MODEL 297
#define IP_FILE 298
#define MIGRATION_PROBABILITY 299
#define SERVER_PORT 300
#define PRINT_STATS 301
#define PLOT_STATS 302
#define GENERATE_CSV_FILE 303
#define GENERATE_GNUPLOT_SCRIPT 304
#define GENERATE_R_SCRIPT 305
#define SAVE_POPULATION 306
#define START_FROM_FILE 307
#define TIME_LIMIT 308
#define MAX_INIT_TREE_D 309
#define MIN_INIT_TREE_D 310
#define MAX_XOVER_DEPTH 311
#define MAX_MUTAT_DEPTH 312
#define MAX_TREE_D 313
#define NB_GPU 314
#define PRG_BUF_SIZE 315
#define NO_FITNESS_CASES 316
#line 161 "EaseaParse.y"
#include "EaseaSym.h"
#include "EaseaLex.h"
#line 94 "EaseaParse.h"
/////////////////////////////////////////////////////////////////////////////
// CEASEAParser
#ifndef YYDECLSPEC
#define YYDECLSPEC
#endif
class YYFAR YYDECLSPEC CEASEAParser : public yyfparser {
public:
CEASEAParser();
protected:
void yytables();
virtual void yyaction(int action);
#ifdef YYDEBUG
void YYFAR* yyattribute1(int index) const;
void yyinitdebug(void YYFAR** p, int count) const;
#endif
public:
#line 168 "EaseaParse.y"
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;
virtual void yysyntaxerror();
#line 131 "EaseaParse.h"
};
#ifndef YYPARSENAME
#define YYPARSENAME CEASEAParser
#endif
#endif
/* A Bison parser, made by GNU Bison 2.5. */
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
UMINUS = 258,
CLASSES = 259,
GENOME = 260,
USER_CTOR = 261,
USER_XOVER = 262,
USER_MUTATOR = 263,
USER_EVALUATOR = 264,
USER_OPTIMISER = 265,
MAKEFILE_OPTION = 266,
END_OF_FUNCTION = 267,
END_METHODS = 268,
IDENTIFIER = 269,
IDENTIFIER2 = 270,
BOOL = 271,
INT = 272,
DOUBLE = 273,
FLOAT = 274,
GPNODE = 275,
CHAR = 276,
POINTER = 277,
NUMBER = 278,
NUMBER2 = 279,
METHODS = 280,
STATIC = 281,
NB_GEN = 282,
NB_OPT_IT = 283,
BALDWINISM = 284,
MUT_PROB = 285,
XOVER_PROB = 286,
POP_SIZE = 287,
SELECTOR = 288,
RED_PAR = 289,
RED_OFF = 290,
RED_FINAL = 291,
OFFSPRING = 292,
SURVPAR = 293,
SURVOFF = 294,
MINIMAXI = 295,
ELITISM = 296,
ELITE = 297,
REMOTE_ISLAND_MODEL = 298,
IP_FILE = 299,
MIGRATION_PROBABILITY = 300,
SERVER_PORT = 301,
PRINT_STATS = 302,
PLOT_STATS = 303,
GENERATE_CSV_FILE = 304,
GENERATE_GNUPLOT_SCRIPT = 305,
GENERATE_R_SCRIPT = 306,
SAVE_POPULATION = 307,
START_FROM_FILE = 308,
TIME_LIMIT = 309,
MAX_INIT_TREE_D = 310,
MIN_INIT_TREE_D = 311,
MAX_XOVER_DEPTH = 312,
MAX_MUTAT_DEPTH = 313,
MAX_TREE_D = 314,
NB_GPU = 315,
PRG_BUF_SIZE = 316,
NO_FITNESS_CASES = 317,
TEMPLATE_END = 318
};
#endif
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{
CSymbol* pSymbol;
double dValue;
int ObjectQualifier;
int nValue;
char *szString;
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE yylval;
/* "%code provides" blocks. */
// forward references
class CSymbol;
#include "EaseaSym.h"
#include "EaseaLex.h"
int CEASEAParser_create();
double CEASEAParser_assign(CSymbol* pIdentifier, double dValue);
double CEASEAParser_divide(double dDividend, double dDivisor);
CSymbol* CEASEAParser_insert();
//virtual void yysyntaxerror();
This diff is collapsed.
......@@ -19,6 +19,9 @@
#include "EaseaSym.h"
#include "debug.h"
using std::cout;
using std::endl;
void debug(char *s)
{
#ifdef _DEBUG
......@@ -55,7 +58,7 @@ template <class T> CListItem<T> *CLList<T>::walkToNextItem()
/////////////////////////////////////////////////////////////////////////////
// symbol construction/destruction
CSymbol::CSymbol(char *s)
CSymbol::CSymbol(const char *s)
{
assert(s != NULL);
......@@ -317,7 +320,7 @@ void CSymbol::print(FILE *fp)
fprintf(fpOutputFile,"\tif(strcmp(line.c_str(),\"NULL\")==0)\n");
fprintf(fpOutputFile,"\t\tthis->%s = NULL;\n",pSym->Object->sName);
fprintf(fpOutputFile,"\telse{\n");
fprintf(fpOutputFile,"\t\tthis->%s = new %s;\n", pSym->Object->sName, pSym->Object->pType->sName);
fprintf(fpOutputFile,"\t\tthis->%s = new %s;\n",pSym->Object->sName, sName);
fprintf(fpOutputFile,"\t\tthis->%s->deserializer(EASEA_Line);\n",pSym->Object->sName);
fprintf(fpOutputFile,"\t}");
}
......
......@@ -14,9 +14,16 @@ Rocquencourt BP 105
#define SYMBOL_H
#include "Easea.h"
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "debug.h"
#include <iostream>
#include <sstream>
#include <string>
using std::string;
using std::ostringstream;
extern void debug (char *);
......@@ -65,7 +72,7 @@ public :
class CSymbol {
public:
CSymbol(char *s);
CSymbol(const char *s);
virtual ~CSymbol();
// Attributes
......@@ -119,8 +126,6 @@ public:
};
using namespace std;
class OPCodeDesc {
public:
unsigned arity;
......
#ifdef WIN32
#define _CRT_SECURE_NO_WARNINGS
#endif
#include "Easea.h"
#include "EaseaLex.h"
#include "debug.h"
#include "EaseaYTools.h"
void pickupSTDSelector(char* sSELECTOR, float* fSELECT_PRM, char* sEZ_FILE_NAME, CEASEALexer* EASEALexer){
void pickupSTDSelector(char* sSELECTOR, float* fSELECT_PRM, char* sEZ_FILE_NAME){
//DEBUG_PRT("Picking up selector without argument %s",sSELECTOR);
if (!mystricmp(sSELECTOR,"Roulette")){
if (nMINIMISE==1) {
fprintf(stderr,"\n%s - Error line %d: The Roulette selection scheme cannot be\n selected when \"minimising the fitness\" is the evaluator goal.\n",
sEZ_FILE_NAME,EASEALexer->yylineno);
sEZ_FILE_NAME,yylineno);
exit(1);
}
else sprintf(sSELECTOR,"Roulette");
......@@ -33,13 +30,13 @@ void pickupSTDSelector(char* sSELECTOR, float* fSELECT_PRM, char* sEZ_FILE_NAME,
if( TARGET==CUDA || TARGET==STD) *fSELECT_PRM = 0.0;
}
else {
fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist in CUDA/STD.\n",sEZ_FILE_NAME,EASEALexer->yylineno, sSELECTOR);
fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist in CUDA/STD.\n",sEZ_FILE_NAME,yylineno, sSELECTOR);
exit(1);
}
}
void pickupSTDSelectorArgument(char* sSELECTOR, float* fSELECT_PRM, char* sEZ_FILE_NAME, float thirdParam, CEASEALexer* EASEALexer){
void pickupSTDSelectorArgument(char* sSELECTOR, float* fSELECT_PRM, char* sEZ_FILE_NAME, float thirdParam){
//DEBUG_PRT("Picking up selector with argument %s %d",sSELECTOR,(int) thirdParam);
if (!mystricmp(sSELECTOR,"Tournament")||!mystricmp(sSELECTOR,"StochTrn")) {
if (thirdParam>=2) {sprintf(sSELECTOR,"Tournament");
......@@ -50,27 +47,27 @@ void pickupSTDSelectorArgument(char* sSELECTOR, float* fSELECT_PRM, char* sEZ_FI
}
else {
fprintf(stderr,"\n%s - Error line %d: The parameter of the Tournament selector must be either >=2 or within ]0.5, 1].\n",
sEZ_FILE_NAME,EASEALexer->yylineno);
sEZ_FILE_NAME,yylineno);
exit(1);
}
}
else if (!mystricmp(sSELECTOR,"Roulette")) {
sprintf(sSELECTOR,"Roulette");
if (thirdParam<1) {fprintf(stderr,"\n%s - Warning line %d: The parameter of Roulette must be greater than one.\nThe parameter will therefore be ignored.",
sEZ_FILE_NAME,EASEALexer->yylineno);
sEZ_FILE_NAME,yylineno);
nWARNINGS++;
}
else *fSELECT_PRM = (float) thirdParam; }
else if (!mystricmp(sSELECTOR,"Random")) {
sprintf(sSELECTOR,"Random");
fprintf(stderr,"\n%s - Warning line %d: The Uniform selector does not (yet) take any parameter in CUDA/STD.\nThe parameter will therefore be ignored.",
sEZ_FILE_NAME,EASEALexer->yylineno);
sEZ_FILE_NAME,yylineno);
nWARNINGS++;
}
else if (!mystricmp(sSELECTOR,"Ranking")) {
sprintf(sSELECTOR,"Ranking");
if ((thirdParam<=1)||(thirdParam>2)) {
fprintf(stderr,"\n%s - Warning line %d: The parameter of Ranking must be in (1,2].\nThe parameter will default to 2.",sEZ_FILE_NAME,EASEALexer->yylineno);
fprintf(stderr,"\n%s - Warning line %d: The parameter of Ranking must be in (1,2].\nThe parameter will default to 2.",sEZ_FILE_NAME,yylineno);
nWARNINGS++;
*fSELECT_PRM = 2.0;
}
......@@ -84,7 +81,7 @@ void pickupSTDSelectorArgument(char* sSELECTOR, float* fSELECT_PRM, char* sEZ_FI
*fSELECT_PRM = 0.0;
}
else {
fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist in CUDA/STD.\n",sEZ_FILE_NAME,EASEALexer->yylineno, sSELECTOR);
fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist in CUDA/STD.\n",sEZ_FILE_NAME,yylineno, sSELECTOR);
exit(1);
}
}
#include "EaseaLex.h"
#include "Easea.h"
//#include "EaseaLex.h"
#include "debug.h"
void pickupSTDSelector(char* sSELECTOR, float* fSELECT_PRM, char* sEZ_FILE_NAME, CEASEALexer* EASEALexer);
void pickupSTDSelectorArgument(char* sSELECTOR, float* fSELECT_PRM, char* sEZ_FILE_NAME, float thirdParam, CEASEALexer* EASEALexer);
extern int yylineno;
void pickupSTDSelector(char* sSELECTOR, float* fSELECT_PRM, char* sEZ_FILE_NAME);
void pickupSTDSelectorArgument(char* sSELECTOR, float* fSELECT_PRM, char* sEZ_FILE_NAME, float thirdParam);
#ifdef DEBUG
#define DEBUG_PRT(format, args...) fprintf (stdout,"***DBG*** %s-%d: "format"\n",__FILE__,__LINE__,##args)
#define DEBUG_YACC(format, args...) fprintf (stdout,"***DBG_YACC*** %s-%d: "format"\n",__FILE__,__LINE__,##args)
#else
#ifndef WIN32
#define DEBUG_PRT(format, args...)
#define DEBUG_YACC(format, args...)
#endif
//#else
//#ifndef WIN32
//#define DEBUG_PRT(format, args...)
//#define DEBUG_YACC(format, args...)
//#endif
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment