0% found this document useful (0 votes)
2K views3 pages

Test May 2024 CSC569

The document contains 8 questions about compilers and finite state machines. Question 1 asks to represent 6 compilers in big C notation. Question 2 asks how to create a C++ compiler for Huawei from a Nexus compiler without writing assembly or machine code. Question 3 compares compiler and interpreter output for a given code snippet. The remaining questions cover finite state machines, binary search trees, tokenization, and other compiler related topics.

Uploaded by

2022470942
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views3 pages

Test May 2024 CSC569

The document contains 8 questions about compilers and finite state machines. Question 1 asks to represent 6 compilers in big C notation. Question 2 asks how to create a C++ compiler for Huawei from a Nexus compiler without writing assembly or machine code. Question 3 compares compiler and interpreter output for a given code snippet. The remaining questions cover finite state machines, binary search trees, tokenization, and other compiler related topics.

Uploaded by

2022470942
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CONFIDENTIAL 1 CSC569/MAY 2024

UNIVERSITI TEKNOLOGI MARA, SHAH ALAM


TEST [MAY 2024]
TIME: 2 HOURS 30 MINUTES

NAME : ___________________________________________
STUDENT NUMBER : _______________________________________
GROUP : _______________________________________

INSTRUCTIONS TO CANDIDATES

1. This question paper consists of EIGHT (8) questions.

2. Answer ALL questions in the given spaces on this question paper.

DO NOT TURN THIS PAGE UNTIL YOU ARE TOLD TO DO SO

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 1 CSC569/MAY 2023/TEST

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.

QUESTION 3 (20 marks)

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)

Consider the following finite state machine:

a b c d
A B D D D
B D B B C
C* D D D D
D D D D D

a) List three different strings generated by the finite state machine.


b) Describe, in you own words, the language specified by the finite state machine.
c) Write regular expressions to specify the languages specified by the finite state machine.

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

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 2 CSC569/MAY 2023/TEST

QUESTION 7 (10 marks)

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

QUESTION 8 (12 marks)

Consider the following sabblecc grammar file.

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

END OF QUESTION PAPER


ASCII Table for question 6 and question 7

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL

You might also like