Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Programming Languages / Advanced Computing Topics

(COMP2003)

2018, semester 2

Test 1

Question 1 (13 marks)

For the following code, draw the stack (complete with dynamic and static chains) and the display as they would appear at POSITION_1 .

Procedure  S :

Procedure  A :

Procedure  B :

Begin

D

End

Procedure  C :

Begin

POSITION_1

End

Procedure  D :

Procedure  E :

Begin

A

End

Begin

C

End

Begin

B

End

Begin

A

End

 

Question 2 (12 marks)

(a) What kind of variable passing did ALGOL use? What problems are associated with ALGOL’s choice of passing methods?                                           [4 marks]

(b) With reference to PL/1, at least one other language, and the programming prin- ciples, discuss what the problems with including too many features in a language

are.                                                                                                            [6 marks]

(c)  FORTRAN is an old language, but unlike ALGOL-60, it is still used today. Why


Question 3 (14 marks)

(a) With reference to two of the programming principles, discuss Pascal’s effective- ness as a learning language.                                                                  [4 marks]

(b) With reference to no less than three of the characteristics of good programming languages, discuss whether or not Pascal’s approach to modularity was a good idea.                                                                                                      [6 marks]

(c) ALGOL-60 is more simple than FORTRAN, and arguably a better language to use.  However, when ALGOL-60 was released, FORTRAN still saw significant use. Name two features that FORTRAN had that ALGOL-60 did not, and explain why they made FORTRAN more attractive than ALGOL-60.                [4 marks]

 

Question 4 (13 marks)

(a) Ada was based on Pascal, but was by no means the same.  Compare and con-

trast Ada and Pascal’s variable passing methods with regards to the programming

[4 marks]

(b) What can go wrong during a rendezvous? Explain with an example.   [2 marks]

(c) What programming principles does Ada’s exception handling break? Why? Give

an example for each.

(d) Name two positive, and two negative effects of Ada’s use of the Loop construct with regards to the characteristics of good programming languages.    [4 marks]

 

Question 5 (8 marks)

A simple language is defined in the following syntax graph:

 

(a) Write the corresponding BNF for the language in the syntax graph. You may not

use EBNF.

(b) Explain using examples why EBNF would have made the previous question eas-

[2 marks]

(c) Could you build a regular expression to recognise any C program, without acci- dentally recognising non-C programs? Why or why not?                      [2 marks]