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]!=
'+') {
146 while(s_[
p_-1]>=
'0' && s_[
p_-1]<=
'9') {
147 b+=h*(s_[
p_-1]-
'0'); h*=10;
156 if(s_[
p_-1]!=
',' ||
p_==1)
161 while(s_[
p_-1]>=
'0' && s_[
p_-1]<=
'9') {
162 a+=h*(s_[
p_-1]-
'0'); h*=10;
177 for(
int i=0; i<a; ++i)
180 return ratexp_t(rs_.mul(p,rs_.star(e)));
183 for(
int i=a; i<
b; ++i) {
199 auto w = ws_.parse(s_,
p_);
201 if(
p_==0 || s_[
p_-1]!=
'<')
216 auto w = ws_.parse(s_,
p_);
218 if(
p_==0 || s_[
p_-1]!=
'<')
222 if(s_[
p_-1]==
'*' || s_[
p_-1]==
'?' || s_[
p_-1]==
'}') {
235 if(
p_>1 && s_[
p_-1]==
'e' && s_[
p_-2]==
'\\') {
240 if(
p_>1 && s_[
p_-1]==
'z' && s_[
p_-2]==
'\\') {
261 auto l = ls_.parse(s_,
p_, strict_);
270 std::set<typename labelset_t::value_t> letter_list;
271 while (
p_>0 && s_[
p_-1]!=
'[') {
272 if(strict_ &&
p_>1 && s_[
p_-1]==
'^' && s_[
p_-2]==
'['){
273 std::set<typename labelset_t::value_t> tmp;
274 auto const& alpha=ls_.genset();
275 auto it=alpha.begin();
276 auto ite=alpha.end();
277 for(
auto l : letter_list) {
290 auto l = ls_.parse(s_,
p_, strict_);
295 auto k = ls_.parse(s_,
p_, strict_);
297 for(
auto i=l; i>=k; --i) {
298 std::ostringstream os;
300 const std::string& s=os.str();
302 ls_.parse(s,
q, strict_);
303 letter_list.emplace(i);
307 letter_list.emplace(l);
315 for(
auto l : letter_list) {
321 res = rs_.add(res,
ratexp_t(rs_.atom(l)));
326 template<
typename... T>
328 auto l = ls_.parse(s_,
p_, strict_);
333 template<
typename F,
typename S>
335 auto l = ls_.parse(s_,
p_, strict_);
342 auto l = ls_.parse(s_,
p_, strict_);
348 while(
p_>0 && s_[
p_-1]==
' ')
359 const std::string& s_;
445 template <
typename RatExpSet>
447 typename RatExpSet::ratexp_t
449 const std::string& s,
bool check_complete=
true,
bool strict_alphabet=
true)
452 auto exp=parser.parseE();
453 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:192
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:448
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:352
ratexp_t parseA()
Definition: exp_parser.hh:234
ratexp_t parseSqrBrkt(const tupleset< T... > &)
Definition: exp_parser.hh:327
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:267
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:347
ratexp_t parseS()
Definition: exp_parser.hh:109
ratexp_t parseL()
Definition: exp_parser.hh:192
size_t p_
Definition: exp_parser.hh:356
ratexp_t parseSqrBrkt(const letterset< set_alphabet< pair_letters< F, S >>> &)
Definition: exp_parser.hh:334
ratexp_t parseSqrBrkt(const wordset< T > &)
Definition: exp_parser.hh:341
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:210
Provide a variadic mul on top of a binary mul(), and one().
Definition: weightset.hh:38