How can I know the value of a variable in bison while debugging with GDB?

Viewed 1305

I'm trying to write a small compiler which can parse some commands I type.

The command I try to parse is:

create class something = create class do_something ; 

My code would be something like this:

grammar : my_grammar
        {
            list<Class1 *> *obj = new list<Class1 *>;
            obj->push_back($1);
        }

my_grammar : my_definition SEMICOLON
           {
               report("something detected!");
               $$ = $1;
            }

my_definition : CREATE CLASS class_name EQU class_expression
               {
                   $5->setClassName(*$3);
                   $$ = $5;
                }

class_expression : CREATE CLASS operand_name
                 {
                     $$ = new OperandClass();
                     $$->setOperationType("createClass");
                     $$->setOperandName(*$3);
                  }

However, when I try to call the parser somewhere else, I can't get the Class I have defined before.

I guess there must be something wrong with the parser and have done some debugging with GDB. But I just can't step in the function push_back(), neither can I print the information of obj correctly.

So, I am wondering if there is a way that I can get the value of $$ or $1 while using GDB. Simply type in p $$ would print something else.

2 Answers
Related