%{
#include <stdio.h>
int single = 0;
int multi = 0;
extern FILE *yyin; // Declare yyin
%}
%%
// Match single-line comments
"//".* { ++single; }
// Match multi-line comments
"/*"([^*]|\*+[^*/])*\*+"/" { ++multi; }
%%
int main(int argc, char **argv) { // Fix argument type
yyin = fopen("abc.txt", "r");
if (!yyin) {
perror("Error opening file");
return 1;
}
yylex();
fclose
(yyin
); // Close file after reading
printf
("
Number of single
-line comments
= %d\n", single); printf
("
Number of multi
-line comments
= %d\n", multi); return 0;
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgc2luZ2xlID0gMDsKaW50IG11bHRpID0gMDsKZXh0ZXJuIEZJTEUgKnl5aW47ICAvLyBEZWNsYXJlIHl5aW4KJX0KCiUlCi8vIE1hdGNoIHNpbmdsZS1saW5lIGNvbW1lbnRzCiIvLyIuKiB7ICsrc2luZ2xlOyB9CgovLyBNYXRjaCBtdWx0aS1saW5lIGNvbW1lbnRzCiIvKiIoW14qXXxcKitbXiovXSkqXCorIi8iIHsgKyttdWx0aTsgfQoKJSUKCmludCBtYWluKGludCBhcmdjLCBjaGFyICoqYXJndikgeyAgLy8gRml4IGFyZ3VtZW50IHR5cGUKICAgIHl5aW4gPSBmb3BlbigiYWJjLnR4dCIsICJyIik7CiAgICBpZiAoIXl5aW4pIHsKICAgICAgICBwZXJyb3IoIkVycm9yIG9wZW5pbmcgZmlsZSIpOwogICAgICAgIHJldHVybiAxOwogICAgfQogICAgeXlsZXgoKTsKICAgIGZjbG9zZSh5eWluKTsgIC8vIENsb3NlIGZpbGUgYWZ0ZXIgcmVhZGluZwogICAgcHJpbnRmKCJOdW1iZXIgb2Ygc2luZ2xlLWxpbmUgY29tbWVudHMgPSAlZFxuIiwgc2luZ2xlKTsKICAgIHByaW50ZigiTnVtYmVyIG9mIG11bHRpLWxpbmUgY29tbWVudHMgPSAlZFxuIiwgbXVsdGkpOwogICAgcmV0dXJuIDA7Cn0K