Commit d18caea5 authored by Joseph Pallamidessi's avatar Joseph Pallamidessi

Merge pull request #7 from Haerezis/master

Transition from AYACC/ALEX to Flex/Bison
parents 02eff1d6 2aa02460
......@@ -2,7 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
project(EASEA)
SET(CMAKE_STATIC_LIBRARY_PREFIX="")
INCLUDE_DIRECTORIES(libeasea/include alexyacc/include boost)
INCLUDE_DIRECTORIES(libeasea/include boost)
ADD_DEFINITIONS(-g -w -Wno-deprecated -Wno-write-strings -fmessage-length=0 )
......@@ -11,12 +11,6 @@ if(WIN32)
FILE(GLOB libeasea_src_win "libeasea/win32/*.cpp" )
endif(WIN32)
#Alexyacc static library
FILE(GLOB libalex_src alexyacc/*.cpp)
ADD_LIBRARY( libalex STATIC ${libalex_src} )
#Libeasea static library
FILE(GLOB libeasea_src libeasea/*.cpp )
ADD_LIBRARY( libeasea STATIC ${libeasea_src} ${libeasea_src_win})
......@@ -28,6 +22,12 @@ FILE(GLOB boost_src boost/*.cpp)
ADD_LIBRARY( program_options STATIC ${boost_src} )
SET_TARGET_PROPERTIES(program_options PROPERTIES OUTPUT_NAME "program_options" PREFIX "" COMPILE_FLAGS "-O2")
find_package(BISON)
find_package(FLEX)
FLEX_TARGET(Lexer compiler/EaseaLex.l compiler/EaseaLex.cpp)
BISON_TARGET(Parser compiler/EaseaParse.y compiler/EaseaParse.cpp COMPILE_FLAGS -d)
#Easea compiler
SET(easea_src
compiler/EaseaLex.cpp
......@@ -37,8 +37,9 @@ SET(easea_src
ADD_EXECUTABLE(easea ${easea_src})
ADD_DEPENDENCIES(easea Lexer Parser)
SET_TARGET_PROPERTIES(easea PROPERTIES COMPILE_FLAGS "")
TARGET_LINK_LIBRARIES(easea libeasea libalex program_options)
TARGET_LINK_LIBRARIES(easea libeasea program_options)
ADD_CUSTOM_COMMAND(TARGET easea POST_BUILD
COMMAND $(CMAKE_COMMAND) -E copy libeasea.a libeasea/
COMMAND $(CMAKE_COMMAND) -E copy program_options.a boost/
......
......@@ -2,11 +2,13 @@ UNAME := $(shell uname)
ifeq ($(shell uname -o 2>/dev/null),Msys)
OS := MINGW
endif
YACC=bison
LEX=flex
EXEC = bin/easea
CPPFLAGS += -DUNIX_OS -Ialexyacc/include/ -g -Wno-deprecated -DDEBUG -DLINE_NUM_EZ_FILE
CPPFLAGS += -DUNIX_OS -g -Wno-deprecated -DDEBUG -DLINE_NUM_EZ_FILE
LDFLAGS =
OBJ= build/EaseaSym.o build/EaseaParse.o build/EaseaLex.o alexyacc/libalex.a build/EaseaYTools.o boost/program_options.a libeasea/libeasea.a
OBJ= build/EaseaSym.o build/EaseaParse.o build/EaseaLex.o build/EaseaYTools.o boost/program_options.a libeasea/libeasea.a
#ifeq ($(UNAME),Darwin)
$(EXEC):build bin $(OBJ)
......@@ -82,19 +84,18 @@ bin:
build/EaseaParse.o: compiler/EaseaParse.cpp compiler/EaseaLex.cpp
$(CXX) $(CPPFLAGS) $< -o $@ -c -w
build/EaseaLex.o: compiler/EaseaLex.cpp
build/EaseaLex.o: compiler/EaseaLex.cpp compiler/EaseaParse.hpp
$(CXX) $(CPPFLAGS) $< -o $@ -c -w
build/%.o:compiler/%.cpp
$(CXX) $(CPPFLAGS) -c -o $@ $<
#compile library for alex and ayacc unix version
alexyacc/libalex.so:alexyacc/*.cpp
cd alexyacc && make libalex.so
compiler/EaseaParse.cpp:compiler/EaseaParse.y
$(YACC) -d -o $@ $<
alexyacc/libalex.a:alexyacc/*.cpp
cd alexyacc && make libalex.a
compiler/EaseaLex.cpp:compiler/EaseaLex.l
$(LEX) -o $@ $<
#ifeq ($(UNAME),Darwin)
boost/program_options.a:boost/*.cpp
......@@ -107,7 +108,6 @@ libeasea/libeasea.a:libeasea/*.cpp
clean:
rm -f build/*.o $(EXEC) $(EXEC)_bin
cd alexyacc && make clean
cd libeasea && make clean
cd boost && make clean
#ifeq ($(UNAME),Darwin)
......
#ifndef CLEX_H
#define CLEX_H
/************************************************************
clex.h
This file can be freely modified for the generation of
custom code.
Copyright (c) 1999-2001 Bumble-Bee Software Ltd.
************************************************************/
#include <stdio.h>
#include <assert.h>
// defines
#include "yytdefs.h"
// user defines
#if defined(YYTUDEFS) || defined(YYUDEFS)
#include <yytudefs.h>
#endif
#define YY_ALEX
// modifiers
#ifndef YYCDECL
#define YYCDECL
#endif
#ifndef YYDCDECL
#define YYDCDECL
#endif
#ifndef YYNEAR
#define YYNEAR
#endif
#ifndef YYFAR
#define YYFAR
#endif
#ifndef YYNEARFAR
#define YYNEARFAR
#endif
#ifndef YYBASED_CODE
#define YYBASED_CODE
#endif
// forward references
class YYFAR yyparser;
// yylex return values
#define YYEOF 0 // end of file
#ifndef YYSTATE_T
#define YYSTATE_T
typedef struct yystate {
short def; // default state
short base; // base
short match; // action associated with state
} yystate_t;
#endif
#ifndef YYTRANSITION_T
#define YYTRANSITION_T
typedef struct yytransition {
short next; // next state on transition
short check; // check
} yytransition_t;
#endif
#ifndef YYCTRANSITION_T
#define YYCTRANSITION_T
typedef struct yyctransition {
unsigned char first; // first character in range
unsigned char last; // last character in range
short next; // next state on transition
} yyctransition_t;
#endif
typedef short yymatch_t;
typedef unsigned char yybackup_t;
class YYFAR yylexer {
public:
yylexer();
virtual ~yylexer();
// Attributes
protected:
// left context
int yystart; // current start state
unsigned char yyeol; // whether an end-of-line '\n' has been seen
unsigned char yyoldeol; // previous end-of-line value
// text buffer
int YYFAR* yystatebuf; // state buffer
int YYFAR* yysstatebuf; // initial (static) state buffer
char YYFAR* yystext; // initial (static) text buffer
int yytext_size; // text buffer size
int yystext_size; // initial (static) text buffer size
// unput buffer
int YYFAR* yyunputbufptr; // unput buffer
int YYFAR* yysunputbufptr; // initial (static) unput buffer
int yyunput_size; // unput buffer size
int yysunput_size; // initial (static) unput buffer size
int yyunputindex; // unput buffer position
// actions
unsigned char yymoreflg; // concatenate matched strings
unsigned char yyrejectflg; // yyreject called from an action
unsigned char yyreturnflg; // return from an action
public:
yyparser YYFAR* yyparserptr; // pointer to the attached parser
// buffer flags
unsigned char yytextgrow; // whether text buffer is allowed to grow
unsigned char yyunputgrow; // whether unput buffer is allowed to grow
// streams
FILE YYFAR* yyin; // input text stream
FILE YYFAR* yyout; // output text stream
FILE YYFAR* yyerr; // error stream
// matched string
char YYFAR* yytext; // text buffer
int yyleng; // matched string length
int yylineno; // current line number
// Operations
protected:
// helper functions
int yyback(const yymatch_t YYNEARFAR* p, int action) const;
public:
// instance functions
int yycreate(yyparser YYFAR* parserptr = NULL);
void yydestroy();
// general functions
void yycleanup();
virtual int yylex() = 0;
void yyreset();
int yysettextsize(int size);
int yysetunputsize(int size);
// service functions
virtual int yyinput();
virtual void yyoutput(int ch);
virtual void yyunput(int ch);
virtual int yywrap();
virtual int yygetchar();
virtual void yytextoverflow();
virtual void yyunputoverflow();
virtual int yyaction(int action) = 0;
// action functions
void yyecho();
void yyless(int length);
void yybegin(int state) { yystart = state; }
void yymore() { yymoreflg = 1; }
void yynewline(int newline) { newline ? yyeol = 1 : (yyeol = 0); }
void yyreject() { yyrejectflg = 1; }
int yyunputcount() const { return yyunputindex; }
// compatibility
int yyclex() { return yylex(); }
void yylexcleanup() { yycleanup(); }
void yylexinit() { /* do nothing */ }
#define BEGIN yystart =
#define ECHO yyecho()
#define REJECT yyreject()
#define YYSTATE yystart
#define YY_START yystart
// Tables
protected:
const yymatch_t YYNEARFAR* yymatch;
const yystate_t YYNEARFAR* yystate;
const yybackup_t YYNEARFAR* yybackup;
// Debugging
#ifdef YYDEBUG
public:
int yydebug; // whether debug information should be output
int yydebugflush; // whether debug output should be flushed
FILE YYFAR* yydebugout; // debug output file
protected:
void yydebugoutput(int ch) const;
void yydmatch(int expr) const;
void yydebugoutput(const char* string) const;
#endif
};
class YYFAR yyflexer : public yylexer {
public:
yyflexer() { /* do nothing */ }
// Operations
public:
virtual int yylex();
// Tables
protected:
const yytransition_t YYNEARFAR* yytransition;
int yytransitionmax;
};
class YYFAR yyclexer : public yylexer {
public:
yyclexer() { /* do nothing */ }
// Operations
public:
virtual int yylex();
// Tables
protected:
const yyctransition_t YYNEARFAR* yyctransition;
};
// helper functions
#ifndef yyassert
#define yyassert(expr) assert(expr)
#endif
// debugging variables
#ifdef YYDEBUG
extern "C" int YYNEAR YYDCDECL yydebug;
extern "C" int YYNEAR YYDCDECL yydebugflush;
#endif
// user defines
#if defined(YYBUDEFS) || defined(YYUDEFS)
#include <yybudefs.h>
#endif
// defines
#include "yybdefs.h"
#endif
#ifndef CYACC_H
#define CYACC_H
/************************************************************
cyacc.h
This file can be freely modified for the generation of
custom code.
Copyright (c) 1999-2001 Bumble-Bee Software Ltd.
************************************************************/
#include <stdio.h>
#include <stddef.h>
#include <assert.h>
// defines
#include "yytdefs.h"
// user defines
#if defined(YYTUDEFS) || defined(YYUDEFS)
#include <yytudefs.h>
#endif
#define YY_AYACC
// modifiers
#ifndef YYCDECL
#define YYCDECL
#endif
#ifndef YYDCDECL
#define YYDCDECL
#endif
#ifndef YYNEAR
#define YYNEAR
#endif
#ifndef YYFAR
#define YYFAR
#endif
#ifndef YYNEARFAR
#define YYNEARFAR
#endif
#ifndef YYBASED_CODE
#define YYBASED_CODE
#endif
// forward references
class YYFAR yylexer;
typedef short yystack_t;
// yyparse return values
#define YYEXIT_SUCCESS 0
#define YYEXIT_FAILURE 1
// common tokens
#define YYTK_ALL (-1) // match all tokens
#define YYTK_END 0 // $end token
#define YYTK_ERROR 256 // error token
#ifndef YYCSTATEGOTO_T
#define YYCSTATEGOTO_T
typedef short yycstategoto_t;
#endif
#ifndef YYCNONTERMGOTO_T
#define YYCNONTERMGOTO_T
typedef struct yycnontermgoto {
short nonterm; // nonterminal
short next; // next state
} yycnontermgoto_t;
#endif
#ifndef YYSTATEGOTO_T
#define YYSTATEGOTO_T
typedef struct yystategoto {
short base; // base
short def; // default state
} yystategoto_t;
#endif
#ifndef YYNONTERMGOTO_T
#define YYNONTERMGOTO_T
typedef struct yynontermgoto {
short check; // check
short next; // next state
} yynontermgoto_t;
#endif
// action types
#define YYAT_SHIFT 0 // shift action
#define YYAT_REDUCE 1 // reduce action
#define YYAT_ERROR 2 // error
#define YYAT_ACCEPT 3 // accept
#define YYAT_DEFAULT 4 // default state
#ifndef YYCSTATEACTION_T
#define YYCSTATEACTION_T
typedef short yycstateaction_t;
#endif
#ifndef YYCTOKENACTION_T
#define YYCTOKENACTION_T
typedef struct yyctokenaction {
int token; // lookahead token
unsigned char type; // action to perform
short sr; // state to shift/production to reduce
} yyctokenaction_t;
#endif
#ifndef YYSTATEACTION_T
#define YYSTATEACTION_T
typedef struct yystateaction {
short base; // base
unsigned char lookahead; // lookahead needed
unsigned char type; // action to perform
short sr; // shift/reduce
} yystateaction_t;
#endif
#ifndef YYTOKENACTION_T
#define YYTOKENACTION_T
typedef struct yytokenaction {
short check; // check
unsigned char type; // action type
short sr; // shift/reduce
} yytokenaction_t;
#endif
// nonterminals
#define YYNT_ALL (-1) // match all nonterminals
// states
#define YYST_ERROR (-1) // goto error
#ifndef YYREDUCTION_T
#define YYREDUCTION_T
typedef struct yyreduction {
short nonterm; // the rhs symbol
short length; // number of symbols on lhs
short action; // the user action
} yyreduction_t;
#endif
typedef short yydestructor_t;
typedef short yytokendest_t;
#ifndef YYCTOKENDEST_T
#define YYCTOKENDEST_T
typedef struct yyctokendest {
int token; /* token */
short action; /* the user action */
} yyctokendest_t;
#endif
// debugging
#ifdef YYDEBUG
#ifndef YYSYMBOL_T
#define YYSYMBOL_T
typedef struct yysymbol {
const char* name; // symbol name
int token; // symbol token
} yysymbol_t;
#endif
#endif
class YYFAR yyparser {
public:
yyparser();
virtual ~yyparser();
// Attributes
protected:
// stack
yystack_t YYFAR* yystackptr; // (state) stack
yystack_t YYFAR* yysstackptr; // static (state) stack
void YYFAR* yyattributestackptr; // attribute stack
void YYFAR* yysattributestackptr; // static attribute stack
int yystack_size; // number of elements in stack
int yysstack_size; // initial number of elements in stack
int yytop; // the current top of the stack
size_t yyattribute_size; // size of attribute
void YYFAR* yyvalptr; // attribute for $$
// lookahead token
unsigned char yylookahead; // whether current lookahead token is valid
int yychar; // current lookahead token
// error recovery
unsigned char yywipeflg; // whether to "wipe" stack on abort
unsigned char yypopflg; // popping symbols during error recovery
int yyskip; // error recovery token shift counter
// actions
unsigned char yyexitflg; // whether yymexit called
unsigned char yyretireflg; // whether yymretire called
unsigned char yyerrorflg; // whether yymforceerror called
int yyexitcode; // yymexit exit code
int yyretirecode; // yymretire exit code
int yyerrorpop; // how many error transitions to pop
public:
yylexer YYFAR* yylexerptr; // pointer to the attached lexical analyser
unsigned char yystackgrow; // whether stack can grow
void YYFAR* yylvalptr; // current token attribute
FILE YYFAR* yyerr; // error output file
int yyerrorcount; // how many syntax errors have occurred
// Operations
protected:
virtual void yyaction(int action) = 0;
// utility functions
#ifdef YYDEBUG
void yypop(int num);
void yysetskip(int skip);
#else
void yypop(int num) { yytop -= num; }
void yysetskip(int skip) { yyskip = skip; }
#endif
int yypush(yystack_t state);
yystack_t yypeek() const { return yystackptr[yytop]; }
public:
// instance functions
int yycreate(yylexer YYFAR* lexerptr = NULL);
void yydestroy();
// general functions
void yydestructpop(int num);
int yyparse();
void yycleanup();
int yysetstacksize(int size);
int yysetup();
void yywipe();
virtual int yywork() = 0;
virtual void yydestructclearin() = 0;
// service functions
virtual void yystackoverflow();
virtual void yyerror(const char YYFAR* text);
virtual void yysyntaxerror();
virtual void yydiscard(int token);
virtual int yygettoken();
// action functions
void yysetin(int token);
int yyunclearin();
void yyabort() { yyexit(1); }
void yyaccept() { yyexit(0); }
#ifndef YY_COMPATIBLE
void yyclearin() { yylookahead = 0; }
void yyerrok() { yysetskip(0); }
#else
void _yyclearin() { yylookahead = 0; }
void _yyerrok() { yysetskip(0); }
#endif
void yyexit(int exitcode) { yyexitflg = 1; yyexitcode = exitcode; }
void yyforceerror() { yythrowerror(); }
int yypopping() const { return yypopflg; }
int yyrecovering() const { return yyskip > 0; }
void yyretire(int retirecode) { yyretireflg = 1; yyretirecode = retirecode; }
void yythrowerror(int pop = 0) { yyerrorflg = 1; yyerrorpop = pop; }
// compatibility
int yycparse() { return yyparse(); }
int yycwork() { return yywork(); }
void yyparsecleanup() { yycleanup(); }
void yyparseinit() { /* do nothing */ }
#ifdef YY_COMPATIBLE
#define yyclearin _yyclearin()
#define yyerrok _yyerrok()
#endif
#define YYABORT yyexit(1)
#define YYACCEPT yyexit(0)
#define YYERROR yyforceerror()
#define YYRECOVERING yyrecovering()
// Tables
protected:
const yyreduction_t YYNEARFAR* yyreduction;
const yydestructor_t YYNEARFAR* yydestructorptr;
// Debugging
#ifdef YYDEBUG
public:
int yydebug; // whether debug information should be output
int yydebugstack; // whether stack debug information should be output
int yydebugflush; // whether debug output should be flushed
FILE YYFAR* yydebugout; // debug output file
protected:
const yysymbol_t YYNEARFAR* yysymbol;
const char* const YYNEARFAR* yyrule;
// debugging functions
protected:
const char* yytokenstring(int token) const;
void yydgettoken(int token) const;
void yydshift(int token) const;
void yydreduce(int rule) const;
void yydsyntaxerror() const;
void yydaccept() const;
void yydabort() const;
void yyddiscard(int token) const;
void yydexit(int exitcode) const;
void yydthrowerror(int errorpop) const;
void yydretire(int retirecode) const;
void yydattemptrecovery() const;
void yydebugoutput(const char* string) const;
#endif
};
class YYFAR yyfparser : public yyparser {
public:
yyfparser() { /* do nothing */ }
// Operations
public:
virtual int yywork();
virtual void yydestructclearin();
// Tables
protected:
const yystateaction_t YYNEARFAR* yystateaction;
const yytokenaction_t YYNEARFAR* yytokenaction;
int yytokenaction_size;
const yystategoto_t YYNEARFAR* yystategoto;
const yynontermgoto_t YYNEARFAR* yynontermgoto;
int yynontermgoto_size;
const yytokendest_t YYNEARFAR* yytokendestptr;
int yytokendest_size;
int yytokendestbase;
};
class YYFAR yycparser : public yyparser {
public:
yycparser() { /* do nothing */ }
// Operations
public:
virtual int yywork();
virtual void yydestructclearin();
// Tables
protected:
const yycstateaction_t YYNEARFAR* yycstateaction;
const yyctokenaction_t YYNEARFAR* yyctokenaction;
const yycstategoto_t YYNEARFAR* yycstategoto;
const yycnontermgoto_t YYNEARFAR* yycnontermgoto;
const yyctokendest_t YYNEARFAR* yyctokendestptr;
};
// utility functions
#ifndef yyassert
#define yyassert(expr) assert(expr)
#endif
// debugging variables
#ifdef YYDEBUG
extern "C" int YYNEAR YYDCDECL yydebug;
extern "C" int YYNEAR YYDCDECL yydebugstack;
extern "C" int YYNEAR YYDCDECL yydebugflush;
#endif
// user defines
#if defined(YYBUDEFS) || defined(YYUDEFS)
#include <yybudefs.h>
#endif
// defines
#include "yybdefs.h"
#endif
#ifndef LEX_H
#define LEX_H
/************************************************************
lex.h
This file can be freely modified for the generation of
custom code.
Copyright (c) 1999-2001 Bumble-Bee Software Ltd.
************************************************************/
#include <stdio.h>
#include <assert.h>
/* defines */
#include <yytdefs.h>
/* user defines */
#if defined(YYTUDEFS) || defined(YYUDEFS)
#include <yytudefs.h>