Compilers and Interpreters
for Dataingenjörsprogrammet, and others
Saturday October 30, 2010
Exam for:
DT3004 Datateknik C, Kompilatorer och interpretatorer, provkod 0100
→ This exam is also available in a Swedish version.
Aids: | No aids. |
Score requirements: |
Maximum score is 32.
To pass (3 or G), at least 16 points are required. |
Results: | Announced on the course website or by e-mail by Saturday November 20, 2010. |
Return of the exams: | After the result has been announced, exams can be collected from the university's central "tentamensutlämning". |
Examiner: | Thomas Padron-McCarthy |
A compiler's work is usually divided into several phases. In which phases are these errors and warnings detected?#include <stdio.h> int main(void) { int a; printf("Hi!\n ); error: missing terminating " character printf("Give a number: "); scanf("%d", &a ; error: expected ')' before ';' token printf("The number was: %d\n", a); return "Charles"; warning: return makes integer from pointer without a cast }
b) (2p) Write a regular expression for the Swedish personal identity number (for example 631211-1658). Your expression should match all valid such numbers. It is difficult to write a regular expression that does not also match certain incorrect numbers, so your solution is allowed to do that. But state at least one check that is not made by your regular expression.
c) (1p) What is the difference between a token and a lexeme?
a) left recursion
b) FIRST() conflicts
c) ambiguity
For each of these problems, provide an example of a grammar that exhibits the problem. Also explain, for each of the grammars, how the problem manifests itself in practice. (That is: what is it that does not work, because of the problem?) Also explain how to solve the problem.
Translate the above program section to two of the following three types of intermediate code:x = 1; y = 2; z = 3; while (y == 2) { if (z > 4) { y = y - 1 - 1; } else { z = z + y * z + z; t = t + 2; } }
a) an abstract syntax tree (by drawing the tree!)
b) postfix code for a stack machine
c) three-address code
Note: There are three sub-tasks in the task above. Select and answer (at most) two of them. (If you answer all three, the one with the most points will be discarded.) |
a) target language
b) target program
c) front end
d) Yacc
e) symbol table
f) shift-reduce conflict
g) deterministic finite state machine
h) reserved word (or "keyword")
i) call sequence