Commit 47755d136249ad233eec7b358552b06d74ca40ce
1 parent
a7f2648e
Exists in
master
and in
89 other branches
Minor changes
Showing
6 changed files
with
30 additions
and
32 deletions
Show diff stats
src/expressionParser/ExpressionContainer.hh
... | ... | @@ -49,25 +49,25 @@ typedef boost::variant<var, |
49 | 49 | boost::recursive_wrapper<binop<op_powerTen> >, |
50 | 50 | boost::recursive_wrapper<unop<op_minusSign> >, |
51 | 51 | boost::recursive_wrapper<unop<op_plusSign> > |
52 | -> expressionContainer; | |
52 | +> ExpressionContainer; | |
53 | 53 | |
54 | 54 | |
55 | 55 | template <typename tag> struct binop |
56 | 56 | { |
57 | - explicit binop(const expressionContainer& l, const expressionContainer& r) : oper1(l), oper2(r) { } | |
58 | - expressionContainer oper1, oper2; | |
57 | + explicit binop(const ExpressionContainer& l, const ExpressionContainer& r) : oper1(l), oper2(r) { } | |
58 | + ExpressionContainer oper1, oper2; | |
59 | 59 | }; |
60 | 60 | |
61 | 61 | template <typename tag> struct comop |
62 | 62 | { |
63 | - explicit comop(const expressionContainer& l, const expressionContainer& r) : oper1(l), oper2(r) { } | |
64 | - expressionContainer oper1, oper2; | |
63 | + explicit comop(const ExpressionContainer& l, const ExpressionContainer& r) : oper1(l), oper2(r) { } | |
64 | + ExpressionContainer oper1, oper2; | |
65 | 65 | }; |
66 | 66 | |
67 | 67 | template <typename tag> struct unop |
68 | 68 | { |
69 | - explicit unop(const expressionContainer& o) : oper1(o) { } | |
70 | - expressionContainer oper1; | |
69 | + explicit unop(const ExpressionContainer& o) : oper1(o) { } | |
70 | + ExpressionContainer oper1; | |
71 | 71 | }; |
72 | 72 | |
73 | 73 | } /* namespace Expression */ | ... | ... |
src/expressionParser/ExpressionParser.cc
... | ... | @@ -5,12 +5,7 @@ |
5 | 5 | * Author: akka |
6 | 6 | */ |
7 | 7 | |
8 | -#include <iostream> | |
9 | -#include <iomanip> | |
10 | -#include <stdexcept> | |
11 | -#include <cstdlib> | |
12 | 8 | #include <sstream> |
13 | -#include <math.h> | |
14 | 9 | |
15 | 10 | #include "ParserLogger.hh" |
16 | 11 | #include "ExpressionParser.hh" |
... | ... | @@ -20,15 +15,15 @@ |
20 | 15 | namespace AMDA { |
21 | 16 | namespace parser { |
22 | 17 | |
23 | -std::string ExpressionParser::parse(const std::string& str) { | |
18 | +std::string ExpressionParser::parse(const std::string& str, AMDA::helpers::Properties& /*lProperties*/) { | |
24 | 19 | LOG4CXX_INFO(gLogger, "ExpressionParser::parse - Try to parse " << str) |
25 | 20 | |
26 | 21 | std::string::const_iterator iter = str.begin(), end = str.end(); |
27 | 22 | |
28 | - parserExpression<std::string::const_iterator,boost::spirit::qi::space_type> parser; | |
29 | - Expression::expressionContainer expr; | |
23 | + ParserGrammar<std::string::const_iterator,boost::spirit::qi::space_type> grammar; | |
24 | + Expression::ExpressionContainer expr; | |
30 | 25 | |
31 | - bool result = boost::spirit::qi::phrase_parse(iter,end,parser,boost::spirit::qi::space, expr); | |
26 | + bool result = boost::spirit::qi::phrase_parse(iter,end,grammar,boost::spirit::qi::space, expr); | |
32 | 27 | |
33 | 28 | if(!result || iter != end) |
34 | 29 | { | ... | ... |
src/expressionParser/ExpressionParser.hh
... | ... | @@ -7,6 +7,9 @@ |
7 | 7 | |
8 | 8 | #ifndef EXPRESSIONPARSER_HH_ |
9 | 9 | #define EXPRESSIONPARSER_HH_ |
10 | + | |
11 | +#include "Properties.hh" | |
12 | + | |
10 | 13 | #include <iostream> |
11 | 14 | |
12 | 15 | namespace AMDA { |
... | ... | @@ -23,7 +26,7 @@ public: |
23 | 26 | /** |
24 | 27 | * Exemple of parser |
25 | 28 | */ |
26 | - static std::string parse(const std::string& s); | |
29 | + static std::string parse(const std::string& s, AMDA::helpers::Properties& lProperties); | |
27 | 30 | }; |
28 | 31 | |
29 | 32 | } /* naemspace parser */ | ... | ... |
src/expressionParser/ExpressionPrinter.hh
... | ... | @@ -7,9 +7,10 @@ namespace AMDA { |
7 | 7 | namespace parser { |
8 | 8 | namespace Expression { |
9 | 9 | |
10 | -struct printer : boost::static_visitor<void> | |
10 | +class ExpressionPrinter : public boost::static_visitor<void> | |
11 | 11 | { |
12 | - printer(std::ostream& os) : _os(os) {} | |
12 | +public: | |
13 | + ExpressionPrinter(std::ostream& os) : _os(os) {} | |
13 | 14 | std::ostream& _os; |
14 | 15 | |
15 | 16 | // |
... | ... | @@ -42,7 +43,7 @@ struct printer : boost::static_visitor<void> |
42 | 43 | void operator()(const unop<op_minusSign>& u) const{printUnique("-",u.oper1);} |
43 | 44 | |
44 | 45 | // printer |
45 | - void print(const std::string& op, const expressionContainer& l, const expressionContainer& r) const | |
46 | + void print(const std::string& op, const ExpressionContainer& l, const ExpressionContainer& r) const | |
46 | 47 | { |
47 | 48 | _os << "("; |
48 | 49 | boost::apply_visitor(*this, l); |
... | ... | @@ -51,18 +52,18 @@ struct printer : boost::static_visitor<void> |
51 | 52 | _os << ")"; |
52 | 53 | } |
53 | 54 | |
54 | - void printUnique(const std::string& op, const expressionContainer& l) const | |
55 | + void printUnique(const std::string& op, const ExpressionContainer& l) const | |
55 | 56 | { |
56 | 57 | _os << op; |
57 | 58 | boost::apply_visitor(*this, l); |
58 | 59 | } |
59 | - void printPower(const std::string& op, const expressionContainer& l, const expressionContainer& r) const | |
60 | + void printPower(const std::string& op, const ExpressionContainer& l, const ExpressionContainer& r) const | |
60 | 61 | { |
61 | 62 | boost::apply_visitor(*this, l); |
62 | 63 | _os << op; |
63 | 64 | boost::apply_visitor(*this, r); |
64 | 65 | } |
65 | - void printOutSide(const std::string& op, const expressionContainer& l, const expressionContainer& r) const | |
66 | + void printOutSide(const std::string& op, const ExpressionContainer& l, const ExpressionContainer& r) const | |
66 | 67 | { |
67 | 68 | _os << op; |
68 | 69 | _os << "("; |
... | ... | @@ -73,9 +74,9 @@ struct printer : boost::static_visitor<void> |
73 | 74 | } |
74 | 75 | }; |
75 | 76 | |
76 | -std::ostream& operator<<(std::ostream& os, const expressionContainer& e) | |
77 | +std::ostream& operator<<(std::ostream& os, const ExpressionContainer& e) | |
77 | 78 | { |
78 | - boost::apply_visitor(printer(os), e); | |
79 | + boost::apply_visitor(ExpressionPrinter(os), e); | |
79 | 80 | return os; |
80 | 81 | } |
81 | 82 | ... | ... |
src/expressionParser/Main.cc
... | ... | @@ -66,12 +66,10 @@ int main(int argc, char *argv[]) { |
66 | 66 | vector<string> lExpressionList = vm["expression"].as< vector<string> >(); |
67 | 67 | std::map<std::string, std::string> expressionMap; |
68 | 68 | for(auto expression :lExpressionList){ |
69 | - LOG4CXX_INFO(logger,"Parasing expression: "<<expression); | |
69 | + LOG4CXX_INFO(logger,"Parsing expression: "<<expression); | |
70 | 70 | try{ |
71 | - std::string parsedExp = AMDA::parser::ExpressionParser::parse(expression); | |
71 | + std::string parsedExp = AMDA::parser::ExpressionParser::parse(expression, lProperties); | |
72 | 72 | expressionMap[expression] = parsedExp; |
73 | - std::cout<<parsedExp<<std::endl; | |
74 | - LOG4CXX_INFO(logger,expression<<" Gives : "<<parsedExp); | |
75 | 73 | }catch(...) { |
76 | 74 | |
77 | 75 | } | ... | ... |
src/expressionParser/ParserGrammar.hh
... | ... | @@ -16,9 +16,10 @@ using namespace qi; |
16 | 16 | using namespace Expression; |
17 | 17 | |
18 | 18 | template <typename It, typename Skipper = boost::spirit::standard_wide::space_type> |
19 | -struct parserExpression : qi::grammar<It, Expression::expressionContainer(), Skipper> | |
19 | +class ParserGrammar : public qi::grammar<It, Expression::ExpressionContainer(), Skipper> | |
20 | 20 | { |
21 | - parserExpression() : parserExpression::base_type(expr_) | |
21 | +public: | |
22 | + ParserGrammar() : ParserGrammar::base_type(expr_) | |
22 | 23 | { |
23 | 24 | expr_ = or_.alias(); |
24 | 25 | |
... | ... | @@ -72,7 +73,7 @@ struct parserExpression : qi::grammar<It, Expression::expressionContainer(), Ski |
72 | 73 | |
73 | 74 | private: |
74 | 75 | qi::rule<It, Expression::var(), Skipper> var_; |
75 | - qi::rule<It, Expression::expressionContainer(), Skipper> not_ | |
76 | + qi::rule<It, Expression::ExpressionContainer(), Skipper> not_ | |
76 | 77 | , and_ |
77 | 78 | , xor_ |
78 | 79 | , or_ | ... | ... |