I am trying to compile a .l file to create a lexical analyzer. the code is:
%{
#include "ifanw.tab.h"
extern int yylval;
%}
%%
"=" { return EQ; }
"!=" { return NE; }
"<" { return LT; }
"<=" { return LE; }
">" { return GT; }
">=" { return GE; }
"+" { return PLUS; }
"-" { return MINUS; }
"*" { return MULT; }
"/" { return DIVIDE; }
")" { return RPAREN; }
"(" { return LPAREN; }
":=" { return ASSIGN; }
";" { return SEMICOLON; }
"IF" { return IF; }
"THEN" { return THEN; }
"ELSE" { return ELSE; }
"FI" { return FI; }
"WHILE" { return WHILE; }
"DO" { return DO; }
"OD" { return OD; }
"PRINT" { return PRINT; }
[0-9]+ { yylval = atoi(yytext); return NUMBER; }
[a-z] { yylval = yytext[0] - 'a'; return NAME; }
\ { ; }
\n { nextline(); }
\t { ; }
"//".*\n { nextline(); }
. { yyerror("illegal token"); }
%%
the commands I have entered were:
flex filename.l
gcc -c lex.yy.c -o out
the output was
filename.l:2:23: fatal error: ifanw.tab.h: no such file or directory.
Is the problem in gcc libraries? If so, where can I download an updated/fixed library?
Otherwise, what’s the problem?
gccis telling you what the trouble is: it cannot find the include file you specified.It’s not a problem of libraries.
You need to create that file from your .y file first
You might find this small tutorial useful.
If you do not have the .y file, then you’re trying to compile an incomplete package, and that just won’t work. You will have to somehow obtain the missing files from wherever you got the files you already have.