Home > Mobile >  How to use %code provides {} to create a yyerror function from bison?
How to use %code provides {} to create a yyerror function from bison?

Time:06-26

I'm trying to build a simple flex/bison scanner/parser. Following the advice of "rici" on this question - How to invoke yyerror() from flex? - I have tried putting my yyerror function in a %code provides {} block, so that it gets generated into my tab.h file. However, when I do this, I get a linker error for multiple definition of 'yyerror';

I could define my yyerror function in a header that's included in both my .y and .l files, but the manual implies that putting it in the provides block is a reasonable tactic.

vscode ➜ /workspaces/slangy $ make
bison -t -v -d bas.y
flex bas.l
gcc -Wl,--trace-symbol=yyerror -o bas bas.tab.c lex.yy.c
/usr/lib/gcc/aarch64-alpine-linux-musl/10.3.1/../../../../aarch64-alpine-linux-musl/bin/ld: /tmp/cccFdeoF.o: definition of yyerror
/usr/lib/gcc/aarch64-alpine-linux-musl/10.3.1/../../../../aarch64-alpine-linux-musl/bin/ld: /tmp/ccFFolkk.o: in function `yyerror':
lex.yy.c:(.text 0x0): multiple definition of `yyerror'; /tmp/cccFdeoF.o:bas.tab.c:(.text 0x0): first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:10: bas] Error 1

The parser .y file

           
  • Related