Re: how to debug yacc file using gdb (Fergus Henderson)
Wed, 4 Jan 1995 02:07:24 GMT

          From comp.compilers

Related articles
how to debug yacc file using gdb (1994-12-31)
Re: how to debug yacc file using gdb (1995-01-04)
Re: how to debug yacc file using gdb (1995-01-06)
| List of all articles for this month |

Newsgroups: comp.compilers
From: (Fergus Henderson)
Keywords: yacc, debug
Organization: Computer Science, University of Melbourne, Australia
References: 94-12-152
Date: Wed, 4 Jan 1995 02:07:24 GMT (Lin Wei) writes:

>I am using lex & yacc to build a compiler for a mini-pascal with parallel
>extension. I found yacc a nice tool, however it was clumsy to debug
> using gdb. As you know, without -l option, I can debug my parser.y
>using gdb. But in this way, it seems impossible to print/display yacc's
>attribute variables like $$ and $1 because they are considered as history
>variables by gdb. I have tried \$\$ and something like that, but I
>failed. Do you have any idea that I can debug .y file in gdb and also I
>can view $$'s value.

With the yacc implementation we have here, `$$' gets translated into
`yyval' and `$n' gets translated into `yypvt[n-m]' where m is the
number of symbols on the RHS of the rule.
So if you have a rule

expr : expr binop expr { ... }

then you can use the following gdb commands:

print yyval # print $$
print yypvt[-2] # print $1
print yypvt[-1] # print $2
print yypvt[0] # print $3

Note that `yypvt' is a local variable of yyparse(), so you may need
to use gdb's `up' command to move into the scope of yyparse() before
you can print it's values.

Different yacc implementations might use different variable names -
have a look at the part of the file produced by yacc which
contains the actions, and you be able to see how `$$' and `$n' get
translated for your particular yacc implementation.

Fergus Henderson -

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.