23 :
public ExpSet::const_visitor
34 using super_t =
typename expressionset_t::const_visitor;
37 "thompson: requires nullable labels");
40 constexpr
static const char* me() {
return "thompson"; }
49 : thompson_visitor(rs.
context(), rs)
58 res_->set_initial(initial_);
59 res_->set_final(final_);
60 return std::move(res_);
62 catch (
const std::runtime_error& e)
65 " while computing thompson automaton of: ",
79 void visit(const tuple_t&,
std::true_type)
override
81 raise(me(),
": tuple is not supported");
86 initial_ = res_->new_state();
87 final_ = res_->new_state();
92 initial_ = res_->new_state();
93 final_ = res_->new_state();
94 res_->new_transition(initial_, final_, epsilon_);
99 initial_ = res_->new_state();
100 final_ = res_->new_state();
103 res_->new_transition(initial_, final_,
104 res_->labelset()->conv(*rs_.labelset(),
110 state_t initial = res_->new_state();
111 state_t final = res_->new_state();
112 for (
const auto& c: e)
115 res_->new_transition(initial, initial_, epsilon_);
116 res_->new_transition(final_,
final, epsilon_);
124 e.head()->accept(*
this);
128 for (
const auto& c: e.tail())
132 res_->new_transition(
final, initial_, epsilon_);
139 e.sub()->accept(*
this);
140 state_t initial = res_->new_state();
141 state_t final = res_->new_state();
142 res_->new_transition(initial, initial_, epsilon_);
143 res_->new_transition(final_,
final, epsilon_);
144 res_->new_transition(final_, initial_, epsilon_);
145 res_->new_transition(initial,
final, epsilon_);
152 e.sub()->accept(*
this);
155 for (
auto t:
out(res_, initial_))
156 res_->set_weight(t, ws_.mul(w, res_->weight_of(t)));
161 e.sub()->accept(*
this);
164 for (
auto t:
in(res_, final_))
165 res_->set_weight(t, ws_.mul(res_->weight_of(t), w));
172 using label_t = label_t_of<automaton_t>;
173 const label_t epsilon_ = res_->labelset()->one();
174 state_t initial_ = automaton_t::element_type::null_state();
175 state_t final_ = automaton_t::element_type::null_state();
183 template <Automaton Aut,
typename ExpSet>
186 const ExpSet&
rs,
const typename ExpSet::value_t&
r)
196 template <Automaton Aut,
typename ExpSet>
213 template <
typename ExpSet>
219 using expressionset_t = ExpSet;
220 const auto& e = exp->
as<expressionset_t>();
223 using ctx_t = decltype(ctx);
225 return ::vcsn::thompson<automaton_t>(
ctx, e.valueset(), e.value());
weightset_t_of< expressionset_t > weightset_t
automaton thompson(const expression &exp)
Bridge.
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
state_t_of< automaton_t > state_t
#define VCSN_RAT_UNSUPPORTED(Type)
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
SharedPtr make_shared_ptr(Args &&...args)
Same as std::make_shared, but parameterized by the shared_ptr type, not the (pointed to) element_type...
static dyn::context ctx(const driver &d)
Get the context of the driver.
auto(const std::vector< automaton > &as) -> automaton tuple_t
nullableset_context_t< context< LabelSet, WeightSet > > make_nullableset_context(const context< LabelSet, WeightSet > &ctx)
The nullableset context of a context.
Provide a variadic mul on top of a binary mul(), and one().
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
std::string to_string(identities i)
Wrapper around operator<<.
typename expressionset_t::const_visitor super_t
Build a Thompson automaton from an expression.
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
context_t_of< automaton_t > context_t
#define VCSN_RAT_VISIT(Type, Val)
std::shared_ptr< detail::mutable_automaton_impl< Context >> mutable_automaton
weight_t_of< expressionset_t > weight_t
auto in(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions arriving to state s.
Aut thompson(const context_t_of< Aut > &ctx, const ExpSet &rs, const typename ExpSet::value_t &r)
Build a Thompson automaton from an expression.
auto & as()
Extract wrapped typed automaton.
value_impl< detail::expression_tag > expression
typename expressionset_t::value_t expression_t