全局变量是 return 在 bison 中构建 AST 的唯一方法吗?

Is a global variable the only way to return the built AST in bison?

对于 return 完全构建的 AST,我被告知我应该使用一个全局变量来存储它:

%{

AST::Root* root;

%}

%start program

%%

program:
    ...            { $$ = root = new AST::Root(...) }
    ...
    ;

但这是唯一的方法吗?或者有没有更好的方法,也许是直接从 yyparse() 到 return AST 的方法?

您可以使用 %parse-paramyyparse() 添加额外的参数。有descrition