COMS 4115 Programming Languages and Translators

Homework 1
Prof. Stephen A. Edwards
Due February 8, 2021 at 11:59 PM

All the problems ask you to use OCaml.  You may download the compiler
from ocaml.org.

Create a hw1.tar.gz file containing your solutions (e.g., with the
Makefile) and upload it to Courseworks.

Do this assignment alone.  You may consult the instructor or a TA, but
not other students.

Cite any websites you use to help you answer these questions aside
from those for the class and ocaml.org.

1) Edit zip3.ml to create the zip3 function.  See zip3.ml for details.

2) Edit wordcount.mll to complete the word counter.
   See wordcount.mll for details

3) Edit ast.mli, calc.ml, parser.mly, and scanner.mll to add variables,
   assignment, and sequencing to the four-function calculator example.

   For example,

   foo = 3; bar = baz = 6; foo * bar + baz

   should print 24.

   Use a String-to-integer hash table to track variable values, i.e.,
   
   module StringHash = Hashtbl.Make(String)
   let vals = StringHash.create 10

   Variable names should be sequences of one or more lowercase letters.

   "=" should denote variable assignment, with a variable name on
   the left and and expression on the right.  An assignment expression
   should return the value being assigned and associate right-to-left.

   ";" should denote sequencing of expressions and should be
   interpreted left-to-right.

   ; should be at the lowest level of precedence, followed by =,
   + -, and * /, so

   baz = 2 ; foo = bar = 3 ; 3 * 2 + 4	

   should be interpreted as if it were parenthesized

   ((baz = 2) ; (foo = (bar = 3))) ; ((3 * 2) + 4)

   (Don't make your calculator accept parentheses)
   

The Makefile has recipes for compiling and running all three problems.