All Exams Test series for 1 year @ ₹349 only
Question

Which of the following tasks could be attained using syntax trees in compiler design ?

(A) Type Checking

(B) Code Generation

(C) Code Optimization

(D) Error Handling

Choose the correct answer from the options given below :

This question was previously asked in
UGC NET 2024 Computer Science and Applications Question Paper (23-Aug-2024) (Shift 1)
The correct answer is

(A), (B), (C) Only

A syntax tree (abstract syntax tree) is the condensed parse tree produced at the end of syntax analysis. Each interior node is an operator and its children are operands, and it is the main data structure passed to the later phases of the compiler.

(A) Type checking is done on the syntax tree: the semantic analyser walks it, attaches types to nodes and checks that operators receive compatible operands.

(B) Code generation can be driven directly by the syntax tree: a post-order traversal emits three-address code or target instructions for each node.

(C) Code optimisation uses it: constant folding, common sub-expression detection (turning the tree into a DAG) and algebraic simplification are performed on tree nodes.

(D) Error handling is not a task the syntax tree is built for; syntax errors are detected and recovered from by the parser while the tree is still being constructed, so this is not counted among the tasks achieved using the tree.

So type checking, code generation and code optimisation are the tasks; choices including error handling or dropping type checking are wrong.

(A), (B), (C) Only option is correct.

Was this answer helpful?

Similar Questions

  1. Which of the following statement(s) are correct?

    A. Syntax Directed Translation can be applied in Type Checking.

    B. Syntax Directed Translation can be used in 3-address code generation.

    C. Syntax Directed Translation can be used in construction of syntax tree.

    D. Syntax Directed Translation can be used to recognize valid tokens.

    Choose the most appropriate answer from the options given below:


Important Questions from Syntax Directed Translation

  1. Given the following syntax directed translation rules:
    Rule 1: $R \to AB$ {$B. i = R. i - 1$; $A. i = B. i$; $R. i = A. i + 1$; }
    Rule 2: $P \to CD$ {$P.i = C.i + D.i$; $D. i = C. i + 2$; }
    Rule 3: $Q \to EF$ {$Q.i = E.i + F. i$; }
    Which ONE is the CORRECT option among the following?
  2. In which graph, semantic rules set up dependencies between attributes ?
  3. COMPILER is used to?

  4. Consider the following two syntax-directed definitions SDD1 and SDD2 for type declarations.

    SDD1
    Grammar (G1)Semantic Rules
    $D \rightarrow T\ V$$D.type = T.type$
    $V.type = T.type$
    $T \rightarrow int$$T.type = int$
    $T \rightarrow float$$T.type = float$
    $V \rightarrow V_1\ id$$V_1.type = V.type$
    $put(id.entry, V.type)$
    $V \rightarrow id$$put(id.entry, V.type)$

    SDD2
    Grammar (G2)Semantic Rules
    $D \rightarrow D_1\ id$$D.type = D_1.type$
    $put(id.entry, D_1.type)$
    $D \rightarrow T\ id$$D.type = T.type$
    $put(id.entry, T.type)$
    $T \rightarrow int$$T.type = int$
    $T \rightarrow float$$T.type = float$

    $D$ is the start symbol, and $int$, $float$ and $id$ are the three terminals. The non-terminal $V_1$ is the same as $V$ and the non-terminal $D_1$ is the same as $D$. Here, the subscript is used to differentiate the grammar symbols on the two sides of a production. The function $put$ updates the symbol table with the type information for an identifier.
    Let P and Q be the languages specified by grammars G1 and G2, respectively.
    Which of the following statements is/are true?
  5. Which of the following statement(s) are correct?

    A. Syntax Directed Translation can be applied in Type Checking.

    B. Syntax Directed Translation can be used in 3-address code generation.

    C. Syntax Directed Translation can be used in construction of syntax tree.

    D. Syntax Directed Translation can be used to recognize valid tokens.

    Choose the most appropriate answer from the options given below:

Need Expert Advice?
Upcoming Exams
CTET
December 12, 2026
CBSE UGC NET
December 14, 2026
CSIR UGC NET
December 19, 2026
Test Series
UGC NET img
Teaching
UGC NET (Paper 2) 2026 Mock Test Series
796 Tests 2 Tests Free
219 Attempts
4.4(46)
English
More Questions from UGC NET

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App