Last Updated: 2018-12-10 Mon 11:49

CSCI 2041 Lab14: Review

CHANGELOG: Empty

1 Rationale

This lab is intended to begin review for the final exam. It provides to large-ish review problems covering Project 5 topics and streams. Grading rules are slightly different than previous labs and involve attendance and completion of an exit survey.

Grading Policy

  • Attendance 60%: Attend lab and sign the attendance sheet. Participate in review activities.
  • Exit Survey 40%: Fill out the Exit Survey linked on Canvas by the day of the Final Exam.

See the full policy in the syllabus.

2 Questions

Analyze the files in the provided codepack and answer the questions given in QUESTIONS.txt.

                           __________________

                            LAB 14 QUESTIONS
                           __________________


The following are review problems which


Review Problem 1: Exponentiation in Calculon
============================================

  Consider extending Calculon to include exponentiation associated with
  the `^' symbol. Below are some examples of the desired behavior.
  ,----
  | calculon> 2^5;
  | - : IntDat(32)
  | 
  | calculon> 2^4;
  | - : IntDat(16)
  | 
  | calculon> 2^2 + 2^5 - 2^4;
  | - : IntDat(20)
  | 
  | calculon> 16 / 8;
  | - : IntDat(2)
  | 
  | calculon> (4^2) / (2^3);
  | - : IntDat(2)
  | 
  | calculon> 4^2 / 2^3;
  | - : IntDat(2)
  | 
  | calculon> 2^2^2;
  | - : IntDat(16)
  | 
  | calculon> 2^2^3^4;
  | - : IntDat(16777216)
  `----

  - Exponentiation has higher precedence than other operators so must be
    parsed before addition, subtraction, multiplication, and division.
  - As shown, exponentiation can be repeated in a chain like `2^2^2'.

  Discuss which parts of Calculon's system would need to be altered to
  support this new operator. Be specific about which files and functions
  would need to change. If you are feeling adventurous, copy your A5
  files to a new directory and code the change.


Review Problem 2: Lexing and Streams
====================================

  Examine Calculon's main lexing function called `lex_string'.  Recall
  that this function processes an entire string and transforms it into a
  list of tokens. Consider how it might be converted to a *stream*
  instead of a list. Discuss how this might work with the interface for
  streams provided in OCamls standard library `Stream' module.

  - Discuss how the state of the stream can be represented
  - Discuss changes that would need to take place in the code to make it
    compatible with the `Stream' module

  Below is the desired behavior via a `lex_stream' function which
  creates a stream of tokens.

  ,----
  | # let stream = Calclex.lex_stream "let x = 4*2 in x-6;";;
  | val stream : Calclex.token Stream.t = <abstr>
  | 
  | # Stream.next stream;;
  | - : Calclex.token = Calclex.Let
  | # Stream.next stream;;
  | - : Calclex.token = Calclex.Ident "x"
  | # Stream.next stream;;
  | - : Calclex.token = Calclex.Equal
  | # Stream.next stream;;
  | - : Calclex.token = Calclex.IntTok 4
  | # Stream.next stream;;
  | - : Calclex.token = Calclex.Times
  | # Stream.next stream;;
  | - : Calclex.token = Calclex.IntTok 2
  | # Stream.next stream;;
  | - : Calclex.token = Calclex.In
  | # Stream.next stream;;
  | - : Calclex.token = Calclex.Ident "x"
  | # Stream.next stream;;
  | - : Calclex.token = Calclex.Minus
  | # Stream.next stream;;
  | - : Calclex.token = Calclex.IntTok 6
  | # Stream.next stream;;
  | - : Calclex.token = Calclex.Semicolon
  | 
  | # Stream.peek stream;;
  | - : Calclex.token option = None
  | # Stream.next stream;;
  | Exception: Stdlib.Stream.Failure.
  `----

3 What to Understand

In addition to the topics covered above, review all major course topics listed on the schedule to help prepare for the final exam.

4 Getting Credit: Show up and Finis Survey

  • There is no check-off associated with this lab. Attend lab to get in-person credit.
  • There is no submission associated with this lab. Complete the exit survey to get remaining credit for the lab.

Author: Chris Kauffman (kauffman@umn.edu)
Date: 2018-12-10 Mon 11:49