Professional Documents
Culture Documents
%{
#include<stdio.h>
#include<stdlib.h>
int com=0;
%}
%%
"//"[^\n]+"//" {com++;}
"//".* {com++;}
%%
int main()
yyin = fopen("Source.c","r");
yyout = fopen("Destination.c","w");
yylex();
fclose(yyin);
fclose(yyout);
}
Experiment 6b
%{
#include<stdio.h>
#include<stdlib.h>
#include"y.tab.h"
%}
%%
%%
%{
#include<stdio.h>
#include<stdlib.h>
int yylex();
int id=0,op=0,key=0;
%}
%token ID OP KEY
%%
prog: ID prog{++id;}
|OP prog{++op;}
|KEY prog{++key;}
|ID {++id;}
|OP{++op;}
|KEY{++key;}
%%
extern FILE*yyin;
int main()
yyin = fopen("Source.c","r");
yyparse();
printf("Identifier : %d\n",id);
printf("Operator :%d\n",op);
printf("Keyword : %d\n",key);
return 0;
exit(0);