Undergraduate Honors Programming Languages Honors

CS345H Fall 2007
Time: TTH 2:00-3:30P
Location: RAS 213
Unique: 56610
Newsgroup: utexas.class.cs345-cook

 

Instructor: William Cook
Email: wcook@cs.utexas.edu
Phone: (512) 471-9555
Office: ACES 5.244
Office Hours: Tues 9-10am, Thurs 3:30-4:30
(or by appointment)

Teaching Assistant:Ali Ibrahim
Email: aibrahim@cs.utexas.edu
Office Hours:
    M: 10:30 – 12
    W: 1:30 - 3
Office Hours Location: ENS 31NQ (thru 31 NR)

 

News

In case you didn’t get it in class, here is the final review sheet (with slight revisions to remove mentions of ML)

 

Final review ANSWERS now posted.

 

Project #3 due Dec 6

 

Homework Due Nov 6:

1. Show the activation records, with control and access links, that are created during the execution of this program:

 

fun g(f, x) {

      return f(x) + x;

}

fun mul(a) = {

      fun f(b) = a * b; // local function definition

      return f;

}

val f2 = mul(2);

val r = g(f2, 5);

 

 

2. Consider the following function:

int B(int x, int y, int z)

{

    if (x == 0)

        return z;

    else if (y == 0)

        return B(x - 1, y, x + z);

    else

        return y * (B(x, y - 1, z));

}

 

a)    Which function calls in this definition of B are tail calls?

 

b)    Assuming that activation records are reused for tail calls, what is the maximum number of activation records on the stack (that is, depth of the stack) during the execution of  B(5, 2, 0) ?

(note that this question does not ask you to compute the actual result of the function)

 

 

 

Program #2: Due date changed to Friday, October 26 at noon. Bring the print-outs to my office.

NOTE: I update the BubbleSort sample to have an explicit instead of implicit cast.

Here are two sample programs using arrays. Also, please note:

·        You should edit and compile the java files in the CLite folder that you downloaded, but you must not use precompiled “Clite.jar” or the Clite Parser or Lexer that you downloaded from the book web site. Use your own parser and complete the other Clite classes until the main class Semantics can run with all code working (including the parts that are given to you but commented out).

·        The assignment incorrectly identifies one of the places where you have to add code (it says it’s in the semantics of unary operators, but it is actually the semantics of binary operators). The key put is that you need to implement all the missing code necessary to run the Semanitcs.Main method as described above.

 

Midterm review

Program #2: Due Tuesday, October 23

Here is a description of the project. If you need it, here is a solution to project one.

Please follow these instructions on how to turn in project 2. Following instructions is worth 10 points.

 

HOMEWORK #3: 10/2/2007

Homework #3: Due Tuesday Oct 2

 

1. Design and describe an algorithm for ensuring that every variable in Clite is assigned a value before it is used. Are there any cases where the program would execute correctly, but your algorithm will reject it has possibly using an undefined variable?

 

2. The intent of this code is to find the first all-zero row of an array. Is there way clean, structured way to write it in C or Java without using goto?

 

int n = 100;

int A[100][100];

int first = -1;

int i, j;

for (i = 0; i < n; i++) {

      for (j = 0; j < n; j++) {

            if (A[i][j] != 0)

                  goto next;

      }

      first = i;

      break;

next: ;

}

 

 

HOMEWORK #2: Problem 3.16 and 3.19 due 9/20/2007

Program #1

I have posted a working example with Flex and Cup. The directory contains a build.bat and run.bat file, which contains a list of commands to build/run the system. To run on windows, just type

   build
   run

If you are using this on unix/Mac, you can use

          sh build.bat
          sh run.bat

BUT NOTE: you must change the “;” to a “:” in the classpath inside these two files.

 

 

Program #1: Parser due Tuesday, September 25

 

Homework #1: DUE Tuesday September  11

From book: 2.6, 2.7, 2.8, 2.9, 2.10, 2.15
Also everyone code and run Euclid’s algorithm in Clite using Clite.jar (include print-out of execution).
See the book web site to get the jar file. Example command line to run is:
     java -jar Clite.jar programs/factorial.cpp