I'm a beginner in lex. My program is to read a file and recognize the data types. I'm getting this error by writing "gcc -c lex.yy.c" in windows command line:-
code1.l: In function 'yylex':
code1.l:8:2: error: expected ';' before '{' token
My input file is:
#include <stdio.h>
int main()
{
int a;
float b;
long int c;
long long int d;
return 0;
}
My lex code is
%{
#include <stdio.h>
#include <stdlib.h>
%}
%%
"int"
{
printf("%s ->Intger data type\n", yytext);
}
"float"
{
printf("%s ->Floating point data type\n", yytext);
}
"double"
{
printf("%s ->double data type\n", yytext);
}
"char"
{
printf("%s ->character data type\n", yytext);
}
"void"
{
printf("%s ->void data type\n", yytext);
}
"bool"
{
printf("%s ->boolean data type\n", yytext);
}
"long"([ ])([ ])* "int"
{
printf("%s ->long int data type\n", yytext);
}
"long"([ ])([ ])* "long"([ ])([ ])* "int"
{
printf("%s ->long long int data type\n", yytext);
}
([a-z])*
{
printf("%s ->Not a data type\n", yytext);
}
([0-9])*
{
printf("%s ->Not a data type\n", yytext);
}
%%
int yywrap()
{
return 1;
}
int main()
{
FILE *fp = fopen("sampleIO.txt","r");
yyin=fp;
yylex();
return 0;
}
I can't find the error.Any help will be appreciated. Thank you.