All questions of Compiler Design for Computer Science Engineering (CSE) Exam

Which languages necessarily need heap allocation in the runtime environment?
  • a)
    Those that support recursion .
  • b)
    Those that use dynamic scoping
  • c)
    Those that allow dynamic data structure
  • d)
    Those that use global variables
Correct answer is option 'C'. Can you explain this answer?

Sanya Agarwal answered
Runtime environment means we deal with dynamic memory allocation and Heap is a dynamic data structure.
So it is clear that those languages that allow dynamic data structure necessarily need heap allocation in the runtime environment.

Pick the functions which are completely performed in pass 1
  • a)
    Updating the location counter
  • b)
    Processing of EQU pseudo op
  • c)
    Processing of DS pseudo op
  • d)
    Ail of the above
Correct answer is option 'D'. Can you explain this answer?

Jatin Joshi answered
Operation performed during pass-1 in 2-pass compiler:
1. Processing the DB pseudo-op.
2. Updating the location counter.
3. Processing of EQU pseudo-op.
4. Processing of DS pseudo-op.

 MIMD stands for __________
  • a)
    Multiple instruction multiple data
  • b)
    Multiple instruction memory data
  • c)
    Memory instruction multiple data
  • d)
    Multiple information memory data
Correct answer is option 'A'. Can you explain this answer?

Abhiram Goyal answered
MIMD stands for Multiple Instruction Multiple Data.

Multiple Instruction Multiple Data (MIMD) is a type of parallel processing architecture in which multiple processors or cores execute different instructions on different data simultaneously. Each processor or core has its own instruction stream and data stream, allowing for independent execution of instructions.

Explanation:
MIMD is a parallel computing architecture that utilizes multiple processors or cores to execute different instructions on different data simultaneously. It is designed to achieve high-performance computing by dividing the workload among multiple processors and allowing them to work in parallel.

In MIMD architecture, each processor or core operates independently and has its own instruction stream and data stream. This means that each processor can execute different instructions on different data at the same time. This allows for simultaneous execution of multiple instructions, leading to faster processing and increased efficiency.

Advantages of MIMD architecture:
- Increased performance: MIMD architecture allows for parallel execution of multiple instructions on different data, which leads to faster processing and increased performance.
- Scalability: MIMD architecture can be scaled up by adding more processors or cores to the system, allowing for increased processing power as the workload demands.
- Flexibility: Each processor or core in a MIMD system can execute different instructions, making it suitable for a wide range of applications that require different types of computations.
- Fault tolerance: MIMD architecture provides redundancy by having multiple processors or cores. If one processor fails, the other processors can continue to operate, ensuring the system's reliability.

Examples of MIMD architecture:
- Multi-core processors: Modern CPUs often have multiple cores that can execute different instructions on different data simultaneously, making them MIMD architectures.
- Distributed computing systems: Systems that utilize multiple computers or servers to perform parallel processing tasks are also examples of MIMD architecture. Each computer or server can execute different instructions on different data, allowing for parallel processing.

In conclusion, MIMD stands for Multiple Instruction Multiple Data, which is a parallel computing architecture that utilizes multiple processors or cores to execute different instructions on different data simultaneously. This architecture provides increased performance, scalability, and flexibility, making it suitable for a wide range of applications.

A basic block can be analyzed by
  • a)
    DAG
  • b)
    A flow graph
  • c)
    A graph with cycles
  • d)
    None of the above
Correct answer is option 'A'. Can you explain this answer?

Amrutha Singh answered
Properties of a basic block are as follows: 

- The flow of control can only enter the basic block through the first instruction in the block. 

  • - No numps in the middle of the block.

  •  - Control leaves the block without halting/branching. 

  • - The basic blocks become the nodes of a flow graph, whose edges indicate which blocks can follow which other blocks.

Hence Option (A) is correct

For video on Intermediate code generation click on the link given below:

For a context-free grammar, FOLLOW(A) is the set of terminals that can appear immediately to the right of non-terminal A in some “sentential” form. We defined to sets LFOLLOW(A) and RFOLLOW(A) by replacing the word “left most sentential” and “right most sentential” respectively in the definition of FOLLOW(A).
Which of the following statements is/are tru
  • a)
    FOLLOW(A) and RFOLLOW(A) may be different.
  • b)
    FOLLOW(A) and RFOLLOW(A) are always the same.
  • c)
    All the three sets are identical.
  • d)
    All the three sets are different.
Correct answer is option 'C'. Can you explain this answer?

Sarthak Desai answered
Definition of Follow (A) as per question “The set of terminals that can appears immediately to the right of non-terminal A in same sentential form”. If the above definition is changed to replace “ sentential” with “ left-most sentential” for L FOLLOW (A) and “right-most sentential” for R FOLLOW (A)
We are still considering the terminal symbol to the right of A ’ .
Hence all three sets would be identical

