%{
#include <stdio.h>
#include <ctype.h>
int isValid = 1;
%}
%%
[ \t\n]+ ;
[a-zA-Z][a-zA-Z0-9]* { printf("Identifier: %s\n", yytext); }
"+"|"-"|"*"|"/" { printf("Operator: %s\n", yytext); }
[0-9]+
"=" { printf("Assignment: %s\n", yytext); }
. { isValid = 0; }
%%
int main(void) {
printf("Enter an arithmetic expression:\n");
yylex();
if (isValid) {
printf
("The expression
is valid
.\n"
); } else {
printf
("The expression
is invalid
.\n"
); }
return 0;
}
int yywrap() {
return 1;
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxjdHlwZS5oPgoKaW50IGlzVmFsaWQgPSAxOyAKJX0KCiUlClsgXHRcbl0rICAgICAgICAgICAgICAgOwpbYS16QS1aXVthLXpBLVowLTldKiAgIHsgcHJpbnRmKCJJZGVudGlmaWVyOiAlc1xuIiwgeXl0ZXh0KTsgfQoiKyJ8Ii0ifCIqInwiLyIgICAgICAgIHsgcHJpbnRmKCJPcGVyYXRvcjogJXNcbiIsIHl5dGV4dCk7IH0KWzAtOV0rICAgICAgICAgICAgICAgIAoiPSIgICAgICAgICAgICAgICAgICAgIHsgcHJpbnRmKCJBc3NpZ25tZW50OiAlc1xuIiwgeXl0ZXh0KTsgfQouICAgICAgICAgICAgICAgICAgICAgIHsgaXNWYWxpZCA9IDA7IH0KJSUKCmludCBtYWluKHZvaWQpIHsKICAgIHByaW50ZigiRW50ZXIgYW4gYXJpdGhtZXRpYyBleHByZXNzaW9uOlxuIik7CiAgICB5eWxleCgpOwoKICAgIGlmIChpc1ZhbGlkKSB7CiAgICAgICAgcHJpbnRmKCJUaGUgZXhwcmVzc2lvbiBpcyB2YWxpZC5cbiIpOwogICAgfSBlbHNlIHsKICAgICAgICBwcmludGYoIlRoZSBleHByZXNzaW9uIGlzIGludmFsaWQuXG4iKTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQoKaW50IHl5d3JhcCgpIHsKICAgIHJldHVybiAxOwp9