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

28,581

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.

Share:
28,581
AJ.
Author by

AJ.

Updated on April 28, 2021

Comments

  • AJ.
    AJ. almost 3 years

    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);}
    
  • AJ.
    AJ. over 10 years
    I compiled the program using 'yacc prog.y' and it is not creating 'y.tab.h' .
  • KriptSkitty
    KriptSkitty over 10 years
    The you need to write yacc -d prog.y.
  • AJ.
    AJ. over 10 years
    But when I do it in red hat, it does not require such thing. Why?
  • KriptSkitty
    KriptSkitty over 10 years
    I don't have Red Hat here to try, but perhaps -d is a default on their particular version of Bison, and you don't need to specify it.