Compilers Exam, 2015-12-18

Theory

  1. What is the input and output of the lexical analyser (lexer)?
  2. Which of the above inputs match the [ab]*(ab)+ regular expression?
    • a, b, ab, ba, aab, bab, baba, ababaab
  3. Given the following token definitions, how will the lexer tokenize the if else ifelse apple text?
    if      cout << "IF";
    else    cout << "ELSE";
    [a-z]+  cout << "IDENTIFIER";
    " "+    cout << "SPACES"
  4. Write down the steps of the derivation of aaabbb (S ⇒ … ⇒ aaabbb) using the grammar below!
    • S → ab | aSb
  5. What is the difference between top-down and bottom-up parsing?
  6. Write down the function of a recursive descent parser corresponding to the A → aB | c rules!
  7. What are the two operations that an LR parser can perform?
  8. What is a symbol table used for?
  9. Write a 32-bit NASM assembly program that swaps the contents of the dword [a] and dword [b] memory locations!
  10. Write a code generation rule for an assignment operation of the form assignment → variable := expression!

Practice

Extend the While language with a new type, called time. An example:

program exam
  time t;
  integer i;
begin
  t := 09:52;
  i := hour(t) + minute(10:02);
  write(i);
end

Tasks: