Compilers and Interpreters
Thursday August 14, 2025
Exam for:
DT501A Kompilatorer och interpretatorer för civilingenjörer, provkod A001
Aids: | No aids. |
Score requirements: |
Maximum score is 40.
To pass, at least 24 points are required. |
Results: | Announced no later than 15 working days after the exam. |
Return of the exams: | Electronically through the student portal "Studenttjänster". |
Examiner and teacher on call: | Thomas Padron-McCarthy, phone 070-73 47 013. |
A is a non-terminal, but x and y are any constructions consisting of terminals and non-terminals.A -> A x | y
The rule is replaced by the following two rules (or, more correctly, three productions), that describe the same language, but are not left recursive:
A -> y R R -> x R | empty
A is a non-terminal, but x, y and z are any constructions consisting of terminals and non-terminals.A -> x y | x z
Replace with these three productions:
A -> x R R -> y | z
w = x + y * z / t; w = (x + y) * (z / t); if (w < x) { w = x; w = y; } else { if (w > y) x = z; else x = t; }
Translate the program segment to two of the following three types of representations.
a) an abstract syntax tree (by drawing it)
b) postfix code for a stack machine
c) three-address code
Note: Two of the three types, not all three. Should you answer with all three, the one with the highest points will be discarded.
b) Give an example of an error in a C program that is detected by the second phase in a compiler, the syntactical analyzer, and explain why it can't be detected by the lexical analyzer.
c) Give an example of an error in a C program that is detected by the third phase in a compiler, the semantic analyzer, and explain why it can't be detected by the lexical analyzer or the syntactical analyzer.
a) ambiguous grammar (in Swedish: tvetydig grammatik)
b) FIRST() conflict (Swedish: FIRST()-konflikt)
c) call sequence (Swedish: anropskonventioner)
d) activation record (Swedish: aktiveringspost)
e) symbol table (Swedish: symboltabell)
To keep track of their superheroes and supervillains they need a program with a special input language. Here is an example of how the input language looks:
superheroes Captain Barvel, Baredevil; supervillains Boctor Boom, Bagneto, Boctor Boctopus; superheroes Black Bidow; superheroes Biderman; friends Boctor Boom, Bagneto; enemies Boctor Boctopus, Biderman; done; |
In the input you can use the commands superheroes, supervillains, friends and enemies, plus the command done that is used to end the input. Commands end with a semicolon, and each of the commands except done takes a comma-separated list of one or more superperson names, which all consist of one or more words, as arguments.
(Yes, you can be friends and enemies just with yourself, and if you list more than two superpersons as argument to enemies, they all hate each other.)
It should be possible to write the input in free format, such as in most common programming languages, for example like this:
superheroes Captain Barvel , Baredevil ; supervillains Boctor Boom , Bagneto , Boctor Boctopus ; superheroes Black Bidow ; superheroes Biderman ; friends Boctor Boom , Bagneto ; enemies Boctor Boctopus , Biderman ; done ; |
b) (2p) Out of these terminals, some will not have fixed lexemes. Write regular expressions for each such terminal.
superheroes Black Bidow, Bulk; supervillains Boki; done; |