I have a project for school where we need to use flex and bison. I want to use C++ so that I have access to STL and my own classes that I wrote. We were provided with the fo
Use either a C Compiler or a C++ compiler but not both (till you know what you are upto). You are sure to shoot yourself many times on both your feet otherwise. Mixing gcc and g++ isn't good.
This line is suspect:
lex.yy.o: scan.l parse.tab.h attr.h # added this ...
gcc -c -o lex.yy.o lex.yy.c
Also, you don't seem to be using CC
anywhere, using that'd have made life easier.
Assuming you don't change a single line of the C code, you will possibly hit some errors and quite a few warnings (like deprecated headers etc). You'll have to fix them as well.
If you are doing parsers in C++ I would recommend to look at Boost Spirit. It is so much nicer to handle than bison/yacc.
From here:
Spirit is an object-oriented recursive-descent parser generator framework implemented using template meta-programming techniques. Expression templates allow us to approximate the syntax of Extended Backus-Normal Form (EBNF) completely in C++.
You don't need to do anything with flex or bison to use C++, I have done it many times. You just have to make sure you use g++, not gcc.
Your problems are with the Makefile, not the code.
There are some differences that you can check out in detail here.
For using flex with C++:
1: read the flex docs:
2: use flex -+ -o file.cc parser.ll
3: In the .ll file:
%option c++
%option yyclass="Your_class_name"
%option batch
4: In your .hh file, derive Your_class_name from public yyFlexLexer
5: you can then use your_class_instance.yylex()