Compilers and Interpreters
for Dataingenjörsprogrammet, and others
Wednesday January 3, 2024
Exam for:
DT135G Kompilatorer och interpretatorer, provkod A001
Aids: | No aids. |
Score requirements: |
Maximum score is 42.
To pass, at least 25 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
a = b * c * d + e + f * (h + i); if (j * (k + l) < m) { while (n < o) { p = q + r * s; } t = u; } v = w; x = y;
Translate the program segment to two of the following three types of representations. (Should you answer with all three, the one with the highest points will be discarded.)
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.
course DT135G; course DT105G; course ZORRO; exam DT135G 2023-01-03; exam DT105G 2023-01-11; exam DT105G 2023-01-12; exam DT105G 2023-03-13; forget DT105G 2023-01-12; forget ZORRO; done; |
As we can se, there are four commands that can be given: course, which states that a course with a given course code exists, exam, which says that there is an exam for a certain course on a certain day, the command forget, which can be used to remove a course or an exam that was entered by mistake, and the command done, which signals the end of the input.
It should be possible to write the input in free format, so the following input should be equivalent to the one above:
course DT135G ; course DT105G ; course ZORRO ; exam DT135G 2023-01-03 ; exam DT105G 2023-01-11; exam DT105G 2023-01-12; exam DT105G 2023-03-13; forget DT105G 2023-01-12; forget ZORRO; done; |
b) (2p) Out of these terminals, some will not have fixed lexemes. Write regular expressions for each such terminal.
course DT135H; forget DT135H; course DT135G; done; |