Vcsn  2.5.dev
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 
86  class tuple: public ast_node
87  {
88  public:
89  using value_t = std::vector<std::shared_ptr<ast_node>>;
90 
91  tuple(const value_t& sets)
92  : sets_(sets)
93  {}
94 
95  const value_t get_sets() const
96  {
97  return sets_;
98  }
99 
101  virtual bool has_one() const
102  {
103  for (auto s : get_sets())
104  if (!s->has_one())
105  return false;
106  return true;
107  }
108 
109  private:
111  };
112 
113  class nullableset : public ast_node
114  {
115  public:
116  nullableset(std::shared_ptr<ast_node> ls)
117  : ls_(ls)
118  {}
119 
120  const std::shared_ptr<ast_node> get_labelset() const
121  {
122  return ls_;
123  }
124 
126 
127  virtual bool has_one() const { return true; }
128 
129  private:
130  std::shared_ptr<ast_node> ls_;
131  };
132 
133 
134  class oneset : public ast_node
135  {
136  public:
138  {}
139 
141  virtual bool has_one() const { return true; }
142  };
143 
144 
148  class genset: public ast_node
149  {
150  public:
151  genset(const std::string& letter_type, const std::string& gens)
152  : letter_type_(letter_type)
153  , generators_(gens)
154  {}
155 
157 
158 
159  const std::string& letter_type() const
160  {
161  return letter_type_;
162  }
163 
165  const std::string& generators() const
166  {
167  return generators_;
168  }
169 
170  private:
171  const std::string letter_type_;
172  const std::string generators_;
173  };
174 
176  class letterset: public ast_node
177  {
178  public:
179  letterset(const std::shared_ptr<const ast_node>& gs)
180  : gs_(gs)
181  {}
182 
184  std::shared_ptr<const ast_node> genset() const
185  {
186  return gs_;
187  }
188 
190  virtual bool has_one() const { return false; }
191 
192  private:
193  const std::shared_ptr<const ast_node> gs_;
194  };
195 
196 
198  class wordset: public ast_node
199  {
200  public:
201  wordset(const std::shared_ptr<const ast_node>& gs)
202  : gs_(gs)
203  {}
204 
206  std::shared_ptr<const ast_node> genset() const
207  {
208  return gs_;
209  }
210 
212  virtual bool has_one() const { return true; }
213 
214  private:
215  const std::shared_ptr<const ast_node> gs_;
216  };
217 
218  class expressionset: public ast_node
219  {
220  public:
221  expressionset(std::shared_ptr<context> ctx,
223  : ctx_(ctx)
224  , identities_(ids)
225  {}
226 
227  const std::shared_ptr<context> get_context() const
228  {
229  return ctx_;
230  }
231 
233  {
234  return identities_;
235  }
236 
238  virtual bool has_one() const { return true; }
239 
240  private:
241  std::shared_ptr<context> ctx_;
243  };
244 
245 
246  class expansionset: public ast_node
247  {
248  public:
249  expansionset(std::shared_ptr<expressionset> rs)
250  : rs_(rs)
251  {}
252 
253  const std::shared_ptr<expressionset> get_expressionset() const
254  {
255  return rs_;
256  }
257 
259  virtual bool has_one() const { return true; }
260 
261  private:
262  std::shared_ptr<expressionset> rs_;
263  };
264 
265 
266  class weightset: public ast_node
267  {
268  public:
269  weightset(const std::string& type)
270  : type_(type)
271  {}
272 
273  const std::string& get_type() const
274  {
275  return type_;
276  }
277 
279  private:
280  std::string type_;
281  };
282 
283 
284  class other : public ast_node
285  {
286  public:
287  other(const std::string& type)
288  : type_(type)
289  {}
290 
291  const std::string& get_type() const
292  {
293  return type_;
294  }
295 
297  private:
298  std::string type_;
299  };
300 
301 
302  class automaton: public ast_node
303  {
304  public:
305  using node_t = std::shared_ptr<ast_node>;
306  using nodes_t = std::vector<node_t>;
307  automaton(const std::string& type, const node_t& child)
308  : type_(type)
309  , children_{child}
310  {}
311 
312  automaton(const std::string& type, const nodes_t& children)
313  : type_(type)
314  , children_(children)
315  {}
316 
317  const std::string& get_type() const
318  {
319  return type_;
320  }
321 
322  const nodes_t& get_content() const
323  {
324  return children_;
325  }
326 
328  {
329  return children_;
330  }
331 
333 
334  private:
335  std::string type_;
336  nodes_t children_;
337  };
338 
339 
340  class polynomialset : public ast_node
341  {
342  public:
343  polynomialset(std::shared_ptr<ast_node> child)
344  : child_(child)
345  {}
346 
347  const std::shared_ptr<ast_node>& get_content() const
348  {
349  return child_;
350  }
351 
353 
354  private:
355  std::shared_ptr<ast_node> child_;
356  };
357 #undef ACCEPT
358  }
359 }
const std::string generators_
Definition: type-ast.hh:172
const std::string & generators() const
The generators.
Definition: type-ast.hh:165
virtual ~ast_node()=default
Represents the "alphabets", or "generator set".
Definition: type-ast.hh:148
const value_t get_sets() const
Definition: type-ast.hh:95
letterset(const std::shared_ptr< const ast_node > &gs)
Definition: type-ast.hh:179
const std::shared_ptr< const ast_node > gs_
Definition: type-ast.hh:215
rat::identities identities_
Definition: type-ast.hh:242
const std::shared_ptr< ast_node > get_weightset() const
Definition: type-ast.hh:46
const std::shared_ptr< ast_node > get_labelset() const
Definition: type-ast.hh:120
std::shared_ptr< context > ctx_
Definition: type-ast.hh:241
nodes_t & get_content()
Definition: type-ast.hh:327
other(const std::string &type)
Definition: type-ast.hh:287
Support for wordset<GenSet>.
Definition: type-ast.hh:198
const value_t get_sets() const
Definition: type-ast.hh:67
weightset(const std::string &type)
Definition: type-ast.hh:269
polynomialset(std::shared_ptr< ast_node > child)
Definition: type-ast.hh:343
const std::string letter_type_
Definition: type-ast.hh:171
const std::shared_ptr< ast_node > get_labelset() const
Definition: type-ast.hh:41
const std::string & get_type() const
Definition: type-ast.hh:273
#define ACCEPT()
Definition: type-ast.hh:18
const std::shared_ptr< expressionset > get_expressionset() const
Definition: type-ast.hh:253
rat::identities get_identities() const
Definition: type-ast.hh:232
expansionset(std::shared_ptr< expressionset > rs)
Definition: type-ast.hh:249
const std::string & get_type() const
Definition: type-ast.hh:317
Traverse a type-ast.
wordset(const std::shared_ptr< const ast_node > &gs)
Definition: type-ast.hh:201
return v
Definition: multiply.hh:362
std::vector< node_t > nodes_t
Definition: type-ast.hh:306
Support for letterset<GenSet>.
Definition: type-ast.hh:176
tuple(const value_t &sets)
Definition: type-ast.hh:91
std::shared_ptr< ast_node > node_t
Definition: type-ast.hh:305
nullableset(std::shared_ptr< ast_node > ls)
Definition: type-ast.hh:116
virtual void accept(context_visitor &v) const =0
std::vector< std::shared_ptr< ast_node > > value_t
Definition: type-ast.hh:61
automaton(const std::string &type, const node_t &child)
Definition: type-ast.hh:307
genset(const std::string &letter_type, const std::string &gens)
Definition: type-ast.hh:151
std::vector< std::shared_ptr< ast_node > > value_t
Definition: type-ast.hh:89
context(std::shared_ptr< ast_node > ls, std::shared_ptr< ast_node > ws)
Definition: type-ast.hh:37
Definition: a-star.hh:8
const nodes_t & get_content() const
Definition: type-ast.hh:322
tupleset(const value_t &sets)
Definition: type-ast.hh:63
static identities ids(const driver &d)
Get the identities of the driver.
Definition: parse.cc:89
automaton(const std::string &type, const nodes_t &children)
Definition: type-ast.hh:312
An expressionset can implement several different sets of identities on expressions.
Definition: identities.hh:20
const std::shared_ptr< const ast_node > gs_
Definition: type-ast.hh:193
const std::shared_ptr< context > get_context() const
Definition: type-ast.hh:227
std::shared_ptr< const ast_node > genset() const
The generator set.
Definition: type-ast.hh:184
std::shared_ptr< ast_node > ls_
Definition: type-ast.hh:130
expressionset(std::shared_ptr< context > ctx, rat::identities ids)
Definition: type-ast.hh:221
std::shared_ptr< expressionset > rs_
Definition: type-ast.hh:262
STL namespace.
const std::string & get_type() const
Definition: type-ast.hh:291
const std::shared_ptr< ast_node > & get_content() const
Definition: type-ast.hh:347
virtual bool has_one() const
Definition: type-ast.hh:31
std::shared_ptr< const ast_node > genset() const
The generator set.
Definition: type-ast.hh:206