I want to read a file in a C++ program and pass it on to lex and yacc for parsing, but I am getting compilation errors. Here is my main.cpp file (with the first error):
extern "C"
{
#include "parser_iface.h"
#include "parser.h"
#include "lexer.h"
}
#include <stdio.h>
#include <iostream>
int yyparse(yyscan_t scanner);
int main(void)
{
yyscan_t scanner;
extern FILE *yyin;
if (yylex_init(&scanner))
return NULL;
yyin = fopen("test_file.cws", "r"); // <- error C2039: 'yyin_r' : is not a member of '_iobuf'
if(yyin == NULL)
{
std::cout << "Error!" << std::endl;
}
else
{
std::cout << "Parsing" << std::endl;
yyparse(scanner);
}
yy_delete_buffer(0, scanner);
yylex_destroy(scanner);
printf("Press ENTER to close. ");
getchar();
return 0;
}
The top of my lex file (.l) is as follows:
%{
#include "parser_iface.h"
#include "parser.h"
#include <stdio.h>
%}
%option outfile="lexer.c" header-file="lexer.h"
%option warn reentrant noyywrap never-interactive nounistd bison-bridge
The top of my yacc file (.y) is as follows:
%{
#include "parser_iface.h"
#include "parser.h"
#include "lexer.h"
int yyerror(yyscan_t scanner, const char *msg);
int curr_mod;
%}
%code requires
{
#ifndef YYSCAN_T
#define YYSCAN_T
typedef void* yyscan_t;
#endif
}
%output "parser.c"
%defines "parser.h"
%define api.pure
%lex-param { yyscan_t scanner }
%parse-param { yyscan_t scanner }
I am using win_flex and win_bison.