|
|
Tracing YACC Parsers
In order to trace the steps of a Yacc-generated parses, you should:
- Declare an external variable yydebug and assign a non-0 value to it (most likely, in your main function:
extern int yydebug;
... yydebug = 1;
As an example, consider this main.c file with debugging-triggering code included. Note that the declaration and assignment of yydebug are included only if the YYDEBUG macro has been defined.
- Compile your parser with the YYDEBUG macro turned on. For example:
gcc -DYYDEBUG lex.yy.c y.tab.c main.c -ll
- Run the parser on a test file and trace the output, comparing it with the content of the y.output file created for your Yacc specification file.
An example of a trace output for the expressions grammar and the input 3+4*5= is shown here (using the corresponding y.output file).
For additional information, read the section on debugging parsers in the on-line Bison manual.
|