Ich versuche, einige Lex und Yacc Programme zu kompilieren. In der Schule verwenden wir Fedora Core 4. Ich benutze das gleiche Betriebssystem auf einer virtuellen Maschine zu Hause, aber ich kann das Programm nicht kompilieren. Im Folgenden sind die lex und yacc CodesLex und Yacc Programme können nicht kompiliert werden
LEX-Code
%{
#include "y.tab.h"
%}
%%
[ \t]+ {;}
\n {return;}
[a-zA-Z][a-zA-Z0-9]* {return ID;}
[0-9]+ {return NUMBER;}
. {return yytext[0];}
%%
YACC-Code
%{
#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
Bitte helfen Sie mir diesen Fehler zu beheben. Vielen Dank im Voraus