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”.



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



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


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:

int main()
int T;
char arr[100][10000];
int i,length,e=0,mf=0,nmf=0,uf=0,l=0;
if(arr[T][0]!='{‘ || arr[T][length-1]!=’}’)
if(arr[T][i]=='<‘ && mf==0 && uf==0 && l==0)
else if(arr[T][i]==’>’ && mf==1 && uf==0 && l==0)
else if(arr[T][i]=='(‘ && mf==0 && uf==0 && l==0)
else if(arr[T][i]==’)’ && mf==0 && uf==1 && l==0)
else if(arr[T][i]=='{‘ && (mf==1 || uf==1))
else if(arr[T][i]==’}’ && l>0 && (mf==1 || uf==1))
else if(arr[T][i]==’P’);
if(e!=0 || uf!=0 || mf!=0 || nmf=1 || l!=0)
printf(“\nCompilation Error\n”);
printf(“\nNo Compilation Error\n”);
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

Your email address will not be published. Required fields are marked *

error: Right Click is Disabled !!