Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests - Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests -

Compiler Design GATE Questions

Compiler Design is an interesting topic covered in the GATE CSE Question Paper, and candidates are encouraged to solve and practise these Compiler Design GATE questions. Some of the main concepts that constitute the Compiler Design questions are Lexical Analysis, Code Generation and Optimization, Parsing and more. Candidates are also advised to refer to the collection of Compiler Design GATE Questions and Answers that we have compiled here in this article below.

Candidates can refer to these Compiler Design Questions and Answers for GATE, so that they will get the best results. Compiler Design is a crucial topic covered in the GATE CSE question paper. Solving these questions will help the candidates to prepare more proficiently for the GATE exams. Meanwhile, candidates can find the GATE Questions for Compiler Design in this article below to solve and practise thoroughly for the exams. They can refer to these GATE previous year question papers and start preparing for the exams.

Note: We shall be updating the answers/ solutions for these questions soon.

Compiler Design GATE Questions with Solutions

From The Compiler Design Topic of the GATE CSE Question Paper

MCQ- Single Answer Questions

1. Match the following:

LIST – I

LIST – II

(a)Lexical Analysis

(1) DAG’s

(b)Code Optimization

(2) Syntax trees

(c) Code Generation

(3) Push Down automata

(d) Abelian Group

(4) Finite automata

  1. a-4, b-1, c-2, d-3
  2. a-3, b-1, c-2, d-4
  3. a-4, b-2, c-1, d-3
  4. a-4, b-1,c-3, d-2

2. Look at these statements given below. Which of these are true?

I. A programming language that does not permit global variables of any kind and has no nesting of procedures/functions, but permits recursion can be implemented with static storage allocation

II. Multi-level access link (or display) arrangement is needed to arrange activation records only if the programming language being implemented has nesting of procedures/functions

III. Recursion in programming languages cannot be implemented with dynamic storage allocation

IV. Nesting procedures/functions and recursion require a dynamic heap allocation scheme and cannot be implemented with a stack-based allocation scheme for activation records

V. Programming languages which permit a function to return a function as its result cannot be implemented with a stack-based storage allocation scheme for activation records

  1. I, II and V only
  2. II only
  3. II, III and V only
  4. I, III and IV only

3. Choose the correct statement from the following.

  1. LALR parser is more powerful than canonical LR parser
  2. The parsers SLR, Canonical CR, and LALR have the same power
  3. SLR parser is more powerful than LALR
  4. Canonical LR parser is more powerful than LALR parser

4. A linker is assigned object modules for a set of programs that were compiled separately. So, what is the information that needs to be included in an object module?

  1. Absolute addresses of internal symbols
  2. Object code
  3. Relocation bits
  4. Names and locations of all external symbols defined in the object module

5. Take a look at the basic block given below.

a = b + c

c = a + d

d = b + c

e = d – b

a = e + b

In this basic block given above, the respective minimum number of nodes and edges present in the DAG representation are_____

  1. 4 and 4
  2. 6 and 6
  3. 8 and 10
  4. 9 and 12

6. Which are the languages that necessarily need heap allocation in the runtime environment?

  1. Those that allow dynamic data structures
  2. Those that support recursion
  3. Those that use dynamic scoping
  4. Those that use global variables

7. ________ is not an advantage of using shared, dynamically linked libraries as opposed to using statically linked libraries.

  1. Faster program setup
  2. Smaller sizes of executable files
  3. Existing programs need not be re-linked to take advantage of newer versions of libraries
  4. Lesser overall page fault in the system

8. What are the number of tokens that will be generated by the scanner for the below given statement?

x = x ∗ (a + b) – 5

  1. 7
  2. 10
  3. 11
  4. 12

9. What is the data structure in a compiler used for managing information about variables and their attributes?

  1. Symbol table
  2. Symbol tree
  3. Abstract syntax tree
  4. Semantic stack

10. When is the symbol table, generated in a two-pass assembler?

  1. Generated in second pass
  2. Generated and used only in second pass
  3. Generated in first pass
  4. Not generated at all

11. _______ phase of compiler generates stream of atoms.

  1. Code Generation
  2. Syntax analysis
  3. Code Optimisation
  4. Lexical Analysis

