Commit e3ca4c3fba8f744d338fe0e082c40efd1a152386

Authored by Benjamin Renard
1 parent d1fc8c33

adding structure of the parser

CMakeLists.txt
... ... @@ -117,6 +117,7 @@ add_subdirectory(src/XMLRequest)
117 117 add_subdirectory(src/SpiceKernel)
118 118 add_subdirectory(src/amdaXMLRequestorTool)
119 119 add_subdirectory(src/amdaParameterGenerator)
  120 +add_subdirectory(src/expressionParser)
120 121 add_subdirectory(src/amdaParameterInfo)
121 122 add_subdirectory(src/PostProcessing)
122 123 add_subdirectory(src/ParamOutputImpl/Download)
... ...
src/expressionParser/CMakeLists.txt 0 → 100644
... ... @@ -0,0 +1,44 @@
  1 +
  2 +PROJECT(expressionParser)
  3 +
  4 +include_directories(
  5 + ${CMAKE_HOME_DIRECTORY}/src/helpers/
  6 + ${CMAKE_HOME_DIRECTORY}/src/Common/
  7 + ${CMAKE_HOME_DIRECTORY}/src/Parameters/
  8 + ${CMAKE_HOME_DIRECTORY}/src/PostProcessing/
  9 + ${CMAKE_HOME_DIRECTORY}/src/XMLConfigurator/
  10 + ${CMAKE_HOME_DIRECTORY}/src/XMLParameterConfigurator/
  11 + ${CMAKE_HOME_DIRECTORY}/src/Plugins/
  12 + ${CMAKE_HOME_DIRECTORY}/src/TimeTableCatalog/
  13 + ${CMAKE_HOME_DIRECTORY}/src/SpiceKernel/
  14 + ${LOG4CXX_INCLUDE_DIR}
  15 + ${Boost_INCLUDE_DIR}
  16 +)
  17 +
  18 +#Configuration de la librairie
  19 +file(
  20 + GLOB_RECURSE
  21 + source_files
  22 + ./*
  23 +)
  24 +
  25 +ADD_EXECUTABLE( expressionParser ${source_files} )
  26 +
  27 +
  28 +target_link_libraries(
  29 + expressionParser
  30 + AMDA_COMMON
  31 + ${CMAKE_THREAD_LIBS_INIT}
  32 + Parameters
  33 + ${LOG4CXX_LIBRARIES}
  34 + Plugin
  35 + XMLParameterConfigurator
  36 + ${Boost_LIBRARY_DIR}/libboost_system.so
  37 + ${Boost_LIBRARY_DIR}/libboost_thread.so
  38 + ${Boost_LIBRARY_DIR}/libboost_program_options.so
  39 + ParamOutputImpl
  40 + TimeTableCatalog
  41 + Info
  42 + SpiceKernel
  43 + ${DDCLIENTLIBRARY}
  44 +)
... ...
src/expressionParser/ExpressionParser.cc 0 → 100644
... ... @@ -0,0 +1,51 @@
  1 +/*
  2 + * ExpressionParser.cc
  3 + *
  4 + * Created on: 02/2019
  5 + * Author: akka
  6 + */
  7 +
  8 +#include <iostream>
  9 +#include <iomanip>
  10 +#include <stdexcept>
  11 +#include <cstdlib>
  12 +#include <sstream>
  13 +#include <math.h>
  14 +
  15 +#include <boost/spirit/include/qi.hpp>
  16 +#include <boost/spirit/include/phoenix.hpp>
  17 +#include "ExpressionParser.hh"
  18 +
  19 +namespace AMDA {
  20 +
  21 +ExpressionParser::ExpressionParser() {
  22 +}
  23 +
  24 +ExpressionParser::~ExpressionParser() {
  25 +}
  26 +std::string ExpressionParser::parsePower(const std::string& s){
  27 +using boost::spirit::qi::_1;
  28 +using boost::spirit::qi::int_;
  29 +using boost::spirit::qi::char_;
  30 +using boost::phoenix::ref;
  31 +int a=0, b=0;
  32 +
  33 +const char* first = s.data();
  34 +const char* const end = first + s.size();
  35 +const bool success = boost::spirit::qi::parse(first, end,
  36 +// Implementation of 'full-date' rule from EBNF grammar.
  37 + int_[ ref(a) = _1 ] >> char_('^')
  38 + >> int_[ ref(b) = _1 ]
  39 + );
  40 + if (!success || first != end) {
  41 + throw std::logic_error("Parsing failed");
  42 + }
  43 + std::stringstream ss;
  44 + ss<<"pow("<<a<<","<<b<<")";
  45 + return ss.str();
  46 +
  47 + }
  48 +}/* namespace AMDA */
  49 +
  50 +
  51 +
... ...
src/expressionParser/ExpressionParser.hh 0 → 100644
... ... @@ -0,0 +1,39 @@
  1 +/*
  2 + * ExpressionParser.hh
  3 + *
  4 + * Created on: 02/2019
  5 + * Author: akka
  6 + */
  7 +
  8 +#ifndef EXPRESSIONPARSER_HH_
  9 +#define EXPRESSIONPARSER_HH_
  10 +#include <iostream>
  11 +#include "ParamOutput.hh"
  12 +
  13 +namespace AMDA {
  14 +
  15 +
  16 +/**
  17 + * @class ExpressionParser
  18 + * @brief This class is to parse expression.
  19 + * @details This class takes as input user expression comming grom the frontend and tranform it to C++ expression that is handled by the
  20 + * Kernel
  21 + */
  22 +class ExpressionParser {
  23 +public:
  24 + /**
  25 + * Constructor.
  26 + */
  27 + ExpressionParser();
  28 + /**
  29 + * Destructor.
  30 + */
  31 + virtual ~ExpressionParser();
  32 + /**
  33 + * Exemple of parser
  34 + * */
  35 + static std::string parsePower(const std::string& s);
  36 +};
  37 +
  38 +} /* namespace AMDA */
  39 +#endif /* PARAMETERGENERATOR_HH_ */
... ...
src/expressionParser/Main.cc 0 → 100644
... ... @@ -0,0 +1,83 @@
  1 +/**
  2 + * Main.cc
  3 + * Created on: 15 oct. 2012
  4 + * Author: AKKA IS
  5 + */
  6 +#include <iostream>
  7 +
  8 +#include <boost/program_options.hpp>
  9 +
  10 +#include "AMDA-Kernel_Config.hh"
  11 +#include <Application.hh>
  12 +
  13 +// Other includes
  14 +#include "ExpressionParser.hh"
  15 +
  16 +
  17 +using namespace std;
  18 +namespace po = boost::program_options;
  19 +using namespace log4cxx;
  20 +using namespace log4cxx::helpers;
  21 +
  22 +LoggerPtr logger(Logger::getLogger("AMDA-Kernel"));
  23 +
  24 +/**
  25 + * Main function
  26 + */
  27 +int main(int argc, char *argv[]) {
  28 + int result = AMDA_EXIT_OK;
  29 +
  30 + /// Parse command line
  31 + po::options_description desc("Allowed options");
  32 +
  33 + desc.add_options()
  34 + ("help,h", "Produce help message")
  35 + ("version,v", "Program version")
  36 + ("expression,p", po::value< vector<string> >(), "expression(s) to parse")
  37 + ;
  38 +
  39 + po::positional_options_description p;
  40 + p.add("expression", -1);
  41 +
  42 + po::variables_map vm;
  43 + po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
  44 + po::notify(vm);
  45 +
  46 + if (vm.count("help")) {
  47 + cout << desc << "\n";
  48 + return result;
  49 + }
  50 + if (vm.count("version")) {
  51 + cout << "Version: " << AMDA_Kernel_VERSION << "\n";
  52 + return result;
  53 + }
  54 +
  55 + if (!vm.count("expression")) {
  56 + return result;
  57 + }
  58 +
  59 + AMDA::Common::Application lMain;
  60 +
  61 + return lMain.main(argc,argv,[&](int , char **, AMDA::helpers::Properties& lProperties) -> int {
  62 +
  63 + vector<string> lExpressionList = vm["expression"].as< vector<string> >();
  64 + std::map<std::string, std::string> expressionMap;
  65 + for(auto expression :lExpressionList){
  66 + LOG4CXX_INFO(logger,"Parasing expression: "<<expression);
  67 + try{
  68 + std::string parsedExp = AMDA::ExpressionParser::parsePower(expression);
  69 + expressionMap[expression] = parsedExp;
  70 + std::cout<<parsedExp<<std::endl;
  71 + LOG4CXX_INFO(logger,expression<<" Gives : "<<parsedExp);
  72 + }catch(...) {
  73 +
  74 + }
  75 + }
  76 +
  77 +
  78 +
  79 + return result;
  80 +});
  81 +
  82 +}
  83 +
... ...