Attempt ONLY FIVE of the following questions. Each question carries equal marks.

Question-1: Choose the most correct answer and write only the letter corresponding to the correct answer next to the question number in your answer sheet.

  • Which of the following is used for grouping of characters into tokens?
  1. a) parser b) code optimizer             c) code generator             d) scanner
  • Which of the following are language processor?
  1. a) assembler b) compilers               c) interpreters              d) all of the above
  • The action of parsing the source program into the proper syntactic classes is known as
  1. a) syntax analysis             b) lexical analysis
  2. c) interpretation analysis            d) general syntax analysis
  • Compiler can diagnose
  1. a) grammatical errors only b) logical errors only
  2. c) grammatical as well as logical errors d) None of these
  • A given grammar is said to be ambiguous if
  1. a) two or more productions have the same nonterminal on the left hand side
  2. b) a derivation tree has more than one associated sentence
  3. c) there is a sentence with more than one derivation tree corresponding to it
  4. d) brackets are not present in the grammar
  • Whether a given pattern constitutes a token or not depends on the
  1. a) Source language b) Target language         c) Compiler          d) All of these
  • Access time of the symbol table will be logarithmic, if it is implemented by
  1. a) Linear list    b) search tree            c) hash table          d) self-organizing list
  • How many tokens are contained in the following FORRTAN statement:

  If(NUMB .EQ. MAX) GOTO 500  

  1. a) 8      b) 10                              c) 22                              d) 24
  • Pick the machine independent phase (s) of the compiler
  1. a) syntax analysis             b) Lexical analysis 
  2. c) intermediate code generation             d) all of the above
  • The value of the expression in postfix notation: 1 4 18 6 / 3 + + 2 /* is
  1. a) 12      b) 10                                c) 5                                 d) 2

 

Question-2:

  • Explain how scope information can be captured in symbol table.
  • Distinguish between static vs. dynamic typing and strong vs. weak typing.
  • Write a regular expression for a set of octal strings that starts and ends with the same character. Use only the basic operations.

 

Question-3:

  • What are the main functions of preprocessors?
  • Construct a finite automata that will accept a set of string of zeros and ones that contains an odd number of zeros and an even number of ones.
  • Write an optimized 3AC for the following source code fragment:

x := 3; y := x + 12; z := y/x;

Question-4:

  • Briefly describe the primary tasks of code generator.
  • Identify the token and, lexemes in the following function:

function gcd (m, n: integer): integer;

begin

if n = 0 then gcd := m

else gcd := gcd (n, m mod n)

end; (* end of gcd *)

  • Write a register-based target code for the arithmetic expression x+(-y*z+u)*v

 

Question-5:

  • Give three examples of semantic errors that a program may contain.
  • Given the grammar G: E E + E | E * E |(E) | id

Show the leftmost derivation and rightmost derivation for the sentence (id*id)+id.

  • Construct a hierarchy of symbol tables for the following source code:

int x;

void main(){

  double x, z;

  ...

}

void f (int m) {

  float x, y;

...

    {int i, j; x=1; }

    {int x; L: x=2; }

}

int g(int n) {

    char c;

    {int i, j; x=5; }

  ...

}

 

Then, associate each definition of x with its appropriate symbol table entry.

 

Question-6:

  • What are the possible error recovery actions in lexical analysis?
  • List three properties that an intermediate language should ideally have.
  • Consider the following a block of source code:

            x := y*z+x w := y*z+x; z := y*z+x;

  • Write a four address code for that block.
  • With the help of depending algorithm, optimize the obtained four address code.

 

Best wishes,,,

Dr.-Ing. Samy Sadek