User Tools

Site Tools


compilers:sample-questions

Sample exam questions (theory part)

  1. What is the task of the lexer?
  2. Which part of the compiler is usually defined by a context-free grammar?
  3. What is JIT (Just in time compilation)?
  4. Write 3 token sequences that are accepted by the following grammar and 5 that are not accepted!
    1. S→ab | aSb
  5. Is LL(1) top-down or bottom-up?
  6. How do the two basic actions of an LR(1) parser change the stack?
  7. In which direction do synthesized attributes propagate information in the syntax tree?
  8. What is the esp register used for?
  9. Write an example assembly line with the and instruction and explain what does it do!
  10. Write a code generation rule for an assignment!

Answers

  1. The lexer breaks up the input character sequence to a token sequence.
  2. Parser.
  3. Some parts of interpreted code (eg. bytecode) are compiled to machine code in runtime to speed up program execution.
  4. Accepted: ab, aabb, aaabbb; Not accepted: a, b, ba.
  5. Top-down.
  6. Shift pushes the next token into the stack, reduction removes the right-hand side and pushes the left-hand side of the selected grammar rule.
  7. Bottom-up.
  8. The esp register points to the top of the stack.
  9. and eax,1: All bits of eax become zero, except the last one, which is preserved.
  10. For integer type: code of the expression + mov [label of the variable],eax
compilers/sample-questions.txt · Last modified: 2016/12/15 11:35 by deva