[comp.sources.d] How do you debug lex/yacc output?

wex@milano.UUCP (07/13/87)

Pardon the cross-posting, this is partly a request and partly
discussion.

I am writing a translator for changing files of type1 into files of
type2.  This involves some heavy semantic work, not simple lexical or
syntactic resuffling.

I am writing in lex and yacc.  The yacc file has 181 terminals, 191
nonterminals 399 grammar rules and 803 states, plus several hundred
lines of C code to perform the semantic action.  Naturally, anything
this big is bound to have bugs.  But dbx can't help me - it can't
operate on the output of yacc (or at least I can't figure out how to
get it to).

So what I need is either advice or another debugger.  (If you're
giving advice or other discussion, please edit the newsgroups: line.
Email also welcome.)

-- 
Alan Wexelblat
ARPA: WEX@MCC.COM
UUCP: {seismo, harvard, gatech, pyramid, &c.}!sally!im4u!milano!wex

"Oh well, a touch of grey,
 Kinda suits you anyway."

hansen@mips.UUCP (Craig Hansen) (07/14/87)

In article <4897@milano.UUCP>, wex@milano.UUCP writes:
> I am writing in lex and yacc.  The yacc file has 181 terminals, 191
> nonterminals 399 grammar rules and 803 states, plus several hundred
> lines of C code to perform the semantic action.  Naturally, anything
> this big is bound to have bugs.  But dbx can't help me - it can't
> operate on the output of yacc (or at least I can't figure out how to
> get it to).

Debuggers are too implementation dependent for me or
anyone else to suggest an alternate debugger.

What I'd suggest is that you use yacc to explicitly generate the C code,
then use a "sed" or "awk" script to remove C preprocessor statements of the
form: # line xx "zz.y" from the code.  These cpp statements cause the source
line numbers within the yyparse procedure to get rather confused, and
simple-minded debuggers such as dbx can't hack them properly. What you'll
end up seeing at the "source" level is a big case statement containing the
semantic actions with the syntactic variables replaced with expressions of
the form: yypvt[-xx].type.

Even better is to make the semantic actions really simple, such as calls to
procedures that do the work.  That way, you will have little need to set
breakpoints within yyparse at all.

-- 
Craig Hansen
Manager, Architecture Development
MIPS Computer Systems, Inc.
...decwrl!mips!hansen