I am trying to keep an error count in a variable called ‘mismatches’, in which i declare in the first part of the bison file.
In my bison grammar, i set a value to that variable.
Then in the 3rd part of the bison file, in the main() function i cout its value, and it’s 0.
A very modified/cut down version of my bison file:
%{
extern "C" FILE *yyin;
extern int yylineno;
extern int yynerrs;
int yylex();
// Declare 'mismatches'
int mismatches;
%}
%error-verbose
%%
expression:
expression ADDOP term
{
cout << "Parser is now here. Going to set `mismatches` to 6";
mismatches = 6;
}
| term
;
%%
int main()
{
// Outputs 0
cout << mismatches;
yyparse();
return 1;
}
What should i do so that the variable ‘mismatches’ can be used in all parts of the bison file?
I think you want to output the variable after you run the parser, like so