How can I use a scanner I've written using Flex as part of a program I'm designing? Specifically, within a c++ class as a method of the class, and from a separate file with just a main method to perform testing.
I don't wish to use the %option c++, but will compile with g++.
To answer the problem of how to test the scanner from a separate file's main I attempted with the following code:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
extern "C" {
extern int yylex();
}
extern FILE* yyin;
int main(int argc, char *argv[]) {
if (argc > 1)
yyin = fopen(argv[1], "r");
yylex();
return 0;
}
I compile like so:
flex mylexer.l++
g++ lex.mylexer.C myDriver.C -o myLexer
I get:
undefined reference to yyin
undefined reference to yylex
What is the correct way to compile/setup the driver file? Thank you for reading and contributing anything!