I am super new to FLEX, I'm trying to write a simple FLEX lex file, but for some reason I get the error in the header.
The complete error is:
bash syntax error near unexpected token '('
The command I am running is:
flex sample.lex
OR
flex sample.l
Where am I going wrong here?
%{
union{
int val;
char name [30];
char str [80];
}yylval;
#include <stdio.h>
%}
%%
. ECHO;
%%
int main(int argc, char **argv)
{
if (argc != 2) {
printf("no input file>\n");
exit (1);
}
printf("token lexeme attribute\n");
printf("--------------------------\n");
yyin=fopen(argv[1], "r");
if(yyin!=0)
{ printf("file opened");
fclose(yyin);}
exit (0);
}
int yywrap () { return 1; }
int
. C99 dropped that rule, but many compilers still support it, perhaps with a warning (strictly speaking omitting the return type is now a syntax error). Still, there's no good reason to omit the return type. David: Changemain
toint main
; that's not the cause of your problem, but you should fix it anyway. – Keith Thompson