OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
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 UDouble
Definition: MSLang.h:34
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition: Polygon.cpp:15
static bool parse_detail(iterator &it, const iterator &end, Function *fun)
Definition: Ellipse.cpp:119
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: Difference.cpp:32
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition: Mask.cpp:120
static bool parse(iterator &it, const iterator &end, Function *&fun)
Definition: MSLang.cpp:48
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition: Rotation.cpp:38
static const std::string FCall
Definition: MSLang.h:37
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
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: Shear.cpp:42
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition: Translation.cpp:39
std::string::iterator iterator
Definition: MSLang.h:16
bool parse(std::string str, Function *&fun)
Definition: MSLang.cpp:37
static const std::string UInt
Definition: MSLang.h:36
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition: Union.cpp:31
static const std::string Double
Definition: MSLang.h:35