Helsingin yliopisto / Tietojenkäsittelytieteen laitos / Ohjelmointikielten periaatteet / Copyright © 2007 Arto Wikla.

581362 Ohjelmointikielten periaatteet, koe 1.3.2007/AW

Kirjoita jokaisen vastauspaperisi alkuun kurssin nimi ja kokeen päivämäärä sekä nimesi, henkilötunnuksesi ja allekirjoituksesi. Vaikka kysymykset ovat pääosin englanniksi, vastaa toki suomeksi! Saat käyttää englantilaisia teknisiä termejä, ellet ole varma suomalaisista.

  1. Tarkastellaan seuraavaa ohjelmaa:
            x : integer := 1  --globaalit
            y : integer := 2
    
            procedure add
               x := x + y
    
            procedure second(P : procedure)
               x : integer := 2
               P()
    
            procedure first
               y : integer := 3
               second(add)
    
            first()            --pääohjelma
            write integer(x)
    
    1. What does this program print if the language uses static scoping? Miksi?
    2. What does it print if the language uses dynamic scoping with deep binding? Miksi?
    3. What does it print if the language uses dynamic scoping with shallow binding? Miksi?
                                                                                (9 pistettä)
    
  2. Vastaa lyhesti ja selkeästi seuraaviin kysymyksiin:
    1. What purpose(s) do types serve in a programming language? What does it mean for a language to be strongly typed? Statically typed? What prevents, say C or C++, from being strongly typed?
    2. In what ways may an enumeration type be preferable to a collection of named constants? In what ways may a subrange type be preferable to its base type? In what ways may a string be preferable to an array of characters?
    3. Explain the difference between type conversion, type coercion, and nonconverting type casts.
    4. Under what circumstances can an array declared within a subroutine be allocated in the stack? Under what circumstances must it be allocated in the heap?
    5. What are the purposes of the stack pointer (sp) and the frame pointer (fp)? Why does a subroutine often need both?
                                                                                (10 pistettä)
    

  3. Selitä ja anna esimerkkejä, miten arvoparametrit (value), viiteparametrit (reference), arvo-tulos-parametrit (value/result) ja nimiparametrit (name) eroavat toisistaan. Käytä jotain sopivaa pseudokieliesitystä esimerkeissäsi
                                                                                (9 pistettä)