I started to use Lex for my homework. In my Lex file, I always meet errors when go to first line of Rules Section. I have tested on sample code in books.
Here is the errors that Flex throw :
1 Error: Parse error at line
2 Description: Badly formed macro definition.
And here is my code.
int num_lines = 0, num_chars = 0;
%%
\n ++num_lines; ++num_chars; // error here
. ++num_chars;
%%
main()
{
yylex();
printf( "# of lines = %d, # of chars = %d\n",
num_lines, num_chars );
}
Thanks 🙂
Try