Skip to content

Commit

Permalink
parser : minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
srajangarg committed Feb 10, 2016
1 parent 0c64af9 commit d50b439
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
18 changes: 12 additions & 6 deletions symengine/parser.cpp
Expand Up @@ -9,6 +9,7 @@
#include <symengine/functions.h>
#include <symengine/constants.h>
#include <symengine/visitor.h>
#include <symengine/parser.h>
#include <vector>
#include <stack>
#include <map>
Expand All @@ -22,12 +23,12 @@ class ExpressionParser {

// OPERATORS and op_precedence used internally, for parsing
std::set<char> OPERATORS = {'-', '+', '*', '/', '^', '(', ')', ','};
std::map<char, int> op_precedence = {
std::map<char, const int> op_precedence = {
{')', 0}, {',', 0}, {'-', 1}, {'+', 1},
{'*', 3}, {'/', 4}, {'^', 5}
};
// symengine supported constants
std::map<std::string, RCP<const Basic> > constants = {
std::map<const std::string, const RCP<const Basic> > constants = {

{"e", E}, {"E", E}, {"EulerGamma", EulerGamma}, {"pi", pi}, {"I", I}
};
Expand All @@ -44,8 +45,8 @@ class ExpressionParser {
double_arg_func double_casted_zeta = zeta;

// maps string to corresponding single argument function
std::map< std::string,
std::function<RCP<const Basic>(const RCP<const Basic>&)>
std::map< const std::string,
const std::function<RCP<const Basic>(const RCP<const Basic>&)>
> single_arg_functions = {

{"", [](const RCP<const Basic>& x){return x;}},
Expand All @@ -68,8 +69,8 @@ class ExpressionParser {
};

// maps string to corresponding double argument function
std::map< std::string,
std::function<RCP<const Basic>(const RCP<const Basic>&, const RCP<const Basic>&)>
std::map< const std::string,
const std::function<RCP<const Basic>(const RCP<const Basic>&, const RCP<const Basic>&)>
> double_arg_functions = {

{"pow", pow}, {"beta", beta}, {"log", double_casted_log}, {"zeta", double_casted_zeta},
Expand Down Expand Up @@ -324,4 +325,9 @@ class ExpressionParser {
}
};

RCP<const Basic> parse(const std::string& s) {
ExpressionParser p;
return p.parse_expr(s);
}

} // SymEngine
6 changes: 1 addition & 5 deletions symengine/parser.h
Expand Up @@ -3,14 +3,10 @@

#include <symengine/basic.h>
#include <symengine/dict.h>
#include <symengine/parser.cpp>

namespace SymEngine {

inline RCP<const Basic> parse(std::string& s) {
ExpressionParser p;
return p.parse_expr(s);
}
RCP<const Basic> parse(const std::string& s);

} // SymEngine

Expand Down

0 comments on commit d50b439

Please sign in to comment.