_ap_ufes{"success":true,"siteUrl":"techblix.com","urls":{"Home":"http://techblix.com","Category":"http://techblix.com/category/3g-4g-plans/","Archive":"http://techblix.com/2017/02/","Post":"http://techblix.com/use-reliance-jio-4g-sim-3g-devices-tricks-proven-work-jio-4g-sim/","Page":"http://techblix.com/guestsponsored-posts/","Attachment":"http://techblix.com/use-reliance-jio-4g-sim-3g-devices-tricks-proven-work-jio-4g-sim/j43g-10/","Nav_menu_item":"http://techblix.com/indianist-2/","Wpcf7_contact_form":"http://techblix.com/?post_type=wpcf7_contact_form&p=5633","Wysijap":"http://techblix.com/?wysijap=subscriptions","Feedback":"http://techblix.com/?post_type=feedback&p=7777","Safecss":"http://techblix.com/?safecss=safecss"}}_ap_ufee
Breaking News

TCS CodeVita previous years questions solved – Compiler Design

TCS CodeVita2014 Round 1 question

TCS CodeVita previous years questions

 

Problem : Compiler Design – Limit the Method Instructions

Raj is a newbie to the programming and while learning the programming language he came to know the following rules:

–         Each program must start with ‘{‘ and end with ‘}’.

–         Each program must contain only one main function. Main function must start with ‘<‘ and end with ‘>’.

–         A program may or may not contain user defined function(s). There is no limitation on the number of user defined functions in the program. User defined function must start with ‘(‘ and end with ‘)’.

–         Loops are allowed only inside the functions (this function can be either main function or user defined function(s)). Every loop must start with ‘{‘ and end with ‘}’.

–         User defined function(s) are not allowed to be defined inside main function or other user defined function(s).

–         Nested loops are allowed.

–         Instructions can be anywhere inside the program.

–         Number of instructions inside any user defined function must not be more than 100.

If any of the above conditions is not satisfied, then the program will generate compilation errors. Today Raj has written a few programs, but he is not sure about the correctness of the programs. Your task is to help him to find out whether his program will compile without any errors or not.

Input Format:

First line starts with T, number of test cases. Each test case will contain a single line L, where L is a program written by Raj.

Output Format:

Print “No Compilation Errors” if there are no compilation errors, else print “Compilation Errors”.


Constraints:


1<=T<=100


L is a text and can be composed of any of the characters {, }, (, ), <, >and P, where P will represents the instruction.


L, comprised of characters mentioned above should be single spaced delimited.

Number of characters in the text, |L| < = 10000
Sample Input and Output

SNo. Input Output
1 3
{ < > ( P ) }
{ < { } > ( { } ) )
{ ( { } ) }
No Compilation Errors
Compilation Errors
Compilation Errors

 

Note:

Please do not use package and namespace in your code. For object oriented languages your code should be written in one class.

Note:

Participants submitting solutions in C language should not use functions from / as these files do not exist in gcc

 

TCS CodeVita previous years questions – Compiler Design solution

Sample Solution in C Programming:

#include<stdio.h>
int main()
{
int T;
char arr[100][10000];
scanf(“%d”,&T);
while(T>0)
{
int i,length,e=0,mf=0,nmf=0,uf=0,l=0;
scanf(“%s”,arr[T]);
length=strlen(arr[T]);
if(arr[T][0]!='{‘ || arr[T][length-1]!=’}’)
e++;
for(i=1;i<length-1;i++)
{
if(arr[T][i]=='<‘ && mf==0 && uf==0 && l==0)
{
mf++;
nmf++;
}
else if(arr[T][i]==’>’ && mf==1 && uf==0 && l==0)
mf–;
else if(arr[T][i]=='(‘ && mf==0 && uf==0 && l==0)
uf++;
else if(arr[T][i]==’)’ && mf==0 && uf==1 && l==0)
uf–;
else if(arr[T][i]=='{‘ && (mf==1 || uf==1))
l++;
else if(arr[T][i]==’}’ && l>0 && (mf==1 || uf==1))
l–;
else if(arr[T][i]==’P’);
else
e++;
}
if(e!=0 || uf!=0 || mf!=0 || nmf=1 || l!=0)
printf(“\nCompilation Error\n”);
else
printf(“\nNo Compilation Error\n”);
T–;
}
return 0;
}

 

/* use of variables:

T-numer of test cases

length- length of the test case

arr[][]-storing test cases (single dimension array also satisfy the question)

uf- count of < & > (checking main functions presence)

nmf- count of < (checking main function is present only once)

uf- count of ( & ) (checking user function creation)

l- count of { & } ( checking loops)

e-compilation error

validate the constraints too

*/

Note: contact us if u need more clarifications or finds any error in the code

** check other important tcs codevita previous questions solved

Check Also

reliance jio logo

How to use Reliance Jio 4G SIM on 3G devices

Use Jio 4G SIM on 3G devices – 100% tested The main issue with Reliance Jio …

Leave a Reply

error: Right Click is Disabled !!