Error Undefined Reference To Yyparse
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more undefined reference to yylex about Stack Overflow the company Business Learn more about hiring developers or posting undefined reference to yylex gcc ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack
In Function `yyparse': Undefined Reference To `yyerror'
Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Undefined reference to yyparse (flex & bison) up vote 5 down
Y.tab.c Undefined Reference To Yyerror'
vote favorite 3 I'm attempting to learn some flex/bison, and I'm reading Flex & Bison by John Levine (O'Reilly). There is an example that I need to get running, however I can't get it to run as I get the following error: /tmp/ccKZcRYB.o: In function `yylex': fb3-1.lex.c:(.text+0x2bd): undefined reference to `yylval' /tmp/cclBqnOk.o: In function `main': fb3-1funcs.c:(.text+0x420): undefined reference to `yyparse' collect2: ld returned 1 exit status I've got four in function yyparse' undefined reference to yylex' source files: fb3-1.h: /* * Declarations for calculator fb3-1 */ /* Interface to the lexer */ extern int yylineno; /* from lexer */ void yyerror(char *s, ...); /* nodes in the abstract syntax tree */ struct ast { int nodetype; struct ast *l; struct ast *r; }; struct numval { int nodetype; /* type K for constant */ double number; }; /* build an AST */ struct ast *newast(int nodetype, struct ast *l, struct ast *r); struct ast *newnum(double d); /* evaluate an AST */ double eval(struct ast *); /* delete and free an AST */ void treefree(struct ast *); fb3-1.l /* recognise tokens for the calculator */ %option noyywrap nodefault yylineno %{ #include "fb3-1.h" #include "fb3-1.tab.h" %} /* float exponent */ EXP ([Ee][-+]?[0-9]+) %% "+" | "-" | "*" | "/" | "|" | "(" | ")" { return yytext[0]; } [0-9]+"."[0-9]*{EXP}? | "."?[0-9]+{EXP}? { yylval.d = atof(yytext); return NUMBER; } \n { return EOL; } "//".* [ \t] { /* ignore whitespace */ } . { yyerror("Mystery character %c\n", *yytext); } %% fb3-1.y /* calculator with AST */ %{ #include #include #include "fb3-1.h" %} %union { struct ast *a; double d; } /* declare tokens */ %token NUMBER %to
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow
Bison Undefined Reference To
the company Business Learn more about hiring developers or posting ads with us Stack undefined reference to yyparse c++ Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community undefined reference to `yywrap' of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Undefined reference to `_yyerror' when compiling with Flex and Bison up vote 5 down vote favorite I'm http://stackoverflow.com/questions/3298718/undefined-reference-to-yyparse-flex-bison trying to make a compiler for a mini Pascal-like language. I'm using Flex and Bison for this and I came up with this error. My Flex file: %{ #include "y.tab.h" #include #include #include void yyerror(char *); %} %% [1-9][0-9]* { yylval.i = atoi(yytext); return INT; } program return PROGRAM; or return OR; and return AND; not return NOT; if return IF; else return ELSE ; while return WHILE; "+" http://stackoverflow.com/questions/17127481/undefined-reference-to-yyerror-when-compiling-with-flex-and-bison return PLUS; "-" return MINUS; "*" return MUL; "/" return DIV; "[" return LSB; "]" return RSB; "{" return LCB; "}" return RCB; "(" return LEFTPAR; ")" return RIGHTPAR; ":=" return ASSIGN; "==" return ISEQUAL; "<" return LTHAN; ">" return GTHAN; "<>" return NOTEQUAL; "<=" return LESSEQUAL; ">=" return GREATEREQUAL; [a-zA-z][a-z0-9]* { yylval.s = (char*)malloc(strlen(yytext)*sizeof(char)); strcopy(yylval.s,yytext); return ID; } [ \t\n]+ /* eat up whitespace */ . yyerror("Unknown Character"); %% int yywrap(void) { return 1; } My Bison file: %{ #include #include int yylex(void); void yyerror(char *s); %} %union { int i; char *s; }; %token INTEGERNUM %token PROGRAM; %token OR; %token AND; %token NOT; %token IF; %token ELSE; %token WHILE; %token PLUS; %token MINUS; %token MUL; %token DIV; %token LSB; %token RSB; %token LCB; %token RCB; %token LEFTPAR; %token RIGHTPAR; %token ID; %token INT; %token ASSIGN; %token ISEQUAL; %token LTHAN; %token GTHAN; %token NOTEQUAL; %token LESSEQUAL; %token GREATEREQUAL; %% program: PROGRAM ID block ; block: LCB sequence RCB ; sequence: statement ';' sequence | statement ';' ; bracketsSeq: LCB sequence RCB ; brackOrStat: bracketsSeq | statement ; statement: assignmentStat |ifStat |whileStat | ; assignmentStat: ID ':=' expression ifStat: IF LEFTPAR condition RIGHTPAR brackOrStat elsepart ; elsepart: ELSE brackOrStat | ; whileStat: WHILE LEFTPAR condition RIGHTPAR brackOrStat ; expression: opt
grammar and a flex lexer. I compile them and a couple c++ source files separately, and then link them all together at once. I'm getting the following error: gcc -o si-stats http://computer-programming-forum.com/47-c-language/bbd6b3e0378fc29b.htm si-stats.o player.o lex.yy.o y.tab.o -lstdc++ -ll si-stats.o: In function `ParseLog(map, __default_alloc_template >, CPlayer, less, __default_alloc_template > >, allocator > &)': /home/log/si-stats/si-stats.cpp:54: undefined reference to `yyparse(void *)' any suggestions? is it because im mixing c++ code with c (from flex and bison)? (flex 2.5.4, bison 1.28, gcc 2.95.2) Log Mon, 04 Aug 2003 05:08:01 GMT Kenneth Ch#2 / 9 flex/bison linking problems Quote:>I'm trying to undefined reference write a simple parser for some log files. I have a bison >grammar and a flex lexer. I compile them and a couple c++ source files >separately, and then link them all together at once. I'm getting the >following error: >gcc -o si-stats si-stats.o player.o lex.yy.o y.tab.o -lstdc++ -ll >si-stats.o: In function `ParseLog(mapstring_char_traits, __default_alloc_template >, CPlayer, >less, >__default_alloc_template > >, allocator > &)': >/home/log/si-stats/si-stats.cpp:54: undefined undefined reference to reference to `yyparse(void *)' >any suggestions? >is it because im mixing c++ code with c (from flex and bison)? Is yyparse() declared extern "C". Also, a general rule of thumb for building mixed C-C++ programs is to link with the compiler corresponding to your main(). That is, if you main is in C++, use g++, etc. There are exceptions, but it's usually the best choice. Mon, 04 Aug 2003 05:18:27 GMT Logan Ingall#3 / 9 flex/bison linking problems Quote: >> I'm trying to write a simple parser for some log files. I have a bison >> grammar and a flex lexer. I compile them and a couple c++ source files >> separately, and then link them all together at once. I'm getting the >> following error: >> gcc -o si-stats si-stats.o player.o lex.yy.o y.tab.o -lstdc++ -ll >> si-stats.o: In function `ParseLog(map> string_char_traits, __default_alloc_template >, CPlayer, >> less, >> __default_alloc_template > >, allocator > &)': >> /home/log/si-stats/si-stats.cpp:54: undefined reference to `yyparse(void *)' >> any suggestions? >> is it because im mixing c++ code with c (from flex and bison)? > Is yyparse() declared extern "C". > Also, a general rule of thumb for building mixed C-C++ programs is to > link wit