Consider the following issues:
1. Simplify the phases.
2. Compiler efficiency is improved.
3. Compiler works faster.
4. Compiler portability is enhanced.
Which is/are true in context of lexical analysis?
  • a)
    1,2 and 3
  • b)
    1,3 and 4
  • c)
    1,2 and 4
  • d)
    All of these
Correct answer is option 'C'. Can you explain this answer?

Hiral Nair answered
Lexical analysis consists of the phases that
(i) Simplify the subsequent phases by the help of tokens instead of arbitrary elements.
(ii) Since interrelated elements are converted to stream of tokens hence compiler efficiency is improved as no arbitrary storage or value is to be checked independently.
(iii) Computer portability is enhanced.

A non relocatable program is one which
  • a)
    Cannot be made to execute in any area of storage other than the one designated for it at the time of its coding or translation.
  • b)
    Consists of a program and relevant information for its relocation.
  • c)
    Can itself perform the relocation of its address sensitive portions.
  • d)
    All of the above
Correct answer is option 'A'. Can you explain this answer?

Gargi Menon answered
The phases of compiler
1. Lexical
2. Syntax
3. Semantic
4. Intermediate code generation, are all machine dependent phases and are not relocatable.
The together make pass-1 of the compiler. This program hence can not be made to execute in any area of storage other than the one designated for it at the time of its coding or translation.

In a bottom-up evaluation of a syntax directed definition, inherited attributes can
  • a)
    Always be evaluated
  • b)
    Be evaluated only if the definition is L-attributed
  • c)
    Be evaluated only if the definition has synthesized attributes
  • d)
    Never be evaluated
Correct answer is option 'C'. Can you explain this answer?

Rajat Sharma answered
Every S(Synthesized) - attributed definition is L- attributed. For implementing inherited attributed during bottom-up parsing, extends to some, but not LR grammars. Consider the following example

In the example above the nonterminal L in L → E inherits the count of the number of 1 ’s generated by S. Since the production L → E is the first that a bottom- up parser would reduce by, the translator at the time can't know the number of 1 ’s in the input. So in a bottom-up evaluation of a syntax directed definition, inherits attributes can’t be evaluated if the definition is L-attributed in the given example. So we can say. that L-attributed definition is based on simple LR(1) grammar, but it can’t be implemented always but inherit attributes can be evaluated only if the definition has synthesized attributes.

If conversion from one type to another type is done automatically by the compiler then, it is called
  • a)
    Implicit conversion
  • b)
    Coercions 
  • c)
    Both (a) and (b)
  • d)
    None of these
Correct answer is option 'C'. Can you explain this answer?

Nishanth Roy answered
If compiler automatically converts one type of from to another type then it is called implicit conversion or coercions, else if not done automatically, then it is called explicit conversion.

 A floating point number that has an O in the MSB of mantissa is said to have__________
  • a)
    Overflow
  • b)
    Underflow
  • c)
    Important number
  • d)
    Undefined
Correct answer is option 'B'. Can you explain this answer?

Raj Datta answered
Underflow in Floating Point Numbers

Underflow is a condition in which a floating point number is too small to be represented in the given format. When a floating point number is too small, its magnitude is less than the minimum value that can be represented by its exponent. This condition is indicated by a special bit pattern in the exponent field of the floating point number's representation.

MSB of Mantissa with O

If a floating point number has an O in the MSB (most significant bit) of mantissa, it means that the number is very small and it cannot be represented accurately. In other words, the number is so small that it underflows the range of values that can be represented by the given format.

Overflow and Underflow

Overflow and underflow are two common problems that can occur in floating point calculations. Overflow occurs when a floating point number is too large to be represented in the given format. Underflow, on the other hand, occurs when a floating point number is too small to be represented in the given format.

Importance of Underflow

Underflow is an important issue in floating point calculations because it can lead to loss of precision and accuracy in the result. When a floating point number underflows, it is usually rounded to zero or the smallest representable value, which can result in significant errors in the final result.

Conclusion

In summary, a floating point number that has an O in the MSB of mantissa is said to have underflowed the range of values that can be represented by the given format. Underflow is an important issue in floating point calculations because it can lead to loss of precision and accuracy in the result.

Which is not true about syntax and semantic parts of a computer language
  • a)
    Syntax is generally checked by the programmer.
  • b)
    Semantics is the responsibility of the programmer.
  • c)
    Semantics is checked mechanically by a computer.
  • d)
    Both (b) and (c) above
Correct answer is option 'D'. Can you explain this answer?

