سؤال

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);}
هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

If you are using flex windows(lex and yacc) on windows and facing this error then fillow the given steps:

  1. In lex file on first line add this line:

%option noyywrap

  1. compile the lex file
  2. compile the yacc file
  3. then compile and build the yacc file
  4. select the option "open with cmd"
  5. Enter the commond:

filename.exe

please note that lex file name and yacc file name should be same only they differ in their extensions

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top