SSlabProgram 6
SSlabProgram 6
%{
#include<stdio.h>
int sl=0;
int ml=0;
%}
%%
"//".* sl++;
%%
main()
{
yyin=fopen("f1.c","r");
yyout=fopen("f2.c","w");
yylex();
fclose(yyin);
fclose(yyout);
f1.c
#include<stido.h>
int main()
// this is a comment
printf("hello");
#include <stdio.h>
#include "y.tab.h"
extern yylval;
%}
%%
[ \t];
[+|-|*|/|=|<|>] {printf("operator is %s\n",yytext);return OP;}
int|char|bool|float|void|for|do|while|if|else|return|void
{printf("keyword is %s\n",yytext);return KEY;}
. ;
%%
lab6.y
%{
#include <stdio.h>
#include <stdlib.h>
%}
%%
input:
| ID input { id++; }
| OP input {op++;}
| DIGIT { dig++; }
| ID { id++; }
| KEY { key++; }
| OP { op++;}
%%
#include <stdio.h>
main()
if (!myfile)
return -1;
yyin = myfile;
do{
yyparse();
}while (!feof(yyin));
void yyerror()
{
exit(-1);
inputfile.txt
#include<stdio.h>
int main()
int a ;
int b ;
a = 1 ;
b = 2 ;
a = a+b;
return 0 ;