Professional Documents
Culture Documents
College Code-802
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
int main() {
int i=0,j=0,x=0,flag=0,n;
void *p, *add[15];
char c, ch, srch, b[15],d[15],g[10];
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
int main() {
char s[50],c;
int state=0,i=0;
while(s[i]!='\0') {
switch(state) {
case 0:
c=s[i++];
if(c=='a') state=1;
else if(c=='b') state=2;
else state=6;
break;
case 1:
c=s[i++];
if(c=='a')
state=3;
else if(c=='b')
state=4;
else
state=6;
break;
case 2:
c=s[i++];
if(c=='a')
state=6;
Roll No: 2108020100001
NITRA TECHNICAL CAMPUS, GHAZIABAD
College Code-802
else if(c=='b')
state=2;
else
state=6;
break;
case 3:
c=s[i++];
if(c=='a')
state=3;
else if(c=='b')
state=2;
else
state=6;
break;
case 4:
c=s[i++];
if(c=='a')
state=6;
else if(c=='b')
state=5;
else
state=6;
break;
case 5:
c=s[i++];
if(c=='a')
state=6;
else if(c=='b')
state=2;
else
state=6;
break;
case 6:
printf("\n %s is not recognised.",s);
exit(0);
}
}
Output:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
int main() {
int flag,i=1,m;
char a[10], s[32][10]=
{"if","else","goto","continue","return","auto","double",
"int","struct", "break","long","switch","case","enum",
"register","typedef","char","extern","union","const",
"float","short","unsigned","sizeof","volatile","for",
"signed","void","default","do","static","while"
};
} else
printf("\n It is a keyword, So it can't be an identifier");
getch();
}
Output:
#include <stdio.h>
#include <conio.h>
struct process
{
int pid;
int btime;
int wtime;
int ttime;
} p[10];
int main() {
int i,j,k,n,ttur,twat;
float awat,atur;
p[0].wtime = 0;
ttur = twat = 0;
awat = (float)twat / n;
atur = (float)ttur / n;
printf("\n\nGANTT Chart\n");
printf("-");
printf("\n");
printf("-");
printf("\n");
printf("0");
getch();
return 0;
}
Output:
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main() {
char str[200],ch;
int a=0,space=0,newline=0;
Output:
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main() {
char ch[80];
int i=0, length, ter=0;
printf("Enter the if statement syntax (Press ESC to terminate your
expression) : \n");
while(ter!=27) {
ch[i]=getchar();
ter=(int)ch[i];
i++;
}
length = i;
if(ch[0]=='i'&&ch[1]=='f'&&ch[2]=='('&&ch[length-2]=='}'||
ch[length-3]=='}') {
for(i=3; i<length-1; i++) {
if(ch[i]==')'&&ch[i+1]=='{'||ch[i+2]=='{' || ch[i+3]=='{')
{
i=1000;
break; }}}
if(i==1000)
printf("\n\tYour if statement syntax is correct\n");
else
printf("\nWrong Syntax...!!!");
getch();
}
Output:
#include<stdio.h>
#include<ctype.h>
void FIRST(char[],char );
void resultSet(char[],char);
int nop;
char proSet[10][10];
int main() {
int i;
char choice;
char c;
char result[20];
printf("Enter the Number of Production in Grammar ::");
scanf(" %d",&nop);
printf("\nEnter productions in form of S=A+B and for Epsilon A=$ \
n");
for(i=0; i<nop; i++) {
printf("Enter productions Number %d : ",i+1);
scanf(" %s",proSet[i]);
}
do {
printf("\n Find the FIRST of :");
scanf(" %c",&c);
FIRST(result,c);
printf("\n FIRST(%c)= { ",c);
for(i=0; result[i]!='\0'; i++)
printf(" %c ",result[i]);
printf("}\n");
printf("press 'y' to continue : ");
scanf(" %c",&choice);
} while(choice=='y'||choice =='Y');
}
Roll No: 2108020100001
NITRA TECHNICAL CAMPUS, GHAZIABAD
College Code-802
void FIRST(char* Result,char c) {
int i,j,k;
char subResult[20];
int foundEpsilon;
subResult[0]='\0';
Result[0]='\0';
if(!(isupper(c))) {
resultSet(Result,c);
return ;
}
if(proSet[i][0]==c) {
if(proSet[i][2]=='$')
resultSet(Result,'$');
else {
j=2;
while(proSet[i][j]!='\0') {
foundEpsilon=0;
FIRST(subResult,proSet[i][j]);
for(k=0; subResult[k]!='\0'; k++)
resultSet(Result,subResult[k]);
for(k=0; subResult[k]!='\0'; k++)
if(subResult[k]=='$') {
foundEpsilon=1;
break;
}
if(!foundEpsilon)
break;
j++;
}
}
}
}
Output:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int n,m=0,p,i=0,j=0;
char a[10][10],followResult[10];
void follow(char c);
void first(char c);
void addToResult(char);
int main() {
int i;
int choice;
char c,ch;
printf("Enter the no.of productions: ");
scanf("%d", &n);
printf(" Enter %d productions\nProduction with multiple terms should
be give as separate productions \n", n);
for(i=0; i<n; i++)
scanf("%s%c",a[i],&ch);
// gets(a[i]);
do {
m=0;
printf("Find FOLLOW of -->");
scanf(" %c",&c);
follow(c);
printf("FOLLOW(%c) = { ",c);
for(i=0; i<m; i++)
printf("%c ",followResult[i]);
printf(" }\n");
printf("Do you want to continue(Press 1 to continue....)?");
scanf("%d%c",&choice,&ch);
} while(choice==1);
}
void follow(char c) {
if(a[0][0]==c)addToResult('$');
for(i=0; i<n; i++) {
for(j=2; j<strlen(a[i]); j++) {
if(a[i][j]==c) {
if(a[i][j+1]!='\0')first(a[i][j+1]);
if(a[i][j+1]=='\0'&&c!=a[i][0])
Roll No: 2108020100001
NITRA TECHNICAL CAMPUS, GHAZIABAD
College Code-802
follow(a[i][0]);
}
}
}
}
void first(char c) {
int k;
if(!(isupper(c)))
//f[m++]=c;
addToResult(c);
for(k=0; k<n; k++) {
if(a[k][0]==c) {
if(a[k][2]=='$') follow(a[i][0]);
else if(islower(a[k][2]))
//f[m++]=a[k][2];
addToResult(a[k][2]);
else first(a[k][2]);
}
}
}
void addToResult(char c) {
int i;
for( i=0; i<=m; i++)
if(followResult[i]==c)
return;
followResult[m++]=c;
}
Output:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
char ip_sym[15],stack[15];
int ip_ptr=0,st_ptr=0,len,i;
char temp[2],temp2[2];
char act[15];
void check();
int main() {
Output:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
char next;
void E(void);
void T(void);
void S(void);
void F(void);
void error(int);
void scan(void);
void enter(char);
void leave(char);
void spaces(int);
int level = 0;
int main() {
printf("Enter the string:: ");
scan();
E();
if (next != '#') error(1);
else printf("Successful parse\n");
}
void T(void) {
enter('T');
S();
while (next == '*' || next == '/') {
scan();
S();
}
leave('T');
}
void S(void) {
enter('S');
F();
if (next == '^') {
scan();
S();
}
leave('S');
}
Output: