Search code examples
debuggingcompiler-constructionbisonyacclex

Bison/Yacc still printing debug messages despite tracing being explicitly disabled


I am using flex and bison on windows from this repository along with Visual Studio 2019 to produce a small calculator application.

Earlier I enabled bison debug messages through the build properties in VS. I've now turned it off, cleaned and rebuilt the project but the debug messages are still persisting in the calculator. I have also tried a number of other ways to explicitly disable it, such as setting YYDEBUG to 0 and %define parse.trace false.

Flex

%option noyywrap

%{
#include <stdlib.h>
#include "calculator.tab.h"
#define YY_DECL extern "C" int yylex()
void yyerror(const char*);
%}

digit   [0-9]

%%

{digit}+    { 
                yylval = atoi(yytext);
                return INTEGER;
            }
[-+*/\n()]  {
                return *yytext;
            }
[ \t]       ;
.           {
                yyerror("Unrecognised character.");
            }

%%
start /B /WAIT /D "%(RootDir)%(Directory)" win_flex.exe --outfile="%(Filename).flex.cpp" --wincompat  "%(Filename)%(Extension)"
exit /b %errorlevel%

Bison

%{
#include <stdlib.h>
#include <stdio.h>
extern "C" int yylex();
void yyerror(const char*);
%}

%token INTEGER
%left '-' '+'
%left '*' '/'

%%

program:    
            program expr '\n'   { printf("Result: %d\n", $2); }
            |
            ;
expr:
            | INTEGER       { $$ = $1; }
            | expr '-' expr { $$ = $1 - $3; }
            | expr '+' expr { $$ = $1 + $3; }
            | expr '*' expr { $$ = $1 * $3; }
            | expr '/' expr { $$ = $1 / $3; }
            | '(' expr ')'  { $$ = $2; }
            ;

%%

void yyerror(const char* msg){
    fprintf(stderr, "ERROR: %s\n", msg);
}

int main(void){
    yyparse();
    return 0;
}
start /B /WAIT /D "%(RootDir)%(Directory)" win_bison.exe --output="%(Filename).tab.cpp" --defines="%(Filename).tab.h"  "%(Filename)%(Extension)"
exit /b %errorlevel%

Runtime Output

--(end of buffer or a NUL)
1+5
--accepting rule at line 14 ("1")
--accepting rule at line 18 ("+")
--accepting rule at line 14 ("5")
--accepting rule at line 18 ("
")
Result: 6
--(end of buffer or a NUL)

How can I properly remove the debug messages/tracing from my application?


Solution

  • It seems it was lex tracing, which I've been able to disable through the bison/yacc input file.

    In the definitions code, add: extern int yy_flex_debug;

    In your main method, add: yy_flex_debug = 0;