IAE Academy

GATE 2018 CS Q.8: solution and answer

GATE 2018 · CSQ.8 · 1 mark · MCQ

Which one of the following statements is FALSE?

  1. (A)

    Context-free grammar can be used to specify both lexical and syntax rules.

  2. (B)

    Type checking is done before parsing.

  3. (C)

    High-level language programs can be translated to different Intermediate Representations.

  4. (D)

    Arguments to a function can be passed using the program stack.

See the question in the paper

Answer and solution

ANSWER

The false statement is (B): type checking is done after parsing, not before.

Official answer: BSource: Official answer key, GATE 2018 CS (IIT Guwahati)

  1. Check each statement against the phases of a compiler: lexical analysis, parsing, semantic analysis (type checking), intermediate code generation and code generation.

  2. (A) Every regular language is context-free, so a context-free grammar can describe both the token structure (lexical rules) and the phrase structure (syntax rules). The statement is true.

  3. (B) Type checking is part of semantic analysis. It works on the parse tree or syntax tree, so it needs the parser's output first. Type checking therefore happens after parsing, and the statement is false.

  4. (C) The same source program can be translated into different Intermediate Representations, such as a syntax tree, a DAG, three-address code or stack-machine code. The statement is true.

  5. (D) Pushing arguments on the call stack is a standard calling convention. The statement is true.

  6. Only (B) is false, so the answer is (B).

KEY IDEA

The compiler phases run in order: lexical analysis, parsing, semantic analysis (type checking), intermediate code, code generation. Type checking needs the syntax tree, so it cannot come before parsing.

WATCH OUT FOR

Doubting (A) because lexical rules are usually written as regular expressions. Regular languages are a subset of context-free languages, so a CFG can express both.

From the GATE 2018 CS paper. Every question of this paper · Download the full paper · All 8 Lexical analysis questions, with notes

More Lexical analysis questions