last day (20 days later) » 

3:23 PM
Apparently not too lazy to create a chat room after all.
To the edit: is it "special" if it is the "trailing limb" only? Surely you can detect that from the ast during evaluation? — sehe 19 mins ago
yes i can detect this in the AST .. but i would prefer to handle this inside boost and create a different AST in this case with this SPECIAL_DOT node — Markus 16 mins ago
Just transform the AST node. It is simple: the semantic distinction doesn't exist at the grammar level. In other words: "doing it in boost" is putting the cart in front of the horse: you need to parse the grammar, and interpret the AST.
Here's a sketch: http://coliru.stacked-crooked.com/a/3a3ffdfb09569a22
Prints
    "a" -> a
    "a()" -> CALL(a)
    "a.b" -> SPECIAL(DOT(a, b))
    "a.b()" -> CALL(DOT(a, b))
    "a.b().c" -> SPECIAL(DOT(CALL(DOT(a, b)), c))
    "a().b.c()" -> CALL(DOT(DOT(CALL(a), b), c))
    "a().b" -> SPECIAL(DOT(CALL(a), b))
    "a(q,r,s).b" -> SPECIAL(DOT(CALL(a, q, r, s), b))
To ACTUALLY get closer to the semantics suggested in the original question you'd even markt the lone "a" special: coliru.stacked-crooked.com/a/bb4a3d6eef994aba
    "a" -> SPECIAL(a)
    "a()" -> CALL(a)
    "a.b" -> SPECIAL(DOT(a, b))
    "a.b()" -> CALL(DOT(a, b))
    "a.b().c" -> SPECIAL(DOT(CALL(DOT(a, b)), c))
    "a().b.c()" -> CALL(DOT(DOT(CALL(a), b), c))
    "a().b" -> SPECIAL(DOT(CALL(a), b))
    "a(q,r,s).b" -> SPECIAL(DOT(CALL(a, q, r, s), b))
What are you actually trying to achieve? Are you trying to keep track of when an expression is still an lvalue? And (perhaps falsely) assuming that a function will not return an lvalue?
In that case this part of the answer was right on the mark:
If you want to assume that a function will not return an lvalue, that's fine of course, it may be correct for your domain. But really that still doesn't mean you should conflate value-category tracking with parsing. It's much more natural to do this during interpretation.
This is what I imagine correct Lvalue classification to be in such a situation:
struct LvalueDetect {
    template <typename T>
        bool operator()(T const& v) const { return detect(v); }
  private:
    bool detect(Ast::expr const& v) const { return boost::apply_visitor(*this, v); }
    bool detect(Ast::name const&) const { return true; }
    bool detect(Ast::call const&) const { return false; }
    bool detect(Ast::member_access const& ma) const { return detect(ma.obj); }
};

bool is_lvalue(Ast::expr const& ast) {
    return LvalueDetect{}(ast);
}
"a" -> a LVALUE
"a()" -> CALL(a)
"a.b" -> DOT(a, b) LVALUE
"a.b()" -> CALL(DOT(a, b))
....
(Note that member expressions would only be lvalue if their object was lvalue to being with)
 
3:46 PM
Hello
 
Hello :)
 
the issue is related to some legacy code. In the past a user may wrote a.b which internal means a.b() but The () was optional.. in the new parser I want to catch this by creating a function call node automatically when a statement like a.b is in global context ..
 
Aha.
Doesn't it depend on whether a.b is a function to begin with?
Also it's not so much transforming "DOT" into "SPECIAL_DOT" (because, as you are actually aware no dot is required. a could also be a() implicitly).
It's more like transforming name -> call { name, empty_args }
So, I'd say, forget about special dot. There is no special dot.
 
8) you are right at the end all in global space will end up as function call. The only question is how to get spirit to create the function call node on root
Instead of the dot
 
The ironic thing is, the way you specified the specialness in the comments ("<-- special") in your original question, actually implies that anything that is not a call is an implicit call. That's what I ended up expressing here:
26 mins ago, by sehe
To ACTUALLY get closer to the semantics suggested in the original question you'd even markt the lone "a" special: http://coliru.stacked-crooked.com/a/bb4a3d6eef994aba
So, really, just be happy and slap a call around your AST unless it already is one?
Ast::lvalue make_implicit_call(Ast::lvalue ast) {
    if (!boost::get<Ast::call>(&ast))
        return Ast::call { std::move(ast), {} }; // no args
    return ast;
}
If you insist, you can put that on your grammar (but why? It's not any more "in boost" that way. I'm hoping you're not having people directly call qi::phrase_parse or` x3::phrase_parse` :))
Here is the demo, and in the grammar: for kicks
Both print:
"a" -> CALL(a)
"a()" -> CALL(a)
"a.b" -> CALL(DOT(a, b))
"a.b()" -> CALL(DOT(a, b))
"a.b().c" -> CALL(DOT(CALL(DOT(a, b)), c))
"a().b.c()" -> CALL(DOT(DOT(CALL(a), b), c))
"a().b" -> CALL(DOT(CALL(a), b))
"a(q,r,s).b" -> CALL(DOT(CALL(a, q, r, s), b))
 
4:03 PM
I will check this .. give me some time 8) thank you
 
