Test May 2024 CSC569
Test May 2024 CSC569
NAME : ___________________________________________
STUDENT NUMBER : _______________________________________
GROUP : _______________________________________
INSTRUCTIONS TO CANDIDATES
QUESTION 1 (6 marks)
Using the big C notation, show the six compilers which are represented in the following figure.
QUESTION 2 (8 marks)
If the only smartphone you have is a Nexus (for which you already have a c++ compiler), show how you can
produce a c++ compiler for the Huawei smartphone, without writing any assembly or machine language.
Show the difference between compiler output and interpreter output for the following source input:
a=10;
for (i=1;i<13;i=i+2)
{
System.out.println(a – 7 + i);
if (i >=5)
a=i+2*a;
}
QUESTION 4 (5 marks)
Show a Finite State Machine diagram that will recognize the words BIRD, BEAR, BABOON, BEAGLE and
SKUNK. Use a different accepting state for each of these words.
QUESTION 5 (9 marks)
a b c d
A B D D D
B D B B C
C* D D D D
D D D D D
QUESTION 6 (8 marks)
Show the binary search tree which would be constructed to store the following list of identifiers:
for Const f2 format int format const dabel
What is the output of the finite state machine, below, for the following input :.
a) otw. b) Mb2U. c)$abc0. d) b737MAX. e) ip168.12.13.14
(L represents any letter, and D represents any numeric digit; also, assume that each input is
terminated with a period):
int sum
L/P2 void P1() { sum = L;}
L/P1
void P2() { sum = sum + L - 10;}
void P3() { sum = sum + D;}
D/P3 void P4() {System.out.println(Hash(sum));exit();}
D/P0 ./P4 void P0() {System.out.println(”ERROR”);exit();}
int Hash(int n) { return n % 100 }
D,L
Helpers
char = ['a'..'z'] ['0'..'9']? ;
Tokens
toka = 'a' char;
tokb = char 'a' ;
tokc = char char ;
tokd = char+ ;
toke = ['0'..'9']+ ;
tokf = ' ' ;
Show the sequence of tokens recognized by the definitions given in the sablecc file using the following input
file: a4a5 a1a aa3 123blast