User:Thethakur09/sandbox

Vowel %{ int vowel=0; int cons=0; %} %% &quot;a&quot;|&quot;e&quot;|&quot;i&quot;|&quot;o&quot;|&quot;u&quot;|&quot;A&quot;|&quot;E&quot;|&quot;I&quot;|&quot;O&quot;|&quot;U&quot; {printf(&quot;is a VOWEL&quot;);vowel++;} [a-zA- z] {printf(&quot;Is a Consonant&quot;);cons++;} %% int yywrap { return 1; } main { printf(&quot;Enter String\n&quot;); yylex; printf(&quot;vowel=%d and Consonent=%d&quot;,vowel,cons); }
 * 1) include&lt;stdio.h&gt;

token %{ %} %% &quot;if&quot;|&quot;else&quot;|&quot;while&quot;|&quot;do&quot;|&quot;switch&quot;|&quot;case&quot; {printf(&quot;Keyword&quot;);} [a-zA- Z][a-z|0- 9]* {printf(&quot;Identifier&quot;);} [0-9]* {printf(&quot;Number&quot;);} &quot;!&quot;|&quot;@&quot;|&quot;*&quot;|&quot;&amp;&quot;|&quot;^&quot;|&quot;%&quot;|&quot;$&quot;|&quot;#&quot; {printf(&quot;Special Character&quot;);} %% int yywrap { return 1; } main { printf(&quot;Enter a string of data\n&quot;); yylex; } -- Caps(upper case/lowercase)
 * 1) include&lt;stdio.h&gt;

%{ int Upper=0; int Lower=0; %} %% [A-Z] {printf(&quot;Uppercase\t&quot;);Upper++;} [a-z] {printf(&quot;Lowercase\t&quot;);Lower++;} %% int yywrap { return 1; } main { printf(&quot;Enter a string\n&quot;); yylex; printf(&quot;Uppercase=%d and Lowercase=%d&quot;,Upper,Lower); }
 * 1) include&lt;stdio.h&gt;

- First and follow


 * 1) include
 * 2) include

int i,j,l,m,n=0,o,p,nv,z=0,x=0; char str[10],temp,temp2[10],temp3[20],*ptr;

struct prod {    char lhs[10],rhs[10][10],ft[10],fol[10]; int n; }pro[10];

void findter {    int k,t; for(k=0;k90 ) pro[i].ft[strlen(pro[i].ft)]=pro[k].rhs[t][0]; else if( pro[k].rhs[t][0]>=65 && pro[k].rhs[t][0]<=90 ) {                    temp=pro[k].rhs[t][0]; if(temp=='S') pro[i].ft[strlen(pro[i].ft)]='#'; findter; }            }             break; }    } }

void findfol {    int k,t,p1,o1,chk; char *ptr1; for(k=0;k=65 && pro[k].rhs[t][p1+1]<=90) {                    for(o1=0;o10) break; } }

int main {    FILE *f; //clrscr;

for(i=0;i<10;i++) pro[i].n=0;

f=fopen("tab5.txt","r"); while(!feof(f)) {        fscanf(f,"%s",pro[n].lhs); if(n>0) {            if( strcmp(pro[n].lhs,pro[n-1].lhs) == 0 ) {                pro[n].lhs[0]='\0'; fscanf(f,"%s",pro[n-1].rhs[pro[n-1].n]); pro[n-1].n++; continue; }        }         fscanf(f,"%s",pro[n].rhs[pro[n].n]); pro[n].n++; n++; }

printf("\n\nTHE GRAMMAR IS AS FOLLOWS\n\n"); for(i=0;i %s\n",pro[i].lhs,pro[i].rhs[j]);

pro[0].ft[0]='#'; for(i=0;i90 ) {                pro[i].ft[strlen(pro[i].ft)]=pro[i].rhs[j][0]; }            else if( pro[i].rhs[j][0]>=65 && pro[i].rhs[j][0]<=90 ) {                temp=pro[i].rhs[j][0]; if(temp=='S') pro[i].ft[strlen(pro[i].ft)]='#'; findter; }        }     }

printf("\n\nFIRST\n"); for(i=0;i ",pro[i].lhs); for(j=0;j=0;l--) if(pro[i].ft[l]==pro[i].ft[j]) break; if(l==-1) printf("%c",pro[i].ft[j]); }    }

for(i=0;i=65 && pro[l].rhs[j][p+1]<=90) {                        for(o=0;o ",pro[i].lhs); for(j=0;j=0;l--) if(pro[i].fol[l]==pro[i].fol[j]) break; if(l==-1) printf("%c",pro[i].fol[j]); }    }    printf("\n"); //getch; } -