17 #ifndef AWALI_EXP_PARSER_HH
18 #define AWALI_EXP_PARSER_HH
23 template<
typename RatExpSet>
32 #include <awali/common/parse_exception.cc>
47 namespace awali {
namespace sttc {
51 template<
typename RatExpSet>
56 using ratexp_t =
typename ratexpset_t::value_t;
60 :
p_(s.length()), rs_(rs), s_(s), strict_(strict_alphabet)
64 : rs_(rs), s_(s),
p_(p), strict_(strict_alphabet)
95 if(s_[
p_-1]!=
'(' && s_[
p_-1]!=
'+') {
117 return ratexp_t(rs_.add(e,rs_.one()));
129 while(s_[
p_-1]>=
'0' && s_[
p_-1]<=
'9') {
130 b+=h*(s_[
p_-1]-
'0'); h*=10;
139 if(s_[
p_-1]!=
',' ||
p_==1)
144 while(s_[
p_-1]>=
'0' && s_[
p_-1]<=
'9') {
145 a+=h*(s_[
p_-1]-
'0'); h*=10;
160 for(
int i=0; i<a; ++i)
163 return ratexp_t(rs_.mul(p,rs_.star(e)));
166 for(
int i=a; i<
b; ++i) {
182 auto w = ws_.parse(s_,
p_);
184 if(
p_==0 || s_[
p_-1]!=
'<')
199 auto w = ws_.parse(s_,
p_);
201 if(
p_==0 || s_[
p_-1]!=
'<')
212 if(
p_>1 && s_[
p_-1]==
'e' && s_[
p_-2]==
'\\') {
217 if(
p_>1 && s_[
p_-1]==
'z' && s_[
p_-2]==
'\\') {
238 auto l = ls_.parse(s_,
p_, strict_);
247 std::set<typename labelset_t::value_t> letter_list;
248 while (
p_>0 && s_[
p_-1]!=
'[') {
249 if(strict_ &&
p_>1 && s_[
p_-1]==
'^' && s_[
p_-2]==
'['){
250 std::set<typename labelset_t::value_t> tmp;
251 auto& alpha=ls_.genset();
252 auto it=alpha.begin();
253 auto ite=alpha.end();
254 for(
auto l : letter_list) {
267 auto l = ls_.parse(s_,
p_, strict_);
272 auto k = ls_.parse(s_,
p_, strict_);
274 for(
auto i=l; i>=k; i--) {
275 std::ostringstream os;
277 const std::string& s=os.str();
279 ls_.parse(s,
q, strict_);
280 letter_list.emplace(i);
284 letter_list.emplace(l);
292 for(
auto l : letter_list) {
298 res = rs_.add(res,
ratexp_t(rs_.atom(l)));
303 template<
typename... T>
305 auto l = ls_.parse(s_,
p_, strict_);
310 template<
typename F,
typename S>
312 auto l = ls_.parse(s_,
p_, strict_);
319 auto l = ls_.parse(s_,
p_, strict_);
325 while(
p_>0 && s_[
p_-1]==
' ')
336 const std::string& s_;
422 template <
typename RatExpSet>
424 typename RatExpSet::ratexp_t
426 const std::string& s,
bool check_complete=
true,
bool strict_alphabet=
true)
429 auto exp=parser.parseE();
430 if(check_complete && parser.getPos()>0)
The Boolean semring.
Definition: b.hh:38
Implementation of labels are letters.
Definition: letterset.hh:43
helper for manipulations of pair letters
Definition: pair.hh:35
The semiring of rational numbers.
Definition: q.hh:41
objets that represent the alphabets of letters as char
Definition: setalpha.hh:44
A ValueSet which is a Cartesian product of ValueSets.
Definition: tupleset.hh:80
Implementation of labels are words.
Definition: wordset.hh:35
variadic_mul_mixin< rat::ratexpset_impl< Context > > ratexpset
Definition: fwd.hh:182
RatExpSet::ratexp_t parse_exp(const RatExpSet &ratexpset, const std::string &s, bool check_complete=true, bool strict_alphabet=true)
parser of rational expressions
Definition: exp_parser.hh:425
typename internal::context_t_of_impl< internal::base_t< ValueSet > >::type context_t_of
Helper to retrieve the type of the context of a value set.
Definition: traits.hh:66
typename internal::labelset_t_of_impl< internal::base_t< ValueSet > >::type labelset_t_of
Helper to retrieve the type of the labelset of a value set.
Definition: traits.hh:76
typename internal::weightset_t_of_impl< internal::base_t< ValueSet > >::type weightset_t_of
Helper to retrieve the type of the weightset of a value set.
Definition: traits.hh:86
Main namespace of Awali.
Definition: ato.hh:22
Exceptions thrown during parsing.
Definition: parse_exception.hh:26
Definition: exp_parser.hh:52
size_t getPos()
Definition: exp_parser.hh:329
ratexp_t parseA()
Definition: exp_parser.hh:211
ratexp_t parseSqrBrkt(const tupleset< T... > &)
Definition: exp_parser.hh:304
context_t_of< ratexpset_t > context_t
Definition: exp_parser.hh:54
ratexp_t parseP()
Definition: exp_parser.hh:83
exp_parser(const ratexpset_t &rs, const std::string &s, size_t &p, bool strict_alphabet)
Definition: exp_parser.hh:63
exp_parser(const ratexpset_t &rs, const std::string &s, bool strict_alphabet)
Definition: exp_parser.hh:59
ratexp_t parseSqrBrkt(const T &)
Definition: exp_parser.hh:244
typename ratexpset_t::value_t ratexp_t
Definition: exp_parser.hh:56
ratexp_t parseE()
Definition: exp_parser.hh:67
RatExpSet ratexpset_t
Definition: exp_parser.hh:53
void ignore()
Definition: exp_parser.hh:324
ratexp_t parseS()
Definition: exp_parser.hh:102
ratexp_t parseL()
Definition: exp_parser.hh:175
size_t p_
Definition: exp_parser.hh:333
ratexp_t parseSqrBrkt(const letterset< set_alphabet< pair_letters< F, S >>> &)
Definition: exp_parser.hh:311
ratexp_t parseSqrBrkt(const wordset< T > &)
Definition: exp_parser.hh:318
weightset_t_of< ratexpset_t > weightset_t
Definition: exp_parser.hh:57
labelset_t_of< context_t > labelset_t
Definition: exp_parser.hh:55
ratexp_t parseR()
Definition: exp_parser.hh:193
Provide a variadic mul on top of a binary mul(), and one().
Definition: weightset.hh:38