2012-04-11 68 views
0

我正在編譯幾個lex和yacc程序。在大學我們使用Fedora Core 4.我在家中的虛擬機上使用相同的操作系統,但我無法編譯程序。以下是lex和yacc代碼無法編譯Lex和Yacc程序

LEX代碼

%{ 
#include "y.tab.h" 
%} 
%% 
[ \t]+ {;} 
\n {return;} 
[a-zA-Z][a-zA-Z0-9]* {return ID;} 
[0-9]+ {return NUMBER;} 
. {return yytext[0];} 
%% 

YACC代碼

%{ 
#include<stdio.h> 
%} 
%token NUMBER ID 
%left '+' '-' 
%left '*' '/' 
%% 
input:e'+'e 
|e'-'e 
|e'*'e 
|e'/'e 
|'('e')' 
; 
e:NUMBER 
|ID 
; 
%% 
int main() 
{ 
printf("\n\nEnter an expression"); 
yyparse(); 
printf("\n\nValid Expression\n\n"); 
} 
void yyerror() 
{ 
printf("\n\nInvalid Expression\n\n"); 
exit(0); 
} 

While executing the above code, I get the following linker error 

$ lex program_name.l      //executes without error 
$ yacc -d program_name.y     //executes without error 
$ cc lex.yy.c y.tab.c -ll -ly 
/usr/bin/ld: cannot find -ly 
collect2: ld returned 1 exit status 

請幫我解決這個錯誤。在此先感謝

回答

0

這與您的YACC LIB做... 你將需要包括與-L"/some/path/to/lib-directory"選項

或可能需要安裝相應的lib目錄...

1

This conversion概述了你的問題:你需要安裝liby並且編譯器需要設置正確的庫路徑(例如-L/usr/lib)

-ly選項告訴鏈接器與liby庫鏈接,但根據到錯誤,它找不到該庫

1

有沒有這樣的事情-ly。 Lex和flex生成的掃描程序使用運行時支持庫。 yacc生成的分析器不會。只需拿出-ly並再試一次。