-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrgm 11(CD)
91 lines (76 loc) · 1.68 KB
/
Prgm 11(CD)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int parsecondition(char[],int,char* int)
void gen(char[],char[],char[],int)
int main()
{
int counter=0,stlen=0,else flag=0;
char stmt[60];
char strB[54];
char strs1[50];
char strs2[45];
clrscr();
printf("Format of if statement\n");
printf("if(a<b) then (s=a)\n");
printf("Enter the statement\n");
gets(stmt);
stlen=strlen(stmt);
countr=parsecondition(stmt,counter,strs1,stlen);
if(stmt[counter+1]=';')
{
printf("Parsing the i/n statement");
gen(strB,strs1,strs2,else flag);
getch();
return 0;
}
if(stmt[counter]==')')
counter++;
counter=counter+3;
counter=parsecondition(stmt,counter,strs2,stlen);
counter=counter+2;
if(counter==stlen)
{
else flag=1;
printf("Parsing the input statement");
gen(strB,strs1,else flag,strs2);
getch();
rteurn 0;
}
return 0;
}
int parsecondition(char input[],int cntr,char*dest,int totallen)
{
int index=0,pos=0;
while(input[cntr]!=(&& cntr<=totallen)
cntr++;
if(cntr>=totallen)
return 0;
index=cntr;
while(input[cntr]!=')')
cntr++;
if(cntr>=totallen)
return 0;
while(inde<=cntr)
dest+[pos++]=input[index++];
dest[pos]='\0';
return 0;
}
void gen(charB[],chars1[],chars2[],int elsepart)
{
int Bt=101,Bf=102,Sn=103;
printf("If %s goto %d",B,Bt);
printf("If %s goto %d",B,Bt);
printf("%d:",Bt);
printf("%s",s1);
if(!elsepart)
{
printf("%d:",Bf);
}
else
{
printf("\n\t %d",Sn);
printf("%d:%s",Bf,S2)
printf("%d:",Sn);
}
}