CC_Lab5
1 Mini-compiler (Version I)
1. In this, you are supposed to begin with your solution for the problem in Lab-04 (your modified project.y and project.l files). 2. Incorporate conditional operator (LOGICAL EXPRESSION)?{BODY } : {BODY } in your mini-compiler. 3. Incorporate the following loop constructs too. (a) while(LOGICAL EXPRESSION){BODY } (b) do{BODY }while(LOGICAL EXPRESSION); (c) for(A EXPN;LOGICAL EXPRESSION;A EXPN) {BODY } (A EXPN stands for arithmetic expression)
input1.c
#include<stdio.h>
int main()
{
int i;
int n;
int sum;
sum=0;
n=10;
for (i=1;i<=n;i++)
{
sum=sum+i;
}
}
input2.c
#include<stdio.h>
int main()
{
int i;
int n;
int sum;
int j;
sum=0;
n=10;
for(i=1;i<=n;i++)
{
j=i%2;
int e;
e=2;
if(j==0)
{
sum=sum+e^j;
}
}
}
input3.c
#include<stdio.h>
int main()
{
int i;
int n;
int sum;
int e;
int j;
sum=0;
i=1;
n=10;
e=2;
while(!(i>n))
{
j=i%2;
(j==0)?{sum=sum+e^j;}:{;}
i++;
}
}
input4.c
#include<stdio.h>
int main()
{
int i;
int n;
int sum;
int j;
sum=0;
n=10;
for (i=1;i<=n;i++)
{
j=i%2;
int e;
e=2;
if(j==0)
{
sum=sum+e^j;
}
}