(I still prefer more natural printing: coliru.stacked-crooked.com/a/e4c13ccd6840040c )
"a" -> a()
"a()" -> a()
"a.b" -> a.b()
"a.b()" -> a.b()
"a.b().c" -> a.b().c()
"a().b.c()" -> a().b.c()
"a().b" -> a().b()
"a(q,r,s).b" -> a(q, r, s).b()
 
 
1 hour later…
5:25 PM
ok now i guess why i using the term "specal_dot" the output "a.b" -> CALL(DOT(a, b)) is not correct it should be
DOT_CALL(a,b) .. because it is a member call .. just the addional CALL on root is not the goal
a -> call(A)
a.b -> dot_call(a,b)
a.b().c() -> DOT_CALL(DOT_CALL(a,b),c)
a.b().c -> DOT_CALL(DOT_CALL(a,b),c) .. equal to the version without () at the end
DOT_CALL is something like "call member of object"
a(q,r,s).b -> DOT_CALL(CALL(a,q,r,s),b)
 
 
1 hour later…
6:51 PM
@Markus @sorry family happened between. So, now we had dinner and soon I'll be off watching a movie, but quickly:
namespace Processing {
    using namespace Ast;
    struct Transform {
        template <typename T> auto operator()(T const& v) const { return apply(v); }
      private:
        lvalue apply(lvalue const& v) const { return boost::apply_visitor(*this, v); }
        template <typename T>
        lvalue apply(T const& v) const { return v; }
        lvalue apply(call const& v) const {
            if (v.f.type() != typeid(Ast::name))
                return Ast::member_call{v};
            return v;
"a" -> a()
"a()" -> a()
"a.b" -> a.b[]
"a.b()" -> a.b[]
"a.b().c" -> a.b().c[]
"a().b.c()" -> a().b.c[]
"a().b" -> a().b[]
"a(q,r,s).b" -> a(q, r, s).b[]
(I chose [] to indicate "member call" because I'm too lazy to turn it back into the DOT_CALL printing again)
Notice that it's not a dot-call still. The dot is unrelated to the call. It's a member function though and whatever you use to evaluate it should know the difference anyways. You'll note that there is no actual difference in the AST:
    struct member_call : call {};
So, it feels like a static distinction for no gain.
    struct make_f<Ast::call> {
        template <typename... Args>
        Ast::lvalue operator()(Ast::lvalue f, Ast::params args) const {
            if (f.type() != typeid(Ast::name)) {
                return Ast::member_call { { std::move(f), std::move(args) } };
            }
            return Ast::call { std::move(f), std::move(args) };
        }
    };
Prints:
"a" -> CALL(a)
"a()" -> CALL(a)
"a.b" -> CALL(DOT(a, b))
"a.b()" -> CALL(MEMBER_CALL(DOT(a, b)))
"a.b().c" -> CALL(DOT(MEMBER_CALL(DOT(a, b)), c))
"a().b.c()" -> CALL(MEMBER_CALL(DOT(DOT(CALL(a), b), c)))
"a().b" -> CALL(DOT(CALL(a), b))
"a(q,r,s).b" -> CALL(DOT(CALL(a, q, r, s), b))
(see I even un-lazied myself). Maybe you can edit my answer to include this. I'll be back later
To be honest I think it is flawed to build it into the parser. I just realizaed that it wouldn't transform the "implicit" call correctly, because that gets added at the end.
So, better to ignore my last sample and stick with that one.
In case you argue that you still don't have the ast you need, I argue that in the case of a.b.c() the "ast" DOT_CALL(b, c) is useless. There's is no such thing as b, because it doesn't exist. It's impossible to usefully make an AST node reflecting something that doesn't exist. a.b on the other hand does exist (and can be represented by the AST member_access{a, b}
That's why call(member_access(member_access(a, b), c), {}) makes more sense than some_ast??(a, dot_call(b, c)) or something.
 
7:31 PM
room topic changed to parsers, asts, members and calls: stackoverflow.com/questions/62714352/… [abstract-syntax-tree] [boost-spirit] [c++]
In the off-chance that you were actually using Qi (you didn't say): Qi version or Alternative takesehe 5 hours ago
(you still didn't specify, by the way)
 
 
1 hour later…
8:39 PM
.. ok got it .. just review the code and maybe another idea .. i know that you don´t like actions .. but if i place the "change to caller" in the action .. this may also work. See below the part with "...change here the type ..." .. this may work because the action is only taken on the root return

auto lvalue
= rule<struct lvalue_, Ast::lvalue> {"lvalue"}
= name [ ([](auto& ctx){ _val(ctx) = _attr(ctx); }) ] >> *(
'.' >> name [ ([](auto& ctx){ _val(ctx) = Ast::member_access{ _val(ctx), _attr(ctx) }; }) ]
 
 
2 hours later…
10:39 PM
@Markus Am I to conclude that you are using X3?
@Markus On the suggestion itself, are you suggesting to make the parser stateful for this whole reason? I would not. It's not helping. It's just shifting around complexity and it's costing more in terms of maintainability that way.
Remind me, why does the semantic processing need to be conflated with the parsing?
 

  last day (20 days later) »