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.
- For what purpose did you use the language?
- How would you describe the syntax of the language?
- Was the language well-suited for the purpose? Why, why not?
- Could you write a program in the language right now without recourse to a textbook or manual? Why, why not?
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.
- z = -x + 3*b;
if( a < 0 || b < 0 ) b = 0; else b = a;
HW 4: Symbol tables and Language selection
Due Monday, Oct 5
- 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.
- 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.
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
- 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.
- 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.
- Show the abstract syntax tree for each ordering and explain the results you get.
HW 6: Type conversion and aliasing
Due Friday, October 23
- 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.
- 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
- 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
- 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.
- 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.
HW 9: VHDL
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.
- A and B are single bits (std_logic).
- S is a 2-bit std_logic_vector.
- clk and reset are single bits.
- Q and C are single bits.
The functionality of the circuit is as follows.
- If reset is '1' the circuit should output Q = '0' and C = '0'.
- Otherwise, on the rising edge the circuit should change its output
based on the input bits A and B and the action selector S.
- If S is "00" then the circuit output should not change its value.
- If S is "01" then Q should become the sum of A and B and C the carry bit.
- If S is "10" then Q should become the AND of A and B and C should be NAND.
- If S is "11" then Q should become the OR of A and B and C should be NOR.
Note that you will need two internal signals in your circuit to represent two flip-flops.