Greetings, I'm having a problem building a reentrant parser. Here's the simple test I'm doing, as suggested by the flex documentation. This is using flex 2.5.31 and bison 2.1 on x86_64 using g++ 4.0.2 on Fedora Core. Please send any suggestions or help.
+++ begin file slex.l +++ /* Scanner for "C" assignment statements... sort of. */ %{ #include "sparse.tab.h" /* Generated by bison. */ %} %option bison-bridge bison-locations %% [[:digit:]]+ { yylval->num = atoi(yytext); return NUMBER;} [[:alnum:]]+ { yylval->str = strdup(yytext); return STRING;} "="|";" { return yytext[0];} . {} %% +++ end of slex.l, begin sparse.y +++ /* Parser to convert "C" assignments to lisp. */ %{ /* Pass the argument to yyparse through to yylex. */ #define YYPARSE_PARAM scanner #define YYLEX_PARAM scanner #include <stdio.h> %} %locations %pure_parser %union { int num; char* str; } %token <str> STRING %token <num> NUMBER %% assignment: STRING '=' NUMBER ';' { printf( "(setf %s %d)", $1, $3 ); } ; %% +++ end of sparse.y So here's how I'm trying to build, complete with error +++ bison -d sparse.y flex -f slex.l g++ lex.yy.c sparse.tab.c sparse.tab.h sparse.tab.c: In function 'int yyparse(void*)': sparse.tab.c:1036: error: 'yylex' was not declared in this scope sparse.tab.c:1267: error: 'yyerror' was not declared in this scope sparse.tab.c:1382: error: 'yyerror' was not declared in this scope ++++ ok, so if we define the yylex function as follows +++ /* Parser to convert "C" assignments to lisp. */ %{ /* Pass the argument to yyparse through to yylex. */ #define YYPARSE_PARAM scanner #define YYLEX_PARAM scanner #include <stdio.h> int yylex(YYSTYPE * lvalp); %} %locations %pure_parser %union { int num; char* str; } %token <str> STRING %token <num> NUMBER %% assignment: STRING '=' NUMBER ';' { printf( "(setf %s %d)", $1, $3 ); } ; %% +++ produces the following error sparse.y:7: error: 'YYSTYPE' was not declared in this scope sparse.y:7: error: 'lvalp' was not declared in this scope sparse.tab.c: In function 'int yyparse(void*)': sparse.tab.c:1037: error: 'yylex' cannot be used as a function sparse.tab.c:1268: error: 'yyerror' was not declared in this scope sparse.tab.c:1383: error: 'yyerror' was not declared in this scope +++ examining the tab.c file, it places the declaration of yylex before the +++ declaration of YYSTYPE +++ fyi, if you make the declaration extern, you get the following error sparse.y:7: warning: 'yylex' initialized and declared 'extern' sparse.y:7: error: 'YYSTYPE' was not declared in this scope sparse.y:7: error: 'lvalp' was not declared in this scope sparse.tab.c: In function 'int yyparse(void*)': sparse.tab.c:1037: error: 'yylex' cannot be used as a function sparse.tab.c:1268: error: 'yyerror' was not declared in this scope sparse.tab.c:1383: error: 'yyerror' was not declared in this scope _______________________________________________ Help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison