#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Location
    Pittsburgh
    Posts
    2
    Rep Power
    0

    Question [SOLVED] YACC/LEX Compile Error Help


    Hey all, I've been trying to teach myself YACC/LEX. Learning LEX seemed pretty straight forward and managed to develop some cool stuff. However when I try to add in YACC my program fails to compile. Each website I read on YACC/LEX seems to say slightly different things when it comes to combining them.

    Anyway, I'm getting the following error:
    Undefined symbols:
    "_yyerror", referenced from:
    _yyparse in ccdhY7WN.o
    _yyparse in ccdhY7WN.o
    "_yylex", referenced from:
    _yyparse in ccdhY7WN.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status

    My code is pretty simple. Only 45 lines in total. If someone could help shine some light on this for me, I'd really appreciate it.

    Lex file (lex.l):
    Code:
    %{
    #include "y.tab.h"
    #define HELLO 300
    #define NUMBER 301
    	
    extern int yylval;
    %}
    
    %% 
    
    hello {
    	printf("Hello World");
    	return HELLO;
    }
    
    [0-9] {
    	printf("Number Recieved");
    	yylval = atoi(yytext);
    	return NUMBER;
    }
    
    %%
    YACC File (yacc.r):
    Code:
    %{
    #include <stdio.h>
    %}
    
    %token HELLO
    %token NUMBER
    
    %%
    test: word_num
    ;
    
    word_num: HELLO NUMBER {printf("YACC FOUND MATCH");}
    
    %%
    
    int yylval;
    
    int main () {
    	yyparse();
    }
    
    #include lex.yy.c
    I'm compiling by using the following commands:
    yacc -d yacc.r
    lex lex.l
    gcc y.tab.c
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Location
    Pittsburgh
    Posts
    2
    Rep Power
    0
    I finally figured it out. I was compiling incorrectly. I should have invoked gcc like this:

    gcc y.tab.c -ly -ll

IMN logo majestic logo threadwatch logo seochat tools logo