CSC376 · TU past paper
Compiler Design and Construction 2076 question paper
The complete TU 2076 exam paper for Compiler Design and Construction (CSC376), all 10 questions with solved model answers written to the mark scheme.
Tap a question to open its answer.
- 16 marksCompiler StructureHideAnswer
Explain briefly about different phases involved in compiler, with a block diagram[6]
A compiler translates a source program written in a high-level language into an equivalent target program (usually machine code). This translation is carried out through a series of well-defined phases, grouped into two major parts: the ...
- 26 marksNumericalFinite Automata relevant to compiler constHideAnswer
Given a regular expression (ε+0)∗10(\varepsilon + 0)^* 10(ε+0)∗10. Construct the DFA recognizing the pattern described by this regular expression using syntax tree based reduction.[6]
Append the end marker : $$(\varepsilon+0)^ \cdot 1 \cdot 0 \cdot (\varepsilon+0)^ \cdot 1 \cdot 0 \cdot $$ Assign position numbers to terminal leaves ($\varepsilon$ leaves get none): Symbol Position ------------------ $0$ (first star) 1...
- 36 marksNumericalBottom-up parsingHideAnswer
What is shift reduce parsing techniques? Show shift reduce parsing action for the string (x+x)*a, given the grammar[6]
- String to parse: (x+x)a - Grammar: Not explicitly printed in the question (the phrase "given the grammar" appears but no production rules follow). The standard expression grammar suitable for this string is assumed and stated explicitl...
- 46 marksNumericalLR parsingHideAnswer
Construct SLR parsing table for the following grammar.S→aAa∣bAb∣baS \rightarrow aAa | bAb | baS→aAa∣bAb∣ba[6]
The grammar as given is: $$S \rightarrow aAa \mid bAb \mid ba$$ The nonterminal $A$ appears on the right-hand side but no productions for $A$ are given. A grammar with an undefined nonterminal is incomplete and cannot generate a language...
- 56 marksNumericalAnnotated Parse TreeHideAnswer
Syntax Directed Definition and Annotated Parse Tree
A Syntax-Directed Definition (SDD) is a context-free grammar in which each grammar symbol is associated with a set of attributes, and each production is associated with a set of semantic rules for computing the values of those attributes...
- 66 marksType Checking and ConversionHideAnswer
Write Syntax Directed Definition to carry out type checking for the following expression.E→id∣E1 op E2∣E1 relop E2∣E1[E2]∣E1↑E \rightarrow id | E1 \text{ op } E2 | E1 \text{ relop } E2 | E1[E2] | E1↑E→id∣E1 op E2∣E1 relop E2∣E1[E2]∣E1↑[6]
Type checking is a key part of semantic analysis. A Syntax-Directed Definition (SDD) associates attributes with grammar symbols and semantic rules with productions. For type checking, each expression E carries a synthesized attribute E.t...
- 76 marksIntermediate Code GeneratorHideAnswer
Explain with example about different methods of intermediate code representation.[6]
Intermediate code is a machine-independent representation of the source program, generated by the front end of the compiler and used as input to the back end (code optimization and code generation phases). It acts as a bridge between the...
- 86 marksCode OptimizationHideAnswer
What is the purpose of code optimization? Explain different types of loop optimization techniques with example.[6]
Code optimization is the process of improving the intermediate code so that the output program runs faster and takes less memory space. It removes unnecessary lines of code and arranges the sequence of statements to speed up program exec...
- 96 marksCode GeneratorHideAnswer
Discuss about the different factors affecting target code generation.[6]
Target code generation is the final phase of compilation that translates optimized intermediate code into target machine language. The quality and correctness of the generated code depends on several important factors. --- - The code gen...
- 106 marksBasic concepts related to Compiler such asHideAnswer
Discuss the importance of error handler in compiler. How is it manipulated in the different phases of compilation?[6]
During the compilation of a source program, errors can be encountered at any phase of compilation. An error handler is a component that is invoked whenever such an error is detected. Its importance can be summarized as follows: - It dete...