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 source diff could not be displayed because it is too large. You can view the blob instead.
#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 source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
#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();
%{
/****************************************************************************
EaseaLex.y
Parser for the EASEA language (EAsy Specification for Evolutionary Algorithms)
Pierre COLLET (Pierre.Collet@polytechnique.fr)
Ecole Polytechnique
Centre de Math�matiques Appliqu�es
91128 Palaiseau cedex
****************************************************************************/
#include "Easea.h"
#include "debug.h"
#include "EaseaYTools.h"
// Globals
CSymbol *pCURRENT_CLASS;
CSymbol *pCURRENT_TYPE;
CSymbol *pGENOME;
CSymbol* pCLASSES[128];
char sRAW_PROJECT_NAME[1000];
int nClasses_nb = 0;
char sPROJECT_NAME[1000];
char sLOWER_CASE_PROJECT_NAME[1000];
char sEZ_FILE_NAME[1000];
char sEO_DIR[1000];
char sEZ_PATH[1000];
char sTPL_DIR[1000];
int TARGET,TARGET_FLAVOR;
int OPERATING_SYSTEM;
int nWARNINGS=0;
int nERRORS=0;
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];
int nMINIMISE=2;
int nELITE=0;
bool bELITISM=0;
bool bVERBOSE=0;
bool bLINE_NUM_EZ_FILE=1;
bool bPRINT_STATS=1;
bool bPLOT_STATS=0;
bool bGENERATE_CSV_FILE=0, bGENERATE_R_SCRIPT=0, bGENERATE_GNUPLOT_SCRIPT=0;
bool bSAVE_POPULATION=0, bSTART_FROM_FILE=0;
bool bBALDWINISM=0; //memetic
bool bREMOTE_ISLAND_MODEL=0; //remote island model
float fMIGRATION_PROBABILITY=0.0;
char sIP_FILE[128]; //remote island model
int nPOP_SIZE, nOFF_SIZE;
float fSURV_PAR_SIZE=-1.0, fSURV_OFF_SIZE=-1.0;
char *nGENOME_NAME;
int nPROBLEM_DIM;
int nNB_GEN=0;
int nNB_OPT_IT=0;
int nTIME_LIMIT=0;
int nSERVER_PORT=0;
float fMUT_PROB;
float fXOVER_PROB;
FILE *fpOutputFile, *fpTemplateFile, *fpGenomeFile;//, *fpExplodedGenomeFile;
unsigned iMAX_INIT_TREE_D,iMIN_INIT_TREE_D,iMAX_TREE_D,iNB_GPU,iPRG_BUF_SIZE,iMAX_TREE_DEPTH,iMAX_XOVER_DEPTH,iNO_FITNESS_CASES;
%}
// 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
%token USER_OPTIMISER
%token MAKEFILE_OPTION
%token END_OF_FUNCTION
//%token DELETE
%token <szString> END_METHODS
%token <pSymbol> IDENTIFIER
%token <pSymbol> IDENTIFIER2
%token <pSymbol> BOOL
%token <pSymbol> INT
%token <pSymbol> DOUBLE
%token <pSymbol> FLOAT
%token <pSymbol> GPNODE
%token <pSymbol> CHAR
%token <pSymbol> POINTER
%token <dValue> NUMBER
%token <dValue> NUMBER2
%token METHODS
%token STATIC
%token NB_GEN
%token NB_OPT_IT //Memetic
%token BALDWINISM //Memetic
%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
%token REMOTE_ISLAND_MODEL //island model
%token IP_FILE //island model
%token MIGRATION_PROBABILITY //island model
%token SERVER_PORT //server port
%token PRINT_STATS
%token PLOT_STATS
%token GENERATE_CSV_FILE
%token GENERATE_GNUPLOT_SCRIPT
%token GENERATE_R_SCRIPT
%token SAVE_POPULATION
%token START_FROM_FILE
%token TIME_LIMIT
%token MAX_INIT_TREE_D
%token MIN_INIT_TREE_D
%token MAX_XOVER_DEPTH
%token MAX_MUTAT_DEPTH
%token MAX_TREE_D
%token NB_GPU
%token PRG_BUF_SIZE
%token NO_FITNESS_CASES
// 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;
virtual void yysyntaxerror();
}
// constructor
{
CSymbol *pNewBaseType;
pNewBaseType=new CSymbol("bool");
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 {
if (bVERBOSE){ printf(" _______________________________________\n");
printf ("\nGeneration of the C++ source file for %s.\n\n",sPROJECT_NAME);}
}
StandardFunctionsAnalysis
| GenomeDeclarationSection {
if (bVERBOSE) printf(" _______________________________________\n");
if (bVERBOSE) printf ("\nGeneration of the C++ source file for %s.\n\n",sPROJECT_NAME);
}
StandardFunctionsAnalysis
;
ClassDeclarationsSection
: CLASSES {
if (bVERBOSE) printf("Declaration of user classes :\n\n");}
ClassDeclarations
| CLASSES {
if (bVERBOSE) printf("No user class declaration found other than GenomeClass.\n");}
;
ClassDeclarations
: ClassDeclaration
| ClassDeclarations ClassDeclaration
;
ClassDeclaration
: Symbol {
pCURRENT_CLASS=SymbolTable.insert($1);
pCURRENT_CLASS->pSymbolList=new CLList<CSymbol *>();
$1->ObjectType=oUserClass;
//DEBUG_PRT("Yacc Symbol declaration %s %d",$1->sName,$1->nSize);
pCLASSES[nClasses_nb++] = $1;
}
'{' VariablesDeclarations '}' {
if (bVERBOSE) printf("Class %s declared for %d bytes.\n\n",$1->sName,$1->nSize);
//DEBUG_PRT("Yacc variable declaration %s %d",$1->sName,$1->nSize);
}
;
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 {}
| 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);
}
;
Qualifier
: STATIC {$$=1;} // 1=Static
| {$$=0;} // 0=Normal
;
BaseObjects
: Objects ';'
| Objects ':' BaseConstructorParameters ';' {}
;
UserObjects
: Objects ';' {}
| Objects ':' UserConstructorParameters ';' {}
;