User Tools

Site Tools


Compilers Exam, 2016-12-20

Programming Part

The following tasks should be solved in the order below. Write tests for each step!

  • Grade 2: Add a new regular expression to the lexer in order to separate the name of the program from the name of the variables! The name of the program has to start with a “@” character, then an upper case letter and a non-empty sequence of lower case letters. The variable names do not change.
  • Grade 3: Change the grammar to include the new program name token!
  • Grade 4: Add the ? and : tokens to the lexical analyser! Extend the grammar with the following new expression type:
    • Examples:
      • a := (x<3 ? 0 : 1) + 1
      • write(2 * (b ? x : y+1))
    • The open and close parentheses are mandatory around these expressions.
    • The meaning of (x<3 ? 0 : 1): If x<3, then the result is 0 and 1 otherwise.
  • Grade 5: Extend the semantic analysis to check if
    • The expressions before ? has to be booleans.
    • The expressions before and after the : have to have the same type.
    • The type of the full (a?b:c) expression is the type of b (and c).
compilers/exam20161220.txt · Last modified: 2016/12/20 09:18 by deva