boostorg / parser

A C++ parser combinator library.
Boost Software License 1.0
87 stars 12 forks source link

"in recursion attribute nullification" design flawed. #186

Closed cppljevans closed 3 weeks ago

cppljevans commented 2 months ago

This code causes a nested call to a rule to return nope instead of attr_type, as acknowledge by the comment here.

The justification for this is given here which justifies this "in recursion attribute nullification" design with:

Recursive rules work differently from other parsers in one way: when re-entering the rule recursively, only the attribute variable (_attr(ctx) in your semantic actions) is unique to that instance of the rule. All the other state of the uppermost instance of that rule is shared. This includes the value of the rule (_val(ctx)), and the locals and parameters to the rule. In other words, _val(ctx) returns a reference to the same object in every instance of a recursive rule. This is because each instance of the rule needs a place to put the attribute it generates from its parse. However, we only want a single return value for the uppermost rule; if each instance had a separate value in _val(ctx), then it would be impossible to build up the result of a recursive rule step by step during in the evaluation of the recursive instantiations.

which is false. In particular the claim:

it would be impossible to build up the result of a recursive rule step by step during in the evaluation of the recursive instantiations.

is false because the value of the uppermost rule depends on the value of the lowermost rule. Discarding the value of the lowermost rule makes no sense to me.

Furthermore, I actually have a test case of arithmetic expressions which shows this "in recursion attribute nullification" design is unneeded. I'll be happy to upload this if you show any interest in examining the issue.

cppljevans commented 3 weeks ago

It is not completed, unless your definition of completed is you no longer wish to pursue the issue despite my sincere effort to helpfully highlight the issue.