%{
#include <stdio.h>
#include <stdlib.h>
int sum = 0; // Variable to store the sum
%}
%%
[0-9]+ { sum += atoi(yytext); } // Convert text to int and add to sum
\n { printf("Sum: %d\n", sum); sum = 0; } // Print sum after each line
[ \t] { /* Ignore spaces and tabs */ }
. { /* Ignore any other characters */ }
%%
int main() {
printf("Enter two numbers separated by spaces or newlines to sum them:\n");
yylex(); // Start lexical analysis
return 0;
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KaW50IHN1bSA9IDA7ICAvLyBWYXJpYWJsZSB0byBzdG9yZSB0aGUgc3VtCiV9CgolJQpbMC05XSsgICAgICB7IHN1bSArPSBhdG9pKHl5dGV4dCk7IH0gIC8vIENvbnZlcnQgdGV4dCB0byBpbnQgYW5kIGFkZCB0byBzdW0KXG4gICAgICAgICAgeyBwcmludGYoIlN1bTogJWRcbiIsIHN1bSk7IHN1bSA9IDA7IH0gIC8vIFByaW50IHN1bSBhZnRlciBlYWNoIGxpbmUKWyBcdF0gICAgICAgIHsgLyogSWdub3JlIHNwYWNlcyBhbmQgdGFicyAqLyB9Ci4gICAgICAgICAgICB7IC8qIElnbm9yZSBhbnkgb3RoZXIgY2hhcmFjdGVycyAqLyB9CiUlCgppbnQgbWFpbigpIHsKICAgIHByaW50ZigiRW50ZXIgdHdvIG51bWJlcnMgc2VwYXJhdGVkIGJ5IHNwYWNlcyBvciBuZXdsaW5lcyB0byBzdW0gdGhlbTpcbiIpOwogICAgeXlsZXgoKTsgIC8vIFN0YXJ0IGxleGljYWwgYW5hbHlzaXMKICAgIHJldHVybiAwOwp9Cg==