12. What is the kind of derivation used by LR parsers?

  1. Rightmost in reverse
  2. Leftmost in reverse
  3. Rightmost
  4. Leftmost

13. What is the output of a lexical analyser?

  1. Machine code
  2. A parse tree
  3. A stream of tokens
  4. Intermediate code

14. From the below given data: a b b a a b b a a b which is not a word in the dictionary created by LZ-coding (the initial words are a, b)?

  1. a b
  2. b a
  3. b a a b
  4. b b

15. ________ among these listed below is a top-down parser.

  1. An LR(k) parser
  2. Operator precedence parser
  3. An LALR(k) parser
  4. Recursive descent parser

16. One of the purposes of using intermediate code in compilers is to________

  1. improve error recovery and error reporting
  2. increase the chances of reusing the machine-independent code optimizer in other compilers
  3. Improve the register allocation
  4. make parsing and semantic analysis simpler

17. What is the least number of temporary variables required to create a three-address code in static single assignment form for the expression q+r/3+s−t∗5+u∗v/w?

18. Debugger is a programming language that______

  1. allows to set breakpoints, execute a segment of program and display contents of register
  2. allows to examine and modify the contents of register
  3. does not allow execution of a segment of program
  4. All the above

19. Which among these is required to convert an infix expression to the postfix form efficiently?

  1. An operand stack and an operator stack
  2. An operator stack
  3. An operand stack
  4. A parse tree

20. A CFG is not closed under ___________

  1. Concatenation
  2. Dot operation
  3. Iteration
  4. Union Operation

21. Which of the following is incorrect for the actions of A LR-Parser

I) shift s

ii) reduce A->ß

iii) Accept

iv) reject?

Only I)

  1. I) and ii)
  2. I), ii) , iii) and iv)
  3. I), ii) and iii)
  4. None of the above

22. Consider the grammar, E → E + n | E × n | n. For a sentence n + n × n, the handles in the right-sentential form of the reduction are________

  1. n, E+ n and E + n x n
  2. n, n + n and n + n x n
  3. n, E + n and E + E x n
  4. n, E + n and E x n

23. Which of the following grammar rules violate the requirements of an operator grammar ? P, Q, R are non-terminals, and r, s, t are terminals.

i) P → Q R

ii) P → Q s R

iii) P → ε

iv) P → Q t R r

(a) i) only

(b) i) and iii) only

(c) ii) and iii) only

(d) iii) and iv) only

24. Look at the following code segment.

x = u – t;

y = x * v;

x = y + w;

y = t – z;

y = x * y;

What is the minimum number of total variables required to convert the above code segment to static single assignment form?

25. Some code optimizations are carried out on the intermediate code because____

  1. program analysis is more accurate on intermediate code than on machine code
  2. the information from dataflow analysis cannot otherwise be used for optimisation
  3. they enhance the portability of the computer to other target processors
  4. the information from the front end cannot otherwise be used for optimisation

26. State if the given statement is true or false: R->R|T T->ε is an ambiguous grammar

(a) true

(b) false

27. If a state does not know whether it will make a shift operation or reduction for a terminal, it is _________

  1. Reduce/ Shift conflict
  2. Reduce conflict
  3. Shift/ reduce conflict
  4. Shift conflict

28. The construction of the canonical collection of the sets of LR (1) items and LR (0) items are similar. Which of these will be an exception?

  1. Closure and go to operations work similarly
  2. Closure and associatively operations work slightly different
  3. Closure and go to operations work slightly different
  4. Closure and additive operations slightly different

29. Which among these is the most powerful parsing method?

  1. LL(1)
  2. SLR
  3. LALR
  4. Canonical LR

30. Which of these classes of statements below usually produces no executable code when compiled?

  1. Input and output statements
  2. Declaration
  3. Assignment statements
  4. Structural statements

31. Which of these below given statements about peephole optimisation is true?

  1. It can be applied to a portion of the code that is not contiguous
  2. It is applied to a small part of the code and applied repeatedly
  3. It is applied in the symbol table to optimize the memory requirements
  4. It is applied to a small part of the code and applied repeatedly

32. Linking:

  1. cannot be performed after relocation
  2. is not required if relocation is performed
  3. cannot be performed before relocation
  4. can be performed both before and after relocation

33. In compiler terminology, what does reduction in strength mean?

  1. Removing common subexpressions
  2. Replacing run time computation by compile time computation
  3. Replacing a costly operation by a relatively cheaper one
  4. Removing loop invariant computation

34. What is the graph that shows basic blocks and their successor relationship, called as?

  1. Hamilton Graph
  2. Flow Graph
  3. DAG
  4. Control Graph

35. Loop unrolling is a code optimisation technique:

  1. That improves performance by decreasing the number of instructions in a basic block
  2. That reorders operations to allow multiple computations to happen in parallel
  3. That avoids tests at every iteration of the loop
  4. That exchanges inner loops with outer loops

36. Consider the grammar rule E → E1 – E2 for arithmetic expressions. The code generated is targeted to a CPU having a single user register. The subtraction operation requires the first operand to be in the register. If E1 and E2 do not have any common sub expression, in order to get the shortest possible code,___

  1. E2 should be evaluated first
  2. E1 should be evaluated first
  3. Order of evaluation of E1 and E2 is of no consequence
  4. )Evaluation of E1 and E2 should necessarily be interleaved

37. What is the identification of common sub-expression and replacement of runtime computations by compile-time computations?

  1. Data flow analysis
  2. Constant folding
  3. Loop optimisation
  4. Local optimisation

38. Who has the responsibility for code optimisation?

  1. Operating system
  2. Application programmer
  3. System programmer
  4. All of these

39. What is the dead- code elimination in machine code optimisation referred to?

  1. Removal of the values that never get used
  2. Removal of function which are not involved
  3. Removal of all labels
  4. Removal of a module after its use

40. Which of these below given operations are not performed during compilation?

  1. Type checking
  2. Dynamic memory allocation
  3. Inline expansion
  4. Symbol table management

41. Substitution of values for names who have constant values are done in_____

  1. Strength reduction
  2. Loop optimisation
  3. Constant folding
  4. Local optimisation

42. In which, are the bodies of the two loops merged together to form a single loop, provided that they do not make any references to each other?

  1. Loop Jamming
  2. Loop unrolling
  3. Strength reduction
  4. Loop concatenation

43. What is the maximum number of reduce moves that can be taken by a bottom-up parser for a grammar with no epsilon and unit-production (i.e., of type A→ϵ and A→a) to parse a string with n tokens?

  1. 2n-1
  2. n-1
  3. n/2
  4. 2n

44. The number of tokens in the Fortran statement DO 10 I = 1.25 is_____

  1. 3
  2. 4
  3. 5
  4. None of the above

45. Which one of the following statements is false?

  1. In un-typed languages, values do not have any types
  2. In statically typed languages, each variable in a program is associated with values of only a single type during the execution of the program
  3. In statically typed languages, each variable in a program has a fixed type
  4. In dynamically typed languages, variables have no types

46. Look at the below given statements :

S1 : The front end of compiler consists of Lexical analyser , Syntax analyser and semantic analyser.

S2 : Target code generator is known as the back-end of compiler.

S3 : Code optimizer is middle end of compiler and is a optional phase in compiler.

Which among these above given option is correct ?

  1. Only S1 and S2 are correct
  2. Only S1 and S3 are correct
  3. Only S2 and S3 are correct
  4. None of the above are correct

47. Which of the following menu types are also known as drop-down menus?

  1. Pull- down
  2. Cascading
  3. Fly-out
  4. Pop-up

48. Data is stored in computer as______

  1. Matter
  2. Files
  3. Floppies
  4. Directories

49. The register or the main memory location that contains the effective address of the operand is known as________

  1. special location
  2. pointer
  3. Indexed register
  4. Question does not provide sufficient data or is vague

50. What is object code the output of?

  1. Only assembler
  2. Only compiler
  3. Compiler or Assembler
  4. Operating system

Candidates are advised to download additional resources such as the GATE preparation materials or the GATE CSE previous year papers from BYJU’S. Stay tuned and access the updates when they go live!

Comments

Leave a Comment

Your Mobile number and Email id will not be published.

*

*