Clone wiki

hopl-course / BETA-assignment

BETA assignment

This assignment will illustrate virtual classes, a concept introduced in BETA, in the language CaesarJ, see for more information. A solution to the expression problem in CaesarJ is described here. The described solution serves as a basis for assignment.


Login to VM

$ ssh

Make new directory for hopl

$ mkdir hopl
$ cd hopl

Copy skeleton code

$ cp -r /hopl/code/caesarj/expr .

Compile and execute program

$ cd expr
$ cjc expr/*.java
$ cj expr.Main_Impl


To complete this assignment:

  • Study the skeleton code (located at the VM, see Installation)
  • Add new data types
    • Add support for subtraction, division and multiplication
    • Add support for let expressions. For example, the expression let x=10 in x*2 should evaluate to 20. The expression does not need to be parsed, but can be created using ordinary code, for example, by Let("x", Lit(10), Mul(Var("x"), Lit(2))) or similar.
    • Create a new class containing the new data types
    • The signature of the eval method needs to be changed in order to handle let expressions.
  • Add new operations
    • Modulary add a toString method that converts an expression to a String (also called pretty printing)