Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fatal error:y.tab.h: No such file or directory on fedora

Tags:

fedora

yacc

lex

I am running my fedora on VMware Workstation. I am having a lex and yacc program. Compilation of program is working fine but when i go to run the program through gcc y.tab.c lex.yy.c -ll it gives fatal error: y.tab.h: No such file or directory.

Same program is working fine with red hat but not in fedora which is running on VMware.

Please give some suggestions.

This program is a infix to post fix program.

lex program:---->

  %{
#include<string.h>
#include"y.tab.h"
FILE *fp,*yyin;
%}

%%
"*"|"/"|"+"|"-"|"("|")" {return yytext[0];}
[0-9]+ {yylval.name=(char*)malloc(yyleng+1);
   strcpy(yylval.name,yytext);
   return num;}
\n {return(0);}
[a-zA-Z][a-zA-Z]* {yylval.name=(char*)malloc(yyleng+1);
      strcpy(yylval.name,yytext);
      return ID;}
. {}
%%

int yywrap()
{
return 1;
}

yacc program:------->

%{
#include<stdio.h>
#include<string.h>

%}
%union
{
  char *name;
}
%token<name>num ID
%type<name>E
%left'+''-'
%left'*''/'
%nonassoc UMINUS
%%
S:E{printf("\n%s",$1);}
;
E:E'*'E {strcpy($$,strcat(strcat($1,$3),"*"));}
|E'/'E {strcpy($$,strcat(strcat($1,$3),"/"));}
|E'+'E {strcpy($$,strcat(strcat($1,$3),"+"));}
|E'-'E {strcpy($$,strcat(strcat($1,$3),"-"));}
|ID
|num
|'-'E%prec UMINUS {strcpy($$,strcat($2,"UMINUS"));}
|'('E')'{strcpy($$,$2);}
;
%%

main()
{
yyparse();
}
int yyerror(char *s) {fprintf(stderr,"%s\n",s);}
like image 446
AJ. Avatar asked Oct 22 '13 17:10

AJ.


1 Answers

This is likely to be a problem with exactly which commands you use to invoke Yacc, Lex and GCC, and not with the input files that you included here.

Yacc (which probably really is a program called Bison even if you use the command yacc) generates two files: A parser (y.tab.c) and another file (y.tab.h) with definitions that the scanner needs. The problem here is that GCC cannot find that file, y.tab.h.

Check these things:

That the file actually is generated. You may have to give the flag -d to Bison/Yacc.

That the file is called y.tab.h. The name can be different depending on program versions, and if you start Bison with the command bison or with the command yacc.

That the file is in a directory where GCC can find it.

like image 171
Thomas Padron-McCarthy Avatar answered Sep 19 '22 21:09

Thomas Padron-McCarthy