I am a freshman in using bison and flex. I downloaded the package provided by gnu bison official site. There is a example folder contains source codes of a calculator in C++. Here is the download link: ftp://ftp.gnu.org/gnu/bison/
I did following action:
bison -d calc++-parser.yy => OK, produce calc++-parser.tab.hh and calc++-parser.tab.cc
flex calc++-scanner.ll => OK, produce lex.yy.c
cc -o a.out lex.yy.c calc++-parser.tab.cc -lfl => failed
I have no idea why I failed in the third step, in fact, I don't really know whether I do right or not.
calc++-scanner.ll:2:20: error: cstdlib: No such file or directory
calc++-scanner.ll:5:19: error: string: No such file or directory
In file included from calc++-scanner.ll:6: ../../doc/bison.texinfo:8284:16: error: map: No such file or directory
In file included from ../../doc/bison.texinfo:8285, from calc++-scanner.ll:6: ../../doc/bison.texinfo:8440: error: expected '=', ',', ';', 'asm' or 'attribute' before 'calcxx_driver'
(... such error msg)
Compiler Version: gcc 4.2.1
Bison: 2.5.1
Flex: 2.5.4
After using {g++} instead of {cc}:
u97530048@csie0[9:45pm]~/Compiler/calc++>g++ -o a.out lex.yy.c calc++-parser.tab.cc -lfl
In file included from ../../doc/bison.texinfo:8285,from ../../doc/bison.texinfo:8504:
./calc++-parser.hh:126: error: redefinition of 'class yy::calcxx_parser' calc++-parser.tab.hh:96: error: previous definition of 'class yy::calcxx_parser'