Title image Spring 2018


Current HW

HW 1: Hello World with Numbers

Due Friday 9 February 2018

Pick a language you do not know and write a program in that language that computes the average of three numbers and prints out the result. Run your code and make sure it works.

  • How simple is the code?
  • How readable is the code?
  • How much time did it take to get it running?
  • Is it compiled or interpreted?

Send the professor an email with your code (not as an attachment) and your short answers to the above questions.

HW 2: Grammars and Regular Expressions

Due Friday 23 February 2018

  1. Define a BNF grammar with the alphabet {a, b} that defines strings that start with an a, have one or more b symbols and end with an a.
  2. Define a regular expression for the prior grammar. Note that you can test regular expressions using the terminal command egrep. You can use the following ABA test file. There are three lines that match the proper specification.
  3. Demonstrate that addition in C is not associative. The following two statements should print significantly different results. You need to figure out appropriate types and values for a, b, and c. Can you do the same with multiplication?
    printf( "%f\n", (a + b) + c );
    printf( "%f\n", a + (b + c) );
  4. Using the Clite syntax, generate both the concrete parse trees and abstract parse trees for the following statements. Feel free to do the concrete tree automatically using flex.

    • a = b * ( 5 + c );
    • if( a == 0 || b > 0 ) 
        b = 0;
        b = a;

HW 3: Exercises

Due Wednesday 7 March 2018

  1. Write a BNF grammar to describe the roman numerals from 0 to 100. Solve the same problem using regular expressions and test it on this file using either flex or egrep. Here is a chart.
  2. For global variables in C: (1) how can they be accessed in other compilation units? (2) how can a global variable be hidden from other compilation units? (3) why would you want to hide global variables?
  3. For C, give three examples of r-values that cannot be l-values. Give three more examples of l-values. Are there l-values that cannot be r-values? Explain your answer.
  4. What is the definition of true and false in C with respect to the condition for an if-statement? Compare to Java. What are the benefits and drawbacks?
  5. Why do you think there is an IEEE standard for float types but not for integer types?
  6. Write two syntatically identical functions in C and Java that have different semantic meanings. Demonstrate the differences by printing out something and explain the semantic differences.

HW 4: Exam follow-up

  1. Consider the do-loop below. The state of the program consists of a single variable i.
    int i=0;
    do {
    } while (i < 5);

    Write a purely functional python representation of the do loop itself. The top level call should be MDo( doloop, state ). The state will be a single integer that starts with the value 0. The body of the do loop consists of a Statement adding something to the state variable. The test of the do loop involves comparing the state to the expression value.

    To make the doloop argument, create a simple class DoLoop that contains a test field and a body field. Assign the test field the value 5. Assign the body field the value 1. You can use the body field as the thing to add to the state.

    The body of the loop should be implemented by a call to an MStmt function that should, in addition to updating state, print out something indicating it is running.

    Demonstrate your functional python code works by running it. Your MStmt function should execute five times and then the MDo function should return 5 for the state (the value of i).