In some languages a new scope can be opened and closed again. In C++ this would be the curly brace. Assuming one creates a new scope on encountering an opening curly brace and closes it on encountering the matching closing curly brace. What would happen in case of a parse error before the closing curly brace is encountered? How could one make certain, that the scope opened by the opening curly brace is properly trashed?
scope objects in boost::spirit and RAII
22 views Asked by Frank Puck At
2
There are 2 answers
0
On
If parse error occurs before the matching closing brace, it will be taken as invalid scope. The compiler in this case will report it as parse error:
You should check for the semicolons in your code either there is a missing one.
You can restructure your code to avoid parse error.
There are some online tools like onlinegdb that can resolve these issues to some extent by beautifying your code.
How else would it work? Deterministic destruction at object lifetime is a property of the language. So, unless you're willing to assume Qi leaks memory by design, you're good to go.
Of course, you can forcibly create a memory leak if you insist, e.g.
eps[px::new_<int>(42)], but you're able to do the same without Spirit (just use the memory leak operator,operator* new).Now this comes into play especially/only when you want to use dynamic polymorphism in your AST types:
As I've said before:
Make that 136 :)
There was this time where I fixed the leaks in a grammar that uses pointer attributes: Building a Custom Expression Tree in Spirit:Qi (Without Utree or Boost::Variant)