Category Archives: Compiler

Find Execution time of your own Program

#include<stdio.h>
#include<time.h>

/*
The C library function clock_t clock(void) returns the number
of clock ticks elapsed since the program was launched.
To get the number of seconds used by the CPU, you will
need to divide by CLOCKS_PER_SEC.

*/


int main() {
clock_t start, end;
double total;
int i,j;
start = clock();
int c;
for (i = 0; i < 100; i++) {
for (j = 0; j < 100; j++) {
c++;
}
}

end = clock();
printf("start = %d, end = %d\n", start, end);
printf("\nTotal = %ld",end-start);

return 0;
}

Follow set of Given Grammer

#include<stdio.h>
#include<string.h>

int len=0,p,i,n,j;
char prod[10][10],c,fset[10];
void follow(char c);
void first(char c);

int main()
{
int i;
char ch;
printf("Enter The No. Of Productions:\n");
scanf("%d",&n);
printf("Enter The Productions:\n { Epsilon = # }\n");
for(i=0;i<n;i++)
{
scanf("%s",prod[i]);
}

printf("\nProductions are:\n");
for(i=0;i<n;i++)
{
printf("\t%s\n",prod[i]);
}

printf("\nWhose Follow you want to find:\n");
scanf("\n%c",&ch);
follow(ch);
printf("Follow of %c is : { ",ch);
for(i=0;i<len;i++)
{
printf("%c ",fset[i]);
}
printf("}\n");

return 0;
}

void follow(char c)
{
if(prod[0][0]==c)
fset[len++]='$';
for(i=0;i<n;i++)
{
for(j=2;j<strlen(prod[i]);j++)
if(prod[i][j]==c)
{
if(prod[i][j+1]!='\0')
first(prod[i][j+1]);

else if(prod[i][j+1]=='\0' && prod[i][0]!=c)
follow(prod[i][0]);
}
}
}

void first(char c)
{

if(!(isupper(c)))
fset[len++]=c;

for(p=0;p<n;p++)
{
if(prod[p][0]==c)
{
if(prod[p][2]=='#')
follow(prod[i][0]);
else if(islower(prod[i][2]))
fset[len++]=prod[p][2];
else first(prod[p][2]);
}
}
}

First &amp; Follow