Check Bison $$ Variable Using GDB

If I set a breakpoint in the Bison.y file, is there a way to check the contents of the $$ pseudo variable at that breakpoint?

+3
source share
3 answers

$$ is the top of the semantic value stack. This can be a little difficult to interpret. If you really need to, the stack pointer can be called yyssp, and the stack can be called yyvsa, so something like yyvsa [yyssp] can give you what you want, depending on the version of bison you are using. Look at the .tab.c code that was generated.

+6
source

Bison yyparse(), .

, - y.tab.c, *++yyvsp = yylval . YYPOPSTACK(), .

+3

I redefined the type yylvalwith %union:

%union {
  int int_val;
  double double_val;
}

And I get either yyval.int_val, or yyval.double_valdepending on the type $$.

But as Richard Pennington said, the best way is to look at the generated code .tab.c.

0
source

Source: https://habr.com/ru/post/1722281/


All Articles