21 template <
typename Aut,
24 :
public ExpSet::const_visitor
34 using super_t =
typename expressionset_t::const_visitor;
37 "zpc: requires nullable labels");
40 constexpr
static const char*
me() {
return "zpc"; }
62 for (
auto t:
res_->all_in(
res_->post()))
65 return std::move(
res_);
76 virtual
void visit(const tuple_t&,
std::true_type)
override
78 raise(
me(),
": tuple is not supported");
102 res_->labelset()->conv(*
rs_.labelset(),
126 e.sub()->accept(*
this);
145 e.sub()->accept(*
this);
149 res_->set_weight(t,
ws_.mul(w,
res_->weight_of(t)));
154 e.sub()->accept(*
this);
164 std::vector<state_t> finals_;
170 finals_.push_back(
final_);
178 for (
auto s: finals_)
190 std::vector<state_t> state_stack;
193 for (
auto i = 0; i < e.size() - 1; ++i)
194 state_stack.push_back(
res_->new_state());
196 e.head()->accept(*
this);
207 state_t final = automaton_t::element_type::null_state();
209 initial = state_stack.back();
210 state_stack.pop_back();
213 for (
auto t: e.tail())
217 final =
res_->new_state();
220 auto cst_e =
res_->get_final_weight(initial_e);
224 res_->unset_final(initial_e);
228 res_->set_final(initial,
ws_.mul(cst_e, cst_f));
235 if (!state_stack.empty())
237 initial = state_stack.back();
238 state_stack.pop_back();
250 e.head()->accept(*
this);
259 for (
auto c: e.tail())
279 e.head()->accept(*
this);
288 for (
auto t: e.tail())
293 auto cst_e =
res_->get_final_weight(initial_e);
297 res_->unset_final(initial_e);
301 res_->set_final(initial,
ws_.mul(cst_e, cst_f));
332 template <
typename Aut,
typename ExpSet>
337 const typename ExpSet::value_t&
r,
338 const std::string& algo =
"auto")
340 require(algo ==
"auto" || algo ==
"regular" || algo ==
"compact",
341 "zpc: expects \"auto\", \"regular\", \"compact\" or nothing");
355 template <
typename ExpSet,
typename String>
362 using expressionset_t = ExpSet;
363 const auto& e = exp->as<expressionset_t>();
366 using ctx_t = decltype(ctx);
VCSN_RAT_VISIT(rweight, e)
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
zpc_visitor(const expressionset_t &rs, bool compact)
nullableset_context_t< context< LabelSet, WeightSet > > make_nullableset_context(const context< LabelSet, WeightSet > &ctx)
The nullableset context of a context.
typename expressionset_t::const_visitor super_t
weight_t_of< expressionset_t > weight_t
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
context_t_of< automaton_t > context_t
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
typename super_t::tuple_t tuple_t
automaton_t operator()(const typename expressionset_t::value_t &v)
SharedPtr make_shared_ptr(Args &&...args)
Same as std::make_shared, but parameterized by the shared_ptr type, not the (pointed to) element_type...
const expressionset_t & rs_
virtual void visit(const tuple_t &, std::true_type) override
automaton make_automaton(const Aut &aut)
Build a dyn::automaton.
static dyn::context ctx(const driver &d)
Get the context of the driver.
const bool compact_
Whether to build the "compact" version of the ZPC automaton.
Provide a variadic mul on top of a binary mul(), and one().
Aut zpc(const context_t_of< Aut > &ctx, const ExpSet &rs, const typename ExpSet::value_t &r, const std::string &algo="auto")
Build a ZPC automaton from an expression.
static constexpr const char * me()
Name of this algorithm, for error messages.
std::shared_ptr< detail::automaton_base > automaton
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
void require(bool b, Args &&...args)
If b is not verified, raise an error with args as message.
automaton zpc(const expression &exp, const std::string &algo)
Bridge.
void prod_regular(const prod_t &e)
Build a ZPC automaton from an expression.
label_t_of< automaton_t > label_t
state_t_of< automaton_t > state_t
zpc_visitor(const context_t &ctx, const expressionset_t &rs, bool compact)
Build an automaton of context ctx.
An inner node implementing a weight.
std::shared_ptr< detail::expression_base > expression
VCSN_RAT_VISIT(lweight, e)
void sum_regular(const sum_t &e)
weightset_t_of< expressionset_t > weightset_t
void prod_compact(const prod_t &e)
std::shared_ptr< detail::mutable_automaton_impl< Context >> mutable_automaton
void sum_compact(const sum_t &e)
An inner node with multiple children.
#define VCSN_RAT_UNSUPPORTED(Type)
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of