23 :
public ExpSet::const_visitor
33 using super_t =
typename expressionset_t::const_visitor;
36 "thompson: requires nullable labels");
39 constexpr
static const char* me() {
return "thompson"; }
48 : thompson_visitor(rs.
context(), rs)
52 operator()(
const typename expressionset_t::value_t&
v)
55 res_->set_initial(initial_);
56 res_->set_final(final_);
57 return std::move(res_);
67 using tuple_t = typename
super_t::tuple_t;
68 virtual
void visit(const tuple_t&,
std::true_type)
override
70 raise(me(),
": tuple is not supported");
75 initial_ = res_->new_state();
76 final_ = res_->new_state();
81 initial_ = res_->new_state();
82 final_ = res_->new_state();
83 res_->new_transition(initial_, final_, epsilon_);
88 initial_ = res_->new_state();
89 final_ = res_->new_state();
92 res_->new_transition(initial_, final_,
93 res_->labelset()->conv(*rs_.labelset(),
99 state_t initial = res_->new_state();
100 state_t final = res_->new_state();
104 res_->new_transition(initial, initial_, epsilon_);
105 res_->new_transition(final_,
final, epsilon_);
113 e.head()->accept(*
this);
117 for (
auto c: e.tail())
121 res_->new_transition(
final, initial_, epsilon_);
128 e.sub()->accept(*
this);
129 state_t initial = res_->new_state();
130 state_t final = res_->new_state();
131 res_->new_transition(initial, initial_, epsilon_);
132 res_->new_transition(final_,
final, epsilon_);
133 res_->new_transition(final_, initial_, epsilon_);
134 res_->new_transition(initial,
final, epsilon_);
141 e.sub()->accept(*
this);
144 for (
auto t:
out(res_, initial_))
145 res_->set_weight(t, ws_.mul(w, res_->weight_of(t)));
150 e.sub()->accept(*
this);
153 for (
auto t:
in(res_, final_))
154 res_->set_weight(t, ws_.mul(res_->weight_of(t), w));
161 using label_t = label_t_of<automaton_t>;
162 const label_t epsilon_ = res_->labelset()->one();
163 state_t initial_ = automaton_t::element_type::null_state();
164 state_t final_ = automaton_t::element_type::null_state();
173 template <Automaton Aut,
typename ExpSet>
177 const ExpSet&
rs,
const typename ExpSet::value_t&
r)
187 template <Automaton Aut,
typename ExpSet>
205 template <
typename ExpSet>
212 using expressionset_t = ExpSet;
213 const auto& e = exp->as<expressionset_t>();
216 using ctx_t = decltype(ctx);
auto in(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions arriving to state s.
state_t_of< automaton_t > state_t
SharedPtr make_shared_ptr(Args &&...args)
Same as std::make_shared, but parameterized by the shared_ptr type, not the (pointed to) element_type...
Aut thompson(const context_t_of< Aut > &ctx, const ExpSet &rs, const typename ExpSet::value_t &r)
Build a Thompson automaton from an expression.
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
static dyn::context ctx(const driver &d)
Get the context of the driver.
automaton make_automaton(const Aut &aut)
Build a dyn::automaton.
context_t_of< automaton_t > context_t
#define VCSN_RAT_VISIT(Type, Val)
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
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.
Provide a variadic mul on top of a binary mul(), and one().
std::shared_ptr< detail::mutable_automaton_impl< Context >> mutable_automaton
nullableset_context_t< context< LabelSet, WeightSet > > make_nullableset_context(const context< LabelSet, WeightSet > &ctx)
The nullableset context of a context.
weight_t_of< expressionset_t > weight_t
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
typename expressionset_t::const_visitor super_t
std::shared_ptr< detail::expression_base > expression
Build a Thompson automaton from an expression.
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of
#define VCSN_RAT_UNSUPPORTED(Type)
std::shared_ptr< detail::automaton_base > automaton