Syntax analysis checks for the syntax of the source program while the semantic analysis, deals with checking of semantic (meaning) of the source program output by syntax analysis phase and input to semantic analysis phase.
Note: The syntax checking is responsibility of the programmer while semantic analys is is checked at the runtime.

Which one of the following statements is TRUE?
  • a)
    LR(1) parsing is sufficient for deterministic context-free languages
  • b)
    Data flow analysis is necessary for run-time memory management.
  • c)
    Symbol table is accessed only during the lexical analysis phase
  • d)
    The LALR(1) parser for a grammar G cannot have reduce-reduce conflict if the LR(1) parser for G does not have reduce-reduce conflict. 
Correct answer is option 'A'. Can you explain this answer?

Varun Khanna answered
Understanding LR(1) Parsing
LR(1) parsing is a type of bottom-up parsing technique widely used in compiler design. It can parse a larger class of deterministic context-free languages than many other parsing techniques.
Why is Option A True?
- Sufficient for Deterministic Context-Free Languages:
- LR(1) parsers can handle all deterministic context-free languages, meaning they can uniquely parse strings based on grammar with a single lookahead token.
- The "1" in LR(1) indicates that the parser uses one lookahead token to make parsing decisions, making it versatile and powerful.
Analyzing Other Options
- Option B - Data Flow Analysis:
- While useful for optimizing compilers, it is not necessary for run-time memory management. Memory management often involves allocation and deallocation rather than data flow analysis.
- Option C - Symbol Table Access:
- Symbol tables are utilized during various stages of compilation, including syntax analysis and semantic analysis, not just lexical analysis.
- Option D - LALR(1) Parser:
- LALR(1) parsers can have reduce-reduce conflicts even if the LR(1) parser does not. This is because LALR(1) combines states that can lead to ambiguities not present in the LR(1) version.
Conclusion
The correct answer is Option A, as LR(1) parsing is indeed sufficient for all deterministic context-free languages, making it a robust choice for parsing in compiler design.

Generation of intermediate code based on an abstract machine model is useful in compilers because
  • a)
    It makes implementation of lexical analysis and syntax analysis easier.
  • b)
    Syntax-directed translations can be written for intermediate code generation.
  • c)
    It enhances the portability of the front end of the compiler.
  • d)
    It is not possible to generate code for real machines directly from high level language programs
Correct answer is option 'C'. Can you explain this answer?

Shubham Chawla answered
Explanation:

Intermediate code is code that is generated by a compiler between the source code and the target code. It is an abstraction of the target machine's code and is used to make it easier to translate the source code into machine code. The intermediate code is generally optimized and platform-independent, which makes it easier to port the compiler front end to different platforms.

The use of an abstract machine model in the generation of intermediate code has several advantages:

1. Easier implementation of lexical analysis and syntax analysis: The abstract machine model provides a simplified representation of the target machine's instruction set, making the implementation of the lexical and syntax analysis stages of the compiler easier.

2. Syntax-directed translations: Intermediate code generation can be done using syntax-directed translation techniques, which facilitates the construction of compilers.

3. Enhanced portability: The use of intermediate code makes it easier to port the front end of the compiler to different platforms. Since the intermediate code is platform-independent, only the back end of the compiler needs to be modified to generate code for different target machines.

4. Direct generation of code for real machines: Although it is possible to generate code for real machines directly from high-level language programs, the use of an abstract machine model provides a layer of abstraction that makes the process easier and more efficient.

Therefore, option C is the correct answer.

An LALR(1) parser for a grammar G can have shift-reduce (S-R) conflicts if and only if
  • a)
    The SLR(1) parser for G has S-R conflicts.
  • b)
    The LR(1) parser for G has S-R conflicts
  • c)
    The LR(0) parser for G has S-R conflicts.
  • d)
    The LALR(1) parser for G has reduce-reduce conflicts.
Correct answer is option 'B'. Can you explain this answer?

Snehal Desai answered
LALR(1) parser for a grammar, G can have shift- reduce ( S - R) conflicts if and only if there is a S - R conflict in its immediate sub-parsers (e.g. LR(1)). If LR(0) has S - R conflicts then they may get removed in LR (1), hence there will be no S - R conflict in LALR(1).

Chapter doubts & questions for Compiler Design - Question Bank for GATE Computer Science Engineering 2025 is part of Computer Science Engineering (CSE) exam preparation. The chapters have been prepared according to the Computer Science Engineering (CSE) exam syllabus. The Chapter doubts & questions, notes, tests & MCQs are made for Computer Science Engineering (CSE) 2025 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests here.

Chapter doubts & questions of Compiler Design - Question Bank for GATE Computer Science Engineering in English & Hindi are available as part of Computer Science Engineering (CSE) exam. Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.

Signup to see your scores go up within 7 days!

Study with 1000+ FREE Docs, Videos & Tests
10M+ students study on EduRev