

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The final exam for cs 784 spring 2009 at wright state university's department of computer science and engineering. The exam covers various topics including static fields in object-oriented programming languages, attribute grammars, axiomatic semantics, and algebraic specification. Students are required to explain modifications to the interpreter code to incorporate static fields, write an attribute grammar for base-3 numerals, determine weakest preconditions for given code snippets, and give an algebraic specification for the int bag adt. Essential for university students specializing in computer science and engineering.
Typology: Exams
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Wright State University Department of Computer Science and Engineering
CS 784 Spring 2009 Prasad
Consider the interpreter for OOPL given in the files 5-3.scm and 5-4-4.scm. We explore introducing static fields into class definitions. Static fields associate some state with a class; all the instances of a class share this state. Static fields can appear in a method body. For example, one might write the following program and obtain as the result, the list (01):
class c static next_serial_number field my_serial_number method get_serial_number () my_serial_number method initialize () begin set my_serial_number = next_serial_number; set next_serial_number = add1(next_serial_number); end let o1 = new c1() o2 = new c1() in list (send o1 get_serial_number(), send o2 get_serial_number())
Explain all the modifications to the interpreter code to incorporate the static fields shown in the grammar rule for class definition below, informally and clearly first, and formally in code later. Initialize each static field to 0, by default.
(class-decl ("class" identifier "extends" identifier (arbno "static" identifier) (arbno "field" identifier) (arbno method-decl) ) a-class-decl)
Specifically, locate all the changes to the original interpreter code on the accompanying interpreter code handout and/or locate changes/insertions using file name, page number, and line numbers.
Consider the following grammar for the base-3 numerals T.
T ::= 0 | 1 | 2 | T T
Write an attribute grammar to determine the numeric value of these numerals. For instance, V alue(201) = 19, V alue(1010) = 30, etc.
Determine the following weakest preconditions. (Assume all variables are of integer type.)
wp( {if odd(j) then k := ki; j := j-1 else i := ii; j := j div 2}, [ k*(i^j) = n ] ) =?
wp( {while i > 0 do i := i - 5;}, i = 0) =?
Give an algebraic specification of the ADT Int Bag that supports the following operations: empty, insert, isEmpty, count, union and intersection. (Recall that a bag is a homogeneous collection of values where duplication is significant, but the order of values is not.) Informally,