When is %destructor invoked in BISON?

旧巷老猫 提交于 2019-12-01 05:54:00

From the Bison Manual:

Discarded symbols are the following:

  • stacked symbols popped during the first phase of error recovery,
  • incoming terminals during the second phase of error recovery,
  • the current lookahead and the entire stack (except the current right-hand side symbols) when the parser returns immediately, and
  • the start symbol, when the parser succeeds.

So if you don't hit an error, the %destructor will be called on the stack if you return immediately (call YYABORT or YYACCEPT), or it will call it on start symbol if parsing succeeds.

I figured out, that I should free() it after I perform the action, so for example

...
| String CONCAT String { $$ = concat($1,$3); free($1); free($3); }
...

That did the trick for me.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!