user1010101
user1010101

Reputation: 1658

Flex Error matchtype.h

I am writing a simple flex program that takes some inputs and creates tokens for the parser.

My code [ex4.l]

%{
enum yytokentype{
NUMBER = 258,
ADD = 259,
SUB = 260,
MUL = 261,
DIV = 262,
ABS = 263,
EOL = 264
};
int yylval
%}

%%
"+"     {return ADD;}
"-"     {return SUB;}
"*"     {return MUL;}
"/"     {return DIV;}
"|"     {return ABS;}
[0-9]+  {yylval = atoi(yytext);return NUMBER;}
\n      {return EOL;}
[ \t]   {/*ignore whitespace */}
.       {printf("Mystery character %c\n",*yytext);}
%%
int main(int argc, char **argv)
{
 int tok;

 while(tok = yylex()){
  printf("%d",tok);
  if(tok == NUMBER)
        printf("=%d\n",yylval);
  else
        printf("\n");
 }
}

After this i ran the command flex ex4.l which generated a lex.yy.c file and when i tried to run this by using the cc lex.yy.c -lfl i got stuck with this error message. And i keep getting this error i am not sure what the problem is at all. i am stuck on this for very long. Please advice

Error Message

cc lex.yy.c -lfl
"/usr/include/sys/machtypes.h", line 33: syntax error before or at: typedef
cc: acomp failed for lex.yy.c

Upvotes: 1

Views: 109

Answers (1)

rici
rici

Reputation: 241671

Line 11 of your flex input:

int yylval

is missing a semicolon.

Undoubtedly what is happening is that flex inserts an #include directive immediately following the code prologue, and the first file included (recursively) is machtypes.h. The error is flagged on the first non-preprocessor line of that file, presumably because the preprocessed C program is:

int yylval typedef struct   _label_t { long val[2]; } label_t;

which is a syntax error, as reported.

Upvotes: 2

Related Questions