Commit 60282ec3 authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Initial commit

parents
build
build2
.kdev4/
.tmp_project
*.kdev4
image: gitlab-registry.in2p3.fr/cta-lapp/phoenix_libs/phoenix/phoenix_minimal:0.2
stages:
- BuildTestinstall
- DocCoverage
- deploy
#- build
#- test
#- deploy
dailyBuildMasterAll:
#cache:
#untracked: true
#paths:
#- build/
stage: BuildTestinstall
script:
- export LD_LIBRARY_PATH=/usr/lib
- env
- mkdir -p build
- cd build
- >
cmake ..
-DCMAKE_INSTALL_PREFIX=/usr
-DSELF_TESTS_MODE=yes
- make all
- make install
- make test
only:
- branches
- tags
tags:
TestCoverage:
stage: DocCoverage
script:
- export LD_LIBRARY_PATH=/usr/lib
- env
- mkdir -p build coverage
- cd build
- >
cmake ..
-DCMAKE_INSTALL_PREFIX=/usr
-DSELF_TESTS_MODE=yes
-DCMAKE_BUILD_TYPE=Coverage
- make all
- make install
- make test
- make ExperimentalCoverage
- cd ../coverage
- gcovr -r ../ --html cov_report.html --html-details
- gcovr -r ../ --xml Coverage.xml
artifacts:
paths:
- coverage
expire_in: 1d
only:
- branches
- tags
tags:
Doc:
stage: DocCoverage
script:
- export LD_LIBRARY_PATH=/usr/lib
- env
- rm -fr build public
- mkdir -p build
- mkdir -p public
- mkdir -p public/html
- cd build
- >
cmake ..
-DCMAKE_INSTALL_PREFIX=/usr
-DDOC_MODE=yes
- make all
- make doc
- scp -r doc/platex/* ../public
- scp -r doc/html/* ../public/html
artifacts:
paths:
- public
expire_in: 1d
only:
- branches
- tags
tags:
pages:
stage: deploy
script:
- mv coverage public/
artifacts:
paths:
- public
expire_in: 1d
project(Phoenix)
cmake_minimum_required(VERSION 3.0)
add_subdirectory(cmake)
phoenix_base_project("ParserGenerator" "1.4.1"
"Tool to generate file parser for programming languages"
"https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS/ParserGenerator")
pull_extra_module("OptionParser" "https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS/OptionParser.git")
pull_extra_module("PhoenixGenerator" "https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS/PhoenixGenerator.git")
pull_extra_module("PhoenixCompareFile" "https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS/PhoenixCompareFile.git")
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src/Stmt)
phoenix_create_find(ParserGenerator convolutionnator_lib convolutionFormat.h "" "OptionParser" "FileParser" "StringUtils")
set(EXTRA_DEPENDENCIES option_parser file_parser tensor_alloc data_stream)
set(EXTRA_GRAPH_DEPENDENCIES convolutionnator_lib ${EXTRA_DEPENDENCIES})
add_definitions(-DCMAKE_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}")
add_subdirectory(src)
add_subdirectory(share)
if(SELF_TESTS_MODE)
include(CTest)
add_subdirectory(TESTS)
endif(SELF_TESTS_MODE)
if(DOC_MODE)
pull_extra_module("PhoenixTex2Html" "https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS/PhoenixTex2Html.git")
add_subdirectory(doc)
endif(DOC_MODE)
set(PHOENIX_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src;${PHOENIX_INCLUDE_DIRS}" CACHE INTERNAL "list of Phoenix include dirs")
![Phoenix logo](doc/logo.png)
----
Code
----
https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS/ParserGenerator
Documentation
----
https://cta-lapp.pages.in2p3.fr//PHOENIX_LIBS/ParserGenerator/
Requirements
------------
- c++ compiler >=5.3.1
- cmake > 3
- make
Installation for Users
----------------------
$ git clone https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS/ParserGenerator.git
$ cd ParserGenerator
$ ./install.sh
project(Phoenix)
cmake_minimum_required(VERSION 3.0)
include(callTestParserDecGenerator.cmake)
set(DEPENDENCIES_GRAPH_PARSER phoenix_parser_graph_parser phoenix_parser_representation file_parser option_parser string_utils)
set(DEPENDENCIES_GRAPH_CPP_BACKEND phoenix_parser_cpp_backend phoenix_parser_representation string_utils)
add_subdirectory(TEST_PARSE_CHARSET)
add_subdirectory(TEST_SHADOK_LIST)
add_subdirectory(TEST_C_ENUM)
add_subdirectory(TEST_VAR_DECL)
add_subdirectory(TEST_VAR_DECL_STRING)
add_subdirectory(TEST_MATH_EXPR)
add_subdirectory(TEST_OPERATOR)
project(Phoenix)
cmake_minimum_required(VERSION 3.0)
# compileTestGenerator(test_shadok_list "PTestParser" shadok.pparser)
# compileMainTestGenerator(test_shadok_list "PTestParser" shadok.pparser main_test.cpp)
# Only when the test will be OK
compileTestGenerator(test_c_enum_list "PEnumParser" c_enum.pdecparser main_test.cpp enum_def.c)
///The Curry coloration seems to be good, but it will be better to have the proper coloration for this language
///Value of the enum
Class EnumValue{
///name of the value
String name[csVariableName];
///Value of the enum value
UInt value[csUnsignedNumber];
}
Graph gEnumValue(EnumValue e){
e.name OPTIONAL{"=" e.value}
}
///Test enum definition
Class CEnum{
///Name of the enum
String name[csVariableName];
///Vector of EnumValue
Vector(EnumValue) vecValue;
}
///Parses an enum
Graph gEnum(CEnum s){
"enum" s.name "{" s.vecValue.pushBack(gEnumValue()) REPEAT{"," s.vecValue.pushBack(gEnumValue())} "}" ";"
}
///Main class
Class Source{
///Vector of CEnum
Vector(CEnum) vecEnum;
}
///Parses a complete source of CEnum
Graph gSource(Source s){
REPEAT{s.vecEnum.pushBack(gEnum())}
}
enum ShadokType{
HAUT,
BAS
};
enum AccessType{
PUBLIC,
PRIVATE,
PROTECTED
};
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
// For the option parsing
#include "OptionParser.h"
#include "string_utils.h"
// To get the generated parser
#include "PEnumParserFull.h"
using namespace std;
///Create the OptionParser of this program
/** @return OptionParser of this program
*/
OptionParser createOptionParser(){
OptionParser parser(true, __PROGRAM_VERSION__);
parser.setExampleLongOption("use_parser --input=fileName.shadok");
parser.setExampleShortOption("use_parser -i fileName.shadok");
parser.addOption("input", "i", OptionType::FILENAME, true, "input shadok file name");
return parser;
}
///Print the shadok file
/** @param fileName : file to be parsed
* @return 0 on success, -1 otherwise
*/
int printShadokFile(const std::string & fileName){
//We create the parser
PEnumParser parser;
if(!parser.load(fileName)){
cerr << "printShadokFile : can't load file '"<<fileName<<"'" << endl;
return -1;
}
std::list<std::string> listEnumName;
listEnumName.push_back("ShadokType");
listEnumName.push_back("AccessType");
std::list<std::string> listShadokAge;
listShadokAge.push_back("HAUT");
listShadokAge.push_back("BAS");
listShadokAge.push_back("PUBLIC");
listShadokAge.push_back("PRIVATE");
listShadokAge.push_back("PROTECTED");
//We get the parsed internal representation
CEnum & source = parser.getSourceS();
std::vector<CEnum> & vecEnum = Source_getVecEnum(source).getVecStmt();
if(vecEnum.size() == listEnumName.size()){
std::list<std::string>::iterator itName = listEnumName.begin();
std::list<std::string>::iterator itAge = listShadokAge.begin();
bool isSuccess(true);
for(std::vector<CEnum>::iterator it(vecEnum.begin()); it != vecEnum.end(); ++it){
cout << "CEnum(name = ";
if(CEnum_getName(*it) == *itName){
cout << termGreen();
}else{
cout << termRed();
isSuccess = false;
cout << "expect " << (*itName) << " but gives ";
}
cout << CEnum_getName(*it) << termDefault() << ", ";
std::vector<EnumValue> & vecValue = CEnum_getVecValue(*it).getVecStmt();
for(std::vector<EnumValue>::iterator itValue(vecValue.begin()); itValue != vecValue.end(); ++itValue){
std::string value(EnumValue_getName(*itValue));
if(value == *itAge){
cout << termGreen();
}else{
cout << termRed();
isSuccess = false;
cout << "expect " << (*itAge) << " but gives ";
}
cout << value << termDefault() << ", ";
++itAge;
}
cout << ")" << endl;
++itName;
}
if(isSuccess){return 0;}
else{return -1;}
}else{
cerr << "printShadokFile : "<<termRed()<<" error wrong number of 'enum' 2 expected but " << vecEnum.size() << " provided." << termDefault() << endl;
return -1;
}
return 0;
}
int main(int argc, char** argv){
OptionParser optionParser = createOptionParser();
optionParser.parseArgument(argc, argv);
const OptionMode & defaultMode = optionParser.getDefaultMode();
std::string fileName("");
defaultMode.getValue(fileName, "input");
return printShadokFile(fileName);
}
project(Phoenix)
cmake_minimum_required(VERSION 3.0)
# compileLibTestGenerator(test_math_expr_parser "PTestMathExprParser" math_expr.pdecparser)
compileMainTestGenerator(test_math_expr_parser "PTestMathExprParser" math_expr.pdecparser main_test.cpp)
# Only when the test will be OK
# compileTestGenerator(test_math_expr_parser "PTestMathExprParser" math_expr.pdecparser main_test.cpp var_decl.txt)
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
// For the option parsing
#include "OptionParser.h"
#include "string_utils.h"
// To get the generated parser
#include "PTestMathExprParserFull.h"
using namespace std;
///Create the OptionParser of this program
/** @return OptionParser of this program
*/
OptionParser createOptionParser(){
OptionParser parser(true, __PROGRAM_VERSION__);
parser.setExampleLongOption("use_parser --input=fileName.shadok");
parser.setExampleShortOption("use_parser -i fileName.shadok");
parser.addOption("input", "i", OptionType::FILENAME, true, "input shadok file name");
return parser;
}
///Test the conversion of and add expression into a string
/** @return true on success, false otherwise
*/
bool testExprAddToString(){
PExpr varA = PExpr_default();
PExpr_setType(varA, PExprType::VAR);
PExpr_setVarName(varA, "a");
PExpr varB = PExpr_default();
PExpr_setType(varB, PExprType::VAR);
PExpr_setVarName(varB, "b");
PExpr exprAdd = PExpr_default();
PExpr_setType(exprAdd, PExprType::ADD);
PExpr_getVecOperand(exprAdd).push_back(varA);
PExpr_getVecOperand(exprAdd).push_back(varB);
std::string exprStr = gExpr(exprAdd);
std::cout << "testExprAddToString : exprAdd = '"<<exprStr<<"'" << std::endl;
return true;
}
///Test the conversion of and add expression into a string
/** @return true on success, false otherwise
*/
bool testExprAdd2ToString(){
PExpr varA = PExpr_default();
PExpr_setType(varA, PExprType::VAR);
PExpr_setVarName(varA, "a");
PExpr varB = PExpr_default();
PExpr_setType(varB, PExprType::VAR);
PExpr_setVarName(varB, "b");
PExpr varC = PExpr_default();
PExpr_setType(varC, PExprType::VAR);
PExpr_setVarName(varC, "c");
PExpr exprAdd = PExpr_default();
PExpr_setType(exprAdd, PExprType::ADD);
PExpr_getVecOperand(exprAdd).push_back(varA);
PExpr_getVecOperand(exprAdd).push_back(varB);
PExpr_getVecOperand(exprAdd).push_back(varC);
std::string exprStr = gExpr(exprAdd);
std::cout << "testExprAdd2ToString : exprAdd = '"<<exprStr<<"'" << std::endl;
return true;
}
///Print the shadok file
/** @param fileName : file to be parsed
* @return true on success, false otherwise
*/
bool printVarDeclFile(const std::string & fileName){
//We create the parser
PTestMathExprParser parser;
if(!parser.load(fileName)){
cerr << "printVarDeclFile : can't load file '"<<fileName<<"'" << endl;
return false;
}
//We get the parsed internal representation
PExpr & source = parser.getPExprE();
std::string exprStr = gExpr(source);
std::cout << "printVarDeclFile : exprStr = '"<<exprStr<<"'" << std::endl;
return true;
}
int main(int argc, char** argv){
OptionParser optionParser = createOptionParser();
optionParser.parseArgument(argc, argv);
const OptionMode & defaultMode = optionParser.getDefaultMode();
std::string fileName("");
defaultMode.getValue(fileName, "input");
bool b(testExprAddToString());
b &= testExprAdd2ToString();
b &= printVarDeclFile(fileName);
if(b){return 0;}
else{return -1;}
}
///Type of the expression
Enum PExprType{
VAR
ADD
MULT
};
///Describes a simple mathematic expression
Class PExpr{
///Type of the expression
PExprType::PExprType type;
///Name of the variable
String varName[csVariableName];
///Vector of operand
Vector(PExpr) vecOperand;
}
Graph gExprVarName(PExpr e){
e.varName e.type=PExprType::VAR
}
///Parses a mathematic expression
Graph gExpr(PExpr e){
e.vecOperand.pushBack(gExprVarName())
REPEAT{
OR{
"*" e.vecOperand.pushBackFirst(e) e.type=PExprType::MULT e.varName="toto"
OR{
"(" e.vecOperand.pushBack(gExpr()) ")",
e.vecOperand.pushBack(gExpr())
},
"+" e.vecOperand.pushBackFirst(e) e.type=PExprType::ADD e.varName="toto"
OR{
"(" e.vecOperand.pushBack(gExpr()) ")",
e.vecOperand.pushBack(gExpr())
}
}
}
}
project(Phoenix)
cmake_minimum_required(VERSION 3.0)
# compileLibTestGenerator(test_math_operator_parser "PTestOperatorParser" parser_operator.pdecparser)
compileMainTestGenerator(test_math_operator_parser "PTestOperatorParser" parser_operator.pdecparser main_test.cpp)
# Only when the test will be OK
# compileTestGenerator(test_math_operator_parser "PTestOperatorParser" parser_operator.pdecparser main_test.cpp var_decl.txt)
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
// To get the generated parser
#include "PTestOperatorParserFull.h"
using namespace std;
///Test the conversion of and add expression into a string
/** @return true on success, false otherwise
*/
bool testExprAddToString(){
PExpr varA = PExpr_default();
PExpr_setType(varA, PExprType::VAR);
PExpr_setVarName(varA, "a");
PExpr varB = PExpr_default();
PExpr_setType(varB, PExprType::VAR);
PExpr_setVarName(varB, "b");
PExpr exprAdd = PExpr_default();
PExpr_setType(exprAdd, PExprType::ADD);
PExpr_getVecOperand(exprAdd).push_back(varA);
PExpr_getVecOperand(exprAdd).push_back(varB);
std::string exprStr = gExprVarName(exprAdd);
std::cout << "testExprAddToString : exprAdd = '"<<exprStr<<"'" << std::endl;
return exprStr == "(a+b)";
}
///Test the conversion of and add expression into a string
/** @return true on success, false otherwise
*/
bool testExprAdd2ToString(){
PExpr varA = PExpr_default();
PExpr_setType(varA, PExprType::VAR);
PExpr_setVarName(varA, "a");
PExpr varB = PExpr_default();
PExpr_setType(varB, PExprType::VAR);
PExpr_setVarName(varB, "b");
PExpr exprAddAB = PExpr_default();
PExpr_setType(exprAddAB, PExprType::ADD);
PExpr_getVecOperand(exprAddAB).push_back(varA);
PExpr_getVecOperand(exprAddAB).push_back(varB);