1
votes

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'

2

2 Answers

1
votes

all: calc++.out

calc++.out: calc++-driver.o calc++-parser.o calc++-scanner.o calc++.o

g++ -o calc++.out calc++-driver.o calc++-parser.o calc++-scanner.o calc++.o

calc++-driver.o: calc++-driver.cc calc++-driver.hh calc++-parser.hh

g++ -c calc++-driver.cc

calc++-parser.o: calc++-parser.cc calc++-parser.hh calc++-driver.hh

g++ -c calc++-parser.cc

calc++-parser.cc calc++-parser.hh: calc++-parser.yy

bison --defines=calc++-parser.hh -ocalc++-parser.cc calc++-parser.yy

calc++-scanner.o: calc++-scanner.cc calc++-parser.hh calc++-driver.hh

g++ -c calc++-scanner.cc

calc++-scanner.cc: calc++-scanner.ll

flex -ocalc++-scanner.cc calc++-scanner.ll

calc++.o: calc++.cc

g++ -c calc++.cc

.PHONY: clean

clean:

-rm *.o calc++-parser.hh calc++-parser.cc calc++-scanner.cc location.hh position.hh stack.hh calc++.out

0
votes

I can't reproduce your problem with Bison 2.7.2. Bison 2.5 is ancient, you should upgrade and report problems you might encounter them.