CS 333: Homework


Current HW

HW 1: What languages do you know?

Due Friday, Sep 11

Write down all of the programming languages you recall using. Use a broad definition of a programming languages as something that enables you to instruct a computer to complete a task automatically. For each language you recall, give a brief answer to each of the following questions.

HW 2: What languages do you want to know?

Due Monday, Sep 21

Pick three languages you do not yet know and write the equivalent of a Hello World program in each of them. Have it do something simple like print out the first ten terms of a Fibonacci series.

Make a small wiki page for each language that includes your program and a description of its key components. Note especially the differences in syntax between the languages. Are there any differences in naming, variable scope, or data types?

Please put the label cs333f09hw02 on your wiki pages.

HW 3: Parse trees

Due Monday, Sep 28


Using the Clite syntax, generate parse trees for the following statements. Feel free to do this automatically using flex, if you feel like trying it out.

HW 4: Symbol tables and Language selection

Due Monday, Oct 5


  1. In the linked C example, specify which value would be printed out for g, h, and i at each label. For the function calls, label them as E-A, E-B, F-A, F-B, and G-A, G-B. Explain which variable is visible and why.
  2. Show the symbol table stack at A, B, C, D, and E during the compilation process. Explain how this makes the g, h, i in main function inaccessible in f1 or f2.
  3. Pick 2 languages you do not already know well that you want to learn in some depth over the course of the semester. They do not have to be in the set of three from your HW 2, but the two languages should be fairly different (C and C++, for example, don't count).

    For each language, find one other person in the course who also wants to learn that language. It does not have to be the same person for each language, but you have to have a partner for each. Send the prof an email with your answers to the above two questions, your two languages, and the name of your partner for each language.

HW 5: Automatic type conversion

Due Friday, October 16

  1. Consider the linked C program. Compile it, run it, and explain the output. What conversion rule is it using when it executes the addition expression? Explain the values printed out by the float and double casts.
  2. Write a C program that demonstrates that the order of operations is critical to the result. Use a single expression that uses three variables. Hint: use an unsigned, an int with a negative value of larger magnitude, and a float and make the simplest mathematical expression possible out of the three variables.
  3. Show the abstract syntax tree for each ordering and explain the results you get.

HW 6: Type conversion and aliasing

Due Friday, October 23

  1. In the last homework we saw it was possible to get unexpected results in C because of automatic type conversions. Pick one of your selected languages for the semester and see if you can do unexpected things by making use of automatic type conversions. If you can't, discuss the language features that prohibit it. Put the example or discussion up as a wiki page linked to your language's main page.
  2. Aliasing occurs when you can use one variable to change a value in memory and have that change reflected when using a different variable. For example, two pointers to the same memory location in C enable aliasing. Pick one of your selected languages for the semester and see if you can demonstrate aliasing in that language. If you can't, discuss the language features that prohibit it. Put the example or discussion up as wiki page linked to your language's main page.

HW 7: Exception handling

Due Friday, November 6

  1. Write a simple example of exception handling in 2 of the three languages (Python, Java, C++). Demonstrate handling a built-in exception and a user defined exception. In Python or Java, demonstrate how the finally block works. Put your code, with comments describing how it works, on the Academics server and send me an email when it's done.

HW 8: Concurrent Programming

Due Friday, November 20

  1. In one of C/Java/Python implement a sorting function/class that uses at least two threads. For example, given a very large array of numbers, divide the array in half, sort each half in a different thread using a built-in sort method, and then merge the two results back together in the parent thread.
  2. In one of C/Java/Python implement a simple 3-thread producer-middleman-consumer model. All three threads should share a common buffer with a single entry and appropriately synchronize their access. If the buffer is empty, the producer should put in a number between 0-9. Once the producer is done, the middleman should multiply the number by 10. Finally, the consumer should remove the number and print it out. Include print statements in your code so that you can watch the processes take turns.


Due Friday, December 4

Download the following files onto fili.cs.

Compile and run these examples, then look at the waveforms using gtkwave. Make sure you understand how the code generates the waveforms.

> ghdl -a <file>.vhd
> ghdl -e <file>
> ghdl -r <file> --vcd=<file>.vcd
> gtkwave <file>.vcd

Write VHDL to simulate a circuit with 5 inputs (A, B, S, clk, reset) and 2 outputs (Q, C). Create one entity to model the circuit and another entity as a testbench.

The functionality of the circuit is as follows.

Note that you will need two internal signals in your circuit to represent two flip-flops.