Vcsn  2.4
Be Rational
type-ast.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <iostream>
4 #include <memory>
5 #include <vector>
6 
8 
10 #include <vcsn/dyn/fwd.hh>
11 
12 
13 namespace vcsn
14 {
15  namespace ast
16  {
17 
18 #define ACCEPT() \
19  virtual void accept(context_visitor &v) const \
20  { \
21  v.visit(*this); \
22  }
23 
24  class ast_node
25  {
26  public:
27  virtual ~ast_node() = default;
28 
29  virtual void accept(context_visitor &v) const = 0;
30 
31  virtual bool has_one() const { return false; }
32  };
33 
34  class context: public ast_node
35  {
36  public:
37  context(std::shared_ptr<ast_node> ls, std::shared_ptr<ast_node> ws)
38  : ls_(ls), ws_(ws)
39  {}
40 
41  const std::shared_ptr<ast_node> get_labelset() const
42  {
43  return ls_;
44  }
45 
46  const std::shared_ptr<ast_node> get_weightset() const
47  {
48  return ws_;
49  }
50 
52 
53  private:
54  std::shared_ptr<ast_node> ls_;
55  std::shared_ptr<ast_node> ws_;
56  };
57 
58  class tupleset: public ast_node
59  {
60  public:
61  using value_t = std::vector<std::shared_ptr<ast_node>>;
62 
63  tupleset(const value_t& sets)
64  : sets_(sets)
65  {}
66 
67  const value_t get_sets() const
68  {
69  return sets_;
70  }
71 
73  virtual bool has_one() const
74  {
75  for (auto s : get_sets())
76  if (!s->has_one())
77  return false;
78  return true;
79  }
80 
81  private:
83  };
84 
85  class tuple: public ast_node
86  {
87  public:
88  using value_t = std::vector<std::shared_ptr<ast_node>>;
89 
90  tuple(const value_t& sets)
91  : sets_(sets)
92  {}
93 
94  const value_t get_sets() const
95  {
96  return sets_;
97  }
98 
100  virtual bool has_one() const
101  {
102  for (auto s : get_sets())
103  if (!s->has_one())
104  return false;
105  return true;
106  }
107 
108  private:
110  };
111 
112  class nullableset : public ast_node
113  {
114  public:
115  nullableset(std::shared_ptr<ast_node> ls)
116  : ls_(ls)
117  {}
118 
119  const std::shared_ptr<ast_node> get_labelset() const
120  {
121  return ls_;
122  }
123 
125 
126  virtual bool has_one() const { return true; }
127 
128  private:
129  std::shared_ptr<ast_node> ls_;
130  };
131 
132  class oneset : public ast_node
133  {
134  public:
136  {}
137 
139  virtual bool has_one() const { return true; }
140  };
141 
145  class genset: public ast_node
146  {
147  public:
148  genset(const std::string& letter_type, const std::string& gens)
149  : letter_type_(letter_type)
150  , generators_(gens)
151  {}
152 
154 
155 
156  const std::string& letter_type() const
157  {
158  return letter_type_;
159  }
160 
162  const std::string& generators() const
163  {
164  return generators_;
165  }
166 
167  private:
168  const std::string letter_type_;
169  const std::string generators_;
170  };
171 
173  class letterset: public ast_node
174  {
175  public:
176  letterset(const std::shared_ptr<const ast_node>& gs)
177  : gs_(gs)
178  {}
179 
181  std::shared_ptr<const ast_node> genset() const
182  {
183  return gs_;
184  }
185 
187  virtual bool has_one() const { return false; }
188 
189  private:
190  const std::shared_ptr<const ast_node> gs_;
191  };
192 
194  class wordset: public ast_node
195  {
196  public:
197  wordset(const std::shared_ptr<const ast_node>& gs)
198  : gs_(gs)
199  {}
200 
202  std::shared_ptr<const ast_node> genset() const
203  {
204  return gs_;
205  }
206 
208  virtual bool has_one() const { return true; }
209 
210  private:
211  const std::shared_ptr<const ast_node> gs_;
212  };
213 
214  class expressionset: public ast_node
215  {
216  public:
217  expressionset(std::shared_ptr<context> ctx,
219  : ctx_(ctx)
220  , identities_(ids)
221  {}
222 
223  const std::shared_ptr<context> get_context() const
224  {
225  return ctx_;
226  }
227 
229  {
230  return identities_;
231  }
232 
234  virtual bool has_one() const { return true; }
235 
236  private:
237  std::shared_ptr<context> ctx_;
239  };
240 
241  class expansionset: public ast_node
242  {
243  public:
244  expansionset(std::shared_ptr<expressionset> rs)
245  : rs_(rs)
246  {}
247 
248  const std::shared_ptr<expressionset> get_expressionset() const
249  {
250  return rs_;
251  }
252 
254  virtual bool has_one() const { return true; }
255 
256  private:
257  std::shared_ptr<expressionset> rs_;
258  };
259 
260  class weightset: public ast_node
261  {
262  public:
263  weightset(const std::string& type)
264  : type_(type)
265  {}
266 
267  const std::string& get_type() const
268  {
269  return type_;
270  }
271 
273  private:
274  std::string type_;
275  };
276 
277  class other : public ast_node
278  {
279  public:
280  other(const std::string& type)
281  : type_(type)
282  {}
283 
284  const std::string& get_type() const
285  {
286  return type_;
287  }
288 
290  private:
291  std::string type_;
292  };
293 
294  class automaton: public ast_node
295  {
296  public:
297  using node_t = std::shared_ptr<ast_node>;
298  using nodes_t = std::vector<node_t>;
299  automaton(const std::string& type, const node_t& child)
300  : type_(type)
301  , children_{child}
302  {}
303 
304  automaton(const std::string& type, const nodes_t& children)
305  : type_(type)
306  , children_(children)
307  {}
308 
309  const std::string& get_type() const
310  {
311  return type_;
312  }
313 
314  const nodes_t& get_content() const
315  {
316  return children_;
317  }
318 
320  {
321  return children_;
322  }
323 
325 
326  private:
327  std::string type_;
328  nodes_t children_;
329  };
330 
331  class polynomialset : public ast_node
332  {
333  public:
334  polynomialset(std::shared_ptr<ast_node> child)
335  : child_(child)
336  {}
337 
338  const std::shared_ptr<ast_node>& get_content() const
339  {
340  return child_;
341  }
342 
344 
345  private:
346  std::shared_ptr<ast_node> child_;
347  };
348 #undef ACCEPT
349  }
350 }
rat::identities get_identities() const
Definition: type-ast.hh:228
STL namespace.
const std::string letter_type_
Definition: type-ast.hh:168
const std::string & get_type() const
Definition: type-ast.hh:284
Support for letterset.
Definition: type-ast.hh:173
auto rs
Definition: lift.hh:152
static identities ids(const driver &d)
Get the identities of the driver.
Definition: parse.cc:89
Support for wordset.
Definition: type-ast.hh:194
const value_t get_sets() const
Definition: type-ast.hh:67
const value_t get_sets() const
Definition: type-ast.hh:94
std::vector< std::shared_ptr< ast_node >> value_t
Definition: type-ast.hh:61
const std::string & get_type() const
Definition: type-ast.hh:267
polynomialset(std::shared_ptr< ast_node > child)
Definition: type-ast.hh:334
nodes_t & get_content()
Definition: type-ast.hh:319
#define ACCEPT()
Definition: type-ast.hh:18
const nodes_t & get_content() const
Definition: type-ast.hh:314
genset(const std::string &letter_type, const std::string &gens)
Definition: type-ast.hh:148
const std::shared_ptr< context > get_context() const
Definition: type-ast.hh:223
tuple(const value_t &sets)
Definition: type-ast.hh:90
tupleset(const value_t &sets)
Definition: type-ast.hh:63
automaton(const std::string &type, const nodes_t &children)
Definition: type-ast.hh:304
std::vector< std::shared_ptr< ast_node >> value_t
Definition: type-ast.hh:88
Definition: a-star.hh:8
std::shared_ptr< ast_node > node_t
Definition: type-ast.hh:297
letterset(const std::shared_ptr< const ast_node > &gs)
Definition: type-ast.hh:176
const std::shared_ptr< ast_node > get_labelset() const
Definition: type-ast.hh:119
nullableset(std::shared_ptr< ast_node > ls)
Definition: type-ast.hh:115
const std::shared_ptr< ast_node > & get_content() const
Definition: type-ast.hh:338
const std::string generators_
Definition: type-ast.hh:169
expansionset(std::shared_ptr< expressionset > rs)
Definition: type-ast.hh:244
std::shared_ptr< ast_node > ls_
Definition: type-ast.hh:54
other(const std::string &type)
Definition: type-ast.hh:280
expressionset(std::shared_ptr< context > ctx, rat::identities ids)
Definition: type-ast.hh:217
virtual void accept(context_visitor &v) const =0
const std::shared_ptr< const ast_node > gs_
Definition: type-ast.hh:190
std::shared_ptr< ast_node > ls_
Definition: type-ast.hh:129
virtual ~ast_node()=default
rat::identities identities_
Definition: type-ast.hh:238
std::shared_ptr< expressionset > rs_
Definition: type-ast.hh:257
An expressionset can implement several different sets of identities on expressions.
Definition: identities.hh:21
return v
Definition: multiply.hh:361
automaton(const std::string &type, const node_t &child)
Definition: type-ast.hh:299
std::shared_ptr< context > ctx_
Definition: type-ast.hh:237
weightset(const std::string &type)
Definition: type-ast.hh:263
const std::string & generators() const
The generators.
Definition: type-ast.hh:162
const std::shared_ptr< expressionset > get_expressionset() const
Definition: type-ast.hh:248
std::shared_ptr< ast_node > ws_
Definition: type-ast.hh:55
const std::shared_ptr< const ast_node > gs_
Definition: type-ast.hh:211
const std::shared_ptr< ast_node > get_labelset() const
Definition: type-ast.hh:41
const std::shared_ptr< ast_node > get_weightset() const
Definition: type-ast.hh:46
Represents the "alphabets", or "generator set".
Definition: type-ast.hh:145
context(std::shared_ptr< ast_node > ls, std::shared_ptr< ast_node > ws)
Definition: type-ast.hh:37
wordset(const std::shared_ptr< const ast_node > &gs)
Definition: type-ast.hh:197
std::shared_ptr< const ast_node > genset() const
The generator set.
Definition: type-ast.hh:202
std::shared_ptr< const ast_node > genset() const
The generator set.
Definition: type-ast.hh:181
virtual bool has_one() const
Definition: type-ast.hh:31
const std::string & get_type() const
Definition: type-ast.hh:309
std::vector< node_t > nodes_t
Definition: type-ast.hh:298