Re: YACC debugger wanted

Scott Stanchfield <scotts@metaware.com>
20 Dec 1996 17:14:27 -0500

          From comp.compilers

Related articles
YACC debugger wanted guenter@student.uni-kl.de (Marvin) (1996-12-18)
Re: YACC debugger wanted scotts@metaware.com (Scott Stanchfield) (1996-12-20)
Re: YACC debugger wanted joerg@tc.pci.uni-heidelberg.de (1996-12-20)
| List of all articles for this month |
From: Scott Stanchfield <scotts@metaware.com>
Newsgroups: comp.compilers
Date: 20 Dec 1996 17:14:27 -0500
Organization: MetaWare Incorporated
References: 96-12-131
Keywords: parse, yacc, debug

I created some simple awk scripts to help debug yacc, but I couldn't
keep them when I left McCabe...


The idea I used was to help set breakpoints at rule reductions:
    -- edit the ytab.c file (using awk):
              -- add a routine called "rule_stop_here" that doesn't
                    have any code in it


              -- add a global
                          char *rule_stop_pattern=(char *)0;


              -- add a function
                          stop_in_rule(char *pattern)
                    which will set rule_stop_pattern to pattern.
                    (Make sure you malloc & strcpy the pattern, freeing an
                    old value first...)


              -- at each action code section (your action code is put into a
                    large switch statement -- look for the cases) add the
                    following code (this is pseudo code...)
                          if current rule name matches rule_stop_pattern
                                call rule_stop_here
                          #line ...
                    Notes:
                          = the current rule name can be determined from (I think)
                              yyreds[], which is defined if you define YYDEBUG when
                              compiling and -t when yaccing
                          = there should be a #line directive at the start of
                              the action code "case;" insert your "if" right before
                              it or your line numbers get off...


    -- go into a debugger (I used gdb with DDD as a GUI)
            -- set a breakpoint on entry to rule_stop_here
            -- set an action at the breakpoint that says "finish" (continue
                  until out of the routine.)
            -- call rule_stop_pattern("ruleA")
                  (where ruleA is the rule you want to stop on.)
            -- run your test...


If I remembered all the stuff you need to do, this _should_ stop you on
each piece of action code for the rule in question. This can help
quite a bit to find problems.


A possible extension might be to change the "if" to
    if rule name matches pattern OR yylineno == line_to_stop_on
and define another routine to set line_to_stop_on.


I hope this is clear enough. It sped up my debugging significantly
(I didn't need to blindly step through the table lookups/state machine
stuff.)


Hope this helps! Happy Holidays!
Scott




Marvin wrote:
>
> Greetings. Is there something like a run-time debugger for YACC
> which allows somebody to check if a set of YACC rules and a
> text in this language match by making some top-down parsing?


--
Scott Stanchfield
MetaWare Incorporated
Santa Cruz, CA


--


Post a followup to this message

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