%{
/* This LEX program returns the tokens for the expression */
#include "y.tab.h"
%}
%%
"
="
{printf
("\n Operator
is EQUAL"
);}"
+"
{printf
("\n Operator
is PLUS"
);}"
-"
{printf
("\n Operator
is MINUS"
);}"
/"
{printf
("\n Operator
is DIVISION"
);}"
*"
{printf
("\n Operator
is MULTIPLICATION"
);}[a-zA-Z]*[0-9]* {
printf
("\n Identifier
is %s",yytext);return ID; }
. return yytext[0];
\n return 0;
%%
int yywrap()
{
return 1;
}
Program name:ex3.y
%{
#include<stdio.h>
/* This YACC program is for recognizing the Expression */
%}
%token A ID
%%
statement: A'='E
| E {
printf("\n Valid arithmetic expression");
$$=$1;
}
;
E: E'+'ID
| E'-'ID
| E'*'ID
| E'/'ID
| ID
;
%%
extern FILE*yyin;
main() {
do {
yyparse();
}while(!feof(yyin)); }
yyerror(char*s)
{
}
JXsKLyogVGhpcyBMRVggcHJvZ3JhbSByZXR1cm5zIHRoZSB0b2tlbnMgZm9yIHRoZSBleHByZXNzaW9uICovCiNpbmNsdWRlICJ5LnRhYi5oIgolfQolJQoiPSIge3ByaW50ZigiXG4gT3BlcmF0b3IgaXMgRVFVQUwiKTt9CiIrIiB7cHJpbnRmKCJcbiBPcGVyYXRvciBpcyBQTFVTIik7fQoiLSIge3ByaW50ZigiXG4gT3BlcmF0b3IgaXMgTUlOVVMiKTt9CiIvIiB7cHJpbnRmKCJcbiBPcGVyYXRvciBpcyBESVZJU0lPTiIpO30KIioiIHtwcmludGYoIlxuIE9wZXJhdG9yIGlzIE1VTFRJUExJQ0FUSU9OIik7fQpbYS16QS1aXSpbMC05XSogewpwcmludGYoIlxuIElkZW50aWZpZXIgaXMgJXMiLHl5dGV4dCk7CnJldHVybiBJRDsgfQouIHJldHVybiB5eXRleHRbMF07ClxuIHJldHVybiAwOwolJQppbnQgeXl3cmFwKCkKewpyZXR1cm4gMTsKfQpQcm9ncmFtIG5hbWU6ZXgzLnkKJXsKI2luY2x1ZGU8c3RkaW8uaD4KLyogVGhpcyBZQ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