C++ mpi module for stochmagnet_main Package
EXPR_Parser.h
1 #ifndef EXPR_Parser_H
2 #define EXPR_Parser_H
3 
4 #include "EXPR_Object.h"
5 
6 #include "EXPR_Tokenizer.h"
7 #include "EXPR_RootNode.h"
8 #include "EXPR_Environment.h"
9 
10 #include "EXPR_OperatorNode.h"
11 #include "EXPR_GroupNode.h"
12 #include "EXPR_ElementaryGeometryNode.h"
13 #include "EXPR_Function.h"
14 
15 
23 class EXPR_Parser : public virtual EXPR_Object {
24 
25 private:
26  //attributes
27 
28 
29 private:
30  //associations
31 
32  CORE_UniquePointer<EXPR_Tokenizer> mTokenizer;
33  CORE_UniquePointer<EXPR_Environment> mEnvironment;
34  CORE_UniquePointer<EXPR_RootNode> mTree;
35 
36  //list of unary operators
37  std::vector<CORE_UniquePointer<EXPR_OperatorNode>> mLeftUnaryOperators;
38 
39  //list of binary operators withith priority 1
40  std::vector<CORE_UniquePointer<EXPR_OperatorNode>> m1OrderBinaryOperators;
41  //list of binary operators withith priority 2
42  std::vector<CORE_UniquePointer<EXPR_OperatorNode>> m2OrderBinaryOperators;
43 
44  //list of leaf geometries
45  std::vector<CORE_UniquePointer<EXPR_ElementaryGeometryNode>> mGeometries;
46 
47  //list of predeifined functions
48  std::vector<CORE_UniquePointer<EXPR_Function>> mFunctions;
49 
50  //expression to parse
51  tString mParseExpression;
52 
53 protected:
54  //builders
55 
58  EXPR_Parser();
59 
60  //deleters
63  virtual ~EXPR_Parser();
64 public:
65  //methods
66 
69  inline static CORE_UniquePointer<EXPR_Parser> New() {
70  CORE_UniquePointer<EXPR_Parser> p(new EXPR_Parser(),EXPR_Parser::Delete());
71  return p;
72  };
73 
77  const EXPR_RootNode * getTree() const {
78  return mTree.get();
79  }
84  const EXPR_RootNode * getTree(const tString& name) const {
85  const EXPR_VariableNode* var=mEnvironment->lookUp(name);
86  if (var==null) return null;
87  return var->getExpression();
88  }
92  const EXPR_Environment * getEnvironment() const {
93  return mEnvironment.get();
94  }
99  return mEnvironment.get();
100  }
101 
102 
107  tBoolean parse(const tString& expr);
108 
112  inline tBoolean parse() {
113  return parse(mParseExpression);
114  }
115 
118  inline const tString& getParseExpression() const {
119  return mParseExpression;
120  }
121 
124  inline void computeBoundingBox() {
125  std::map<tString,tBoolean> alreadyComputed;
126  mEnvironment->computeBoundingBox(alreadyComputed);
127  mTree->computeBoundingBox(alreadyComputed);
128  }
129 
132  inline void adimensionize(const tReal& L) {
133  if (L==0) {
134  std::cout << "adimenionsionization failed when L=0. Ignored \n";
135  return;
136  }
137  std::map<tString,tBoolean> alreadyComputed;
138  mEnvironment->adimensionize(L,alreadyComputed);
139  mTree->adimensionize(L,alreadyComputed);
140  }
141 
142 private:
146  tBoolean readAssignement(EXPR_Environment& env);
147 
151  tBoolean readExpression(EXPR_ParentNode& node);
152 
156  CORE_SharedPointer<EXPR_ChildNode> read2OrderBinaryOperator();
160  CORE_SharedPointer<EXPR_ChildNode> read1OrderBinaryOperator();
161 
165  CORE_SharedPointer<EXPR_OperatorNode> readLeftUnaryOperator();
166 
170  CORE_SharedPointer<EXPR_ChildNode> readTerm();
171 
175  CORE_SharedPointer<EXPR_GroupNode> readGroup();
176 
180  CORE_SharedPointer<EXPR_ChildNode> readFunction();
181 
187  CORE_SharedPointer<EXPR_ChildNode> apply(const tString& name,
188  const std::vector<tString>& args,
189  EXPR_Environment& env);
190 
194  CORE_SharedPointer<EXPR_ChildNode> readFactor();
195 
196 public:
200  virtual tString toString() const override;
201 
202 };
203 
204 
205 
206 
207 #endif
208 
209 
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
This class is the environment with contains all the variable value.
Definition: EXPR_Environment.h:20
This class is the base class of all the parser package.
Definition: EXPR_Object.h:27
This class is a parent node with children.
Definition: EXPR_ParentNode.h:23
This class parse an expression into a tree.
Definition: EXPR_Parser.h:23
void computeBoundingBox()
compute the bounding box of the main expression and its environment
Definition: EXPR_Parser.h:124
const EXPR_RootNode * getTree(const tString &name) const
get the tree with name
Definition: EXPR_Parser.h:84
const tString & getParseExpression() const
return the last parse exopression
Definition: EXPR_Parser.h:118
EXPR_Parser()
create the class
Definition: EXPR_Parser.cpp:15
virtual tString toString() const override
return the string representation of this
Definition: EXPR_Parser.cpp:450
EXPR_Environment * getEnvironment()
get the environment
Definition: EXPR_Parser.h:98
void adimensionize(const tReal &L)
adimensionize the main expression and its environment
Definition: EXPR_Parser.h:132
static CORE_UniquePointer< EXPR_Parser > New()
create a test class
Definition: EXPR_Parser.h:69
virtual ~EXPR_Parser()
delete the class
Definition: EXPR_Parser.cpp:40
const EXPR_RootNode * getTree() const
get the tree
Definition: EXPR_Parser.h:77
tBoolean parse()
parse the expression
Definition: EXPR_Parser.h:112
const EXPR_Environment * getEnvironment() const
get the environment
Definition: EXPR_Parser.h:92
This class describes the root of the tree.
Definition: EXPR_RootNode.h:16
This class describes a variable node with contains:
Definition: EXPR_VariableNode.h:17
const EXPR_RootNode * getExpression() const
get the expression of the variable
Definition: EXPR_VariableNode.h:95