%{
#include <stdio.h>
%}
%%
[ \t\n]+ { printf(" "); } // Replace whitespace sequence with a single blank
. { putchar(yytext[0]); } // Copy other characters as they are
%%
int main(int argc, char *argv[]) {
if (argc < 2) {
printf("Usage: %s <filename>\n", argv[0]);
return 1;
}
FILE *fp = fopen(argv[1], "r");
if (!fp) {
printf
("Error
: Unable to
open the file
.\n"
); return 1;
}
yyin = fp;
yylex();
fclose(fp);
return 0;
}
CgolewojaW5jbHVkZSA8c3RkaW8uaD4KJX0KCiUlCgpbIFx0XG5dKyAgICB7IHByaW50ZigiICIpOyB9IC8vIFJlcGxhY2Ugd2hpdGVzcGFjZSBzZXF1ZW5jZSB3aXRoIGEgc2luZ2xlIGJsYW5rCi4gICAgICAgICAgIHsgcHV0Y2hhcih5eXRleHRbMF0pOyB9IC8vIENvcHkgb3RoZXIgY2hhcmFjdGVycyBhcyB0aGV5IGFyZQoKJSUKCmludCBtYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pIHsKICAgIGlmIChhcmdjIDwgMikgewogICAgICAgIHByaW50ZigiVXNhZ2U6ICVzIDxmaWxlbmFtZT5cbiIsIGFyZ3ZbMF0pOwogICAgICAgIHJldHVybiAxOwogICAgfQogICAgRklMRSAqZnAgPSBmb3Blbihhcmd2WzFdLCAiciIpOwogICAgaWYgKCFmcCkgewogICAgICAgIHByaW50ZigiRXJyb3I6IFVuYWJsZSB0byBvcGVuIHRoZSBmaWxlLlxuIik7CiAgICAgICAgcmV0dXJuIDE7CiAgICB9CiAgICB5eWluID0gZnA7CiAgICB5eWxleCgpOwogICAgZmNsb3NlKGZwKTsKICAgIHJldHVybiAwOwp9