17 #ifndef AWALI_EXP_PARSER_HH
18 #define AWALI_EXP_PARSER_HH
23 template<
typename RatExpSet>
32 #include <awali/common/parse_exception.cc>
54 namespace awali {
namespace sttc {
58 template<
typename RatExpSet>
63 using ratexp_t =
typename ratexpset_t::value_t;
67 :
p_(s.length()), rs_(rs), s_(s), strict_(strict_alphabet)
71 : rs_(rs), s_(s),
p_(p), strict_(strict_alphabet)
102 if(s_[
p_-1]!=
'(' && s_[
p_-1]!=
'+') {
124 return ratexp_t(rs_.add(e,rs_.one()));
136 while(s_[
p_-1]>=
'0' && s_[
p_-1]<=
'9') {
137 b+=h*(s_[
p_-1]-
'0'); h*=10;
146 if(s_[
p_-1]!=
',' ||
p_==1)
151 while(s_[
p_-1]>=
'0' && s_[
p_-1]<=
'9') {
152 a+=h*(s_[
p_-1]-
'0'); h*=10;
167 for(
int i=0; i<a; ++i)
170 return ratexp_t(rs_.mul(p,rs_.star(e)));
173 for(
int i=a; i<
b; ++i) {
189 auto w = ws_.parse(s_,
p_);
191 if(
p_==0 || s_[
p_-1]!=
'<')
206 auto w = ws_.parse(s_,
p_);
208 if(
p_==0 || s_[
p_-1]!=
'<')
212 if(s_[
p_-1]==
'*' || s_[
p_-1]==
'?' || s_[
p_-1]==
'}') {
225 if(
p_>1 && s_[
p_-1]==
'e' && s_[
p_-2]==
'\\') {
230 if(
p_>1 && s_[
p_-1]==
'z' && s_[
p_-2]==
'\\') {
251 auto l = ls_.parse(s_,
p_, strict_);
260 std::set<typename labelset_t::value_t> letter_list;
261 while (
p_>0 && s_[
p_-1]!=
'[') {
262 if(strict_ &&
p_>1 && s_[
p_-1]==
'^' && s_[
p_-2]==
'['){
263 std::set<typename labelset_t::value_t> tmp;
264 auto const& alpha=ls_.genset();
265 auto it=alpha.begin();
266 auto ite=alpha.end();
267 for(
auto l : letter_list) {
280 auto l = ls_.parse(s_,
p_, strict_);
285 auto k = ls_.parse(s_,
p_, strict_);
287 for(
auto i=l; i>=k; --i) {
288 std::ostringstream os;
290 const std::string& s=os.str();
292 ls_.parse(s,
q, strict_);
293 letter_list.emplace(i);
297 letter_list.emplace(l);
305 for(
auto l : letter_list) {
311 res = rs_.add(res,
ratexp_t(rs_.atom(l)));
316 template<
typename... T>
318 auto l = ls_.parse(s_,
p_, strict_);
323 template<
typename F,
typename S>
325 auto l = ls_.parse(s_,
p_, strict_);
332 auto l = ls_.parse(s_,
p_, strict_);
338 while(
p_>0 && s_[
p_-1]==
' ')
349 const std::string& s_;
435 template <
typename RatExpSet>
437 typename RatExpSet::ratexp_t
439 const std::string& s,
bool check_complete=
true,
bool strict_alphabet=
true)
442 auto exp=parser.parseE();
443 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:42
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:438
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:59
size_t getPos()
Definition: exp_parser.hh:342
ratexp_t parseA()
Definition: exp_parser.hh:224
ratexp_t parseSqrBrkt(const tupleset< T... > &)
Definition: exp_parser.hh:317
context_t_of< ratexpset_t > context_t
Definition: exp_parser.hh:61
ratexp_t parseP()
Definition: exp_parser.hh:90
exp_parser(const ratexpset_t &rs, const std::string &s, size_t &p, bool strict_alphabet)
Definition: exp_parser.hh:70
exp_parser(const ratexpset_t &rs, const std::string &s, bool strict_alphabet)
Definition: exp_parser.hh:66
ratexp_t parseSqrBrkt(const T &)
Definition: exp_parser.hh:257
typename ratexpset_t::value_t ratexp_t
Definition: exp_parser.hh:63
ratexp_t parseE()
Definition: exp_parser.hh:74
RatExpSet ratexpset_t
Definition: exp_parser.hh:60
void ignore()
Definition: exp_parser.hh:337
ratexp_t parseS()
Definition: exp_parser.hh:109
ratexp_t parseL()
Definition: exp_parser.hh:182
size_t p_
Definition: exp_parser.hh:346
ratexp_t parseSqrBrkt(const letterset< set_alphabet< pair_letters< F, S >>> &)
Definition: exp_parser.hh:324
ratexp_t parseSqrBrkt(const wordset< T > &)
Definition: exp_parser.hh:331
weightset_t_of< ratexpset_t > weightset_t
Definition: exp_parser.hh:64
labelset_t_of< context_t > labelset_t
Definition: exp_parser.hh:62
ratexp_t parseR()
Definition: exp_parser.hh:200
Provide a variadic mul on top of a binary mul(), and one().
Definition: weightset.hh:38