Guys, apply simple logic. Detect all keywords( This program deal with a small number of keywods for sake of simplicity).
On detecting any keyword in C, convert it into uppercasr letter using the funtion 'toupper' . Game over!!
%{#include<stdio.h>
int i;
%}keyword main|int|scanf|printf|if|else
%%
{keyword} {
for(i=0;i<yyleng;i++)
printf("%c",toupper(yytext[i]));
}
%%
main()
{
yyin=fopen("num.c","r");
yylex();
}
int yywrap()
{
return 1;
}
OutputLet num.c contains following program fragment.
main()
{
int num;
scanf("%d",&num);
if(num%2)printf("Odd");
else printf("Even")
}
The output will be,
MAIN()
{
INT num;
SCANF("%d",&num);
IF(num%2)PRINTF("Odd");
ELSE PRINTF("Even")
}
4 comments :
error, undefined definion, keyword
in the first program what do we do to ignore the keyword given inside printf ? Eg : printf(" do u eat this");
hey there is error undefined definition keyword
for error , undefined definion, keyword
line "keyword main|int|scanf|printf|if|else" should be written in a new line.
Post a Comment