Lexical Analysis PYQ QUIZ GATE CS

Last Updated :
Discuss
Comments

Question 1

Consider the following C-program:

C
double foo (double); /* Line 1 */

int main()
{

    double da, db;

    // input da

    db = foo(da);

}

double foo(double a)
{
    return a;
}

The above code compiled without any error or warning. If Line 1 is deleted, the above code will show:

  • no compile warning or error

  • some compiler-warnings not leading to unintended results

  • some compiler-warnings due to type-mismatch eventually leading to unintended results

  • compiler errors

Question 2

Which data structure in a compiler is used for managing information about variables and their attributes?

  • Abstract syntax tree

  • Symbol table

  • Semantic stack

  • Parse Table

Question 3

The lexical analysis for a modern computer language such as Java needs the power of which one of the following machine models in a necessary and sufficient sense?

  • Finite state automata

  • Deterministic pushdown automata

  • Non-Deterministic pushdown automata

  • Turing Machine

Question 4

In a compiler, keywords of a language are recognized during

  • parsing of the program

  • the code generation

  • the lexical analysis of the program

  • dataflow analysis

Question 5

The number of tokens in the following C statement.

C
printf("i = %d, &i = %x", i, &i);

is

  • 3

  • 26

  • 10

  • 21

Question 6

Match the following according to input(from the left column) to the compiler phase(in the right column) that process it:

g2017_1

  • P -> (ii), Q -> (iii), R -> (iv), S -> (i)

  • P -> (ii), Q -> (i), R -> (iii), S -> (iv)

  • P -> (iii), Q -> (iv), R -> (i), S -> (ii)

  • P -> (i), Q -> (iv), R -> (ii), S -> (iii)

Question 7

Consider the following statements.

  • I. Symbol table is accessed only during lexical analysis and syntax analysis.
  • II. Compilers for programming languages that support recursion necessarily need heap storage for memory allocation in the run-time environment.
  • III. Errors violating the condition ‘any variable must be declared before its use’ are detected during syntax analysis.

Which of the above statements is/are TRUE ?

  • I only

  • I and III only

  • Ⅱ only

  • None of Ⅰ, Ⅱ and Ⅲ

Question 8

A lexical analyzer uses the following patterns to recognize three tokens T1, T2, and T3 over the alphabet {a,b,c}. T1: a?(b∣c)*a T2: b?(a∣c)*b T3: c?(b∣a)*c Note that ‘x?’ means 0 or 1 occurrence of the symbol x. Note also that the analyzer outputs the token that matches the longest possible prefix. If the string bbaacabc is processes by the analyzer, which one of the following is the sequence of tokens it outputs?

  • T1T2T3

  • T1T1T3

  • T2T1T3

  • T3T3

Question 9

Which one of the following statements is FALSE?

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

  • Type checking is done before parsing.

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

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

Question 10

Consider the following definition of a lexical token id for an identifier in a programming language, using extended regular expressions:

letter    →    [A-Za-z]

digit      →    [0-9]

id           →    letter (letter | digit)∗

Which one of the following Non-deterministic Finite-state Automata with ϵ- transitions accepts the set of valid identifiers? (A double-circle denotes a final state)

  •  
  •  
  •  
  •  

There are 13 questions to complete.

Take a part in the ongoing discussion