OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
MSLang.cpp
Go to the documentation of this file.
1 #include "Utilities/MSLang.h"
11 #include "Utilities/MSLang/Union.h"
17 #include "Utilities/Mesher.h"
18 #include "Algorithms/Quaternion.h"
19 #include "Physics/Physics.h"
20 
21 
22 #include <boost/regex.hpp>
23 
24 #include <iostream>
25 #include <string>
26 #include <fstream>
27 #include <streambuf>
28 #include <cstdlib>
29 #include <cmath>
30 
31 namespace mslang {
32  const std::string Function::UDouble = "([0-9]+\\.?[0-9]*([Ee][+-]?[0-9]+)?)";
33  const std::string Function::Double = "(-?[0-9]+\\.?[0-9]*([Ee][+-]?[0-9]+)?)";
34  const std::string Function::UInt = "([0-9]+)";
35  const std::string Function::FCall = "([a-z_]*)\\((.*)";
36 
37  bool parse(std::string str, Function* &fun) {
38  iterator it = str.begin();
39  iterator end = str.end();
40  if (!Function::parse(it, end, fun)) {
41  std::cout << "parsing failed here:" << std::string(it, end) << std::endl;
42  return false;
43  }
44 
45  return true;
46  }
47 
48  bool Function::parse(iterator &it, const iterator &end, Function* &fun) {
49  boost::regex functionCall(Function::FCall);
50  boost::smatch what;
51 
52  std::string str(it, end);
53  if( !boost::regex_match(str , what, functionCall ) ) return false;
54 
55  std::string identifier = what[1];
56  std::string arguments = what[2];
57  unsigned int shift = identifier.size() + 1;
58 
59  if (identifier == "rectangle") {
60  fun = new Rectangle;
61  it += shift;
62  if (!Rectangle::parse_detail(it, end, fun)) return false;
63 
64  return true;
65  } else if (identifier == "ellipse") {
66  fun = new Ellipse;
67  it += shift;
68  if (!Ellipse::parse_detail(it, end, fun)) return false;
69 
70  return true;
71  } else if (identifier == "polygon") {
72  fun = new Polygon;
73  it += shift;
74  if (!Polygon::parse_detail(it, end, fun)) return false;
75 
76  return true;
77  } else if (identifier == "mask") {
78  fun = new Mask;
79  it += shift;
80 
81  return Mask::parse_detail(it, end, fun);
82  } else if (identifier == "repeat") {
83  fun = new Repeat;
84  it += shift;
85  if (!Repeat::parse_detail(it, end, fun)) return false;
86 
87  return true;
88  } else if (identifier == "rotate") {
89  fun = new Rotation;
90  it += shift;
91  if (!Rotation::parse_detail(it, end, fun)) return false;
92 
93  return true;
94  } else if (identifier == "translate") {
95  fun = new Translation;
96  it += shift;
97  if (!Translation::parse_detail(it, end, fun)) return false;
98 
99  return true;
100  } else if (identifier == "shear") {
101  fun = new Shear;
102  it += shift;
103  if (!Shear::parse_detail(it, end, fun)) return false;
104 
105  return true;
106  } else if (identifier == "union") {
107  fun = new Union;
108  it += shift;
109  if (!Union::parse_detail(it, end, fun)) return false;
110 
111  return true;
112  } else if (identifier == "difference") {
113  fun = new Difference;
114  it += shift;
115  if (!Difference::parse_detail(it, end, fun)) return false;
116 
117  return true;
118  } else if (identifier == "symmetric_difference") {
119 
120  fun = new SymmetricDifference;
121  it += shift;
122  if (!SymmetricDifference::parse_detail(it, end, fun)) return false;
123 
124  return true;
125  } else if (identifier == "intersection") {
126  fun = new Intersection;
127  it += shift;
128  if (!Intersection::parse_detail(it, end, fun)) return false;
129 
130  return true;
131  }
132 
133  return (it == end);
134  }
135 }
static const std::string FCall
Definition: MSLang.h:36
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition: Difference.cpp:32
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed we want its recipients to know that what they have is not the so that any problems introduced by others will not reflect on the original authors reputations any free program is threatened constantly by software patents We wish to avoid the danger that redistributors of a free program will individually obtain patent in effect making the program proprietary To prevent we have made it clear that any patent must be licensed for everyone s free use or not licensed at all The precise terms and conditions for distribution and modification follow GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR DISTRIBUTION AND MODIFICATION This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License The refers to any such program or and a work based on the Program means either the Program or any derivative work under copyright a work containing the Program or a portion of it
Definition: LICENSE:43
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition: Union.cpp:31
static const std::string Double
Definition: MSLang.h:34
static const std::string UInt
Definition: MSLang.h:35
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition: Shear.cpp:42
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
static bool parse_detail(iterator &it, const iterator &end, Function *fun)
Definition: Ellipse.cpp:120
static bool parse(iterator &it, const iterator &end, Function *&fun)
Definition: MSLang.cpp:48
std::string::iterator iterator
Definition: MSLang.h:15
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition: Mask.cpp:121
bool parse(std::string str, Function *&fun)
Definition: MSLang.cpp:37
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition: Rotation.cpp:38
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition: Translation.cpp:39
static const std::string UDouble
Definition: MSLang.h:33
static bool parse_detail(iterator &it, const iterator &end, Function *fun)
Definition: Rectangle.cpp:107
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition: Repeat.cpp:36
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition: Polygon.cpp:15
end
Definition: multipole_t.tex:9