How To Compile YACC And LEX?

Posted by nisha on Stack Overflow See other posts from Stack Overflow or by nisha
Published on 2011-01-11T13:40:56Z Indexed on 2011/01/11 13:53 UTC
Read the original article Hit count: 276

Filed under:
|
|

Actually I'm having YACC file as pos.yacc and LEX file name is pos1.lex.. while compilling I'm getting the folowing error...

malathy@malathy:~$ cc lex.yy.c  y.tab.c -ly -ll

pos1.lex

%{
#include "y.tab.h"

  int yylval;
%}
DIGIT [0-9]+
%%
{DIGIT} {yylval=atoi(yytext);return DIGIT;}
[\n ] {}
. {return *yytext;}
%%

yacc file is pos.yacc

%token DIGIT
%%
s:e {printf("%d\n",$1);}
e:DIGIT {$$=$1;}
|e e "+" {$$=$1+$2;}
|e e "*" {$$=$1*$2;}
|e e "-" {$$=$1-$2;}
|e e "/" {$$=$1/$2;}
;
%%
main() {
  yyparse();
}
yyerror() {
  printf("Error");
}

so while compiling i m getting like

malathy@malathy:~$ cc lex.yy.c  y.tab.c -ly -ll
pos.y: In function ‘yyerror’:
pos.y:16: warning: incompatible implicit declaration of built-in function ‘printf’
pos.y: In function ‘yyparse’:
pos.y:4: warning: incompatible implicit declaration of built-in function ‘printf’

© Stack Overflow or respective owner

Related posts about yacc

Related posts about lex