Lab for Automated Reasoning and Analysis LARA

Lab 01

Part 0: Lab Setup

Start by setting up your environment as described. Familiarize yourself with the Tool Programming Language and the Tool Compiler Project.

Part 1: Your first Tool programs

Write two example Tool programs each (4 per group of 2) and make sure you can compile them using the Tool Reference Compiler. Please be creative when writing your programs. We don't need 5 versions of a program computing the Fibonacci sequence. The examples at the end of the Tool page should convince you that you can write interesting programs.

Remember that you will use these programs in the remaining of the semester to test your compiler, so don't make them too trivial! Try to test many features of the language.

Part 2: An Interpreter for Tool

Complete the various methods of the Evaluator class so that it “runs” the program passed to it. Print the output straight to the console. Add as many helper methods and fields as you need in the same file. Keep the following in mind:

  • You can assume the program is correct:
    1. no undefined variables/fields being accessed
    2. the program type-checks
    3. referenced methods and classes are correctly defined
    4. The main method does not define/access variables, and it does not access this.

Your interpreter is free to crash with runtime errors in case any of the above is violated. It should not crash on valid programs.

Implementation skeleton

If you have followed Labs Setup, you should have a working Eclipse project with a stub implementation, containing the following files:

  • src/main/scala/toolc/ast/Tree.scala contains the AST class hierarchy
  • src/main/scala/toolc/eval/Evaluator.scala contains a partially implemented interpreter/evaluator
  • src/main/scala/toolc/Main.scala contains the main method which runs the interpreter on a given input file
  • The programs directory contains some example programs on which you can try your implementation.
  • lib/lib/toolc-reference-parser.jar contains a parser turning the input programs into ASTs.

Notice that all classes are in a toolc package. toolc.Main is the entry point.

You will have to complete the implementation of two methods: evalExpr and evalStmt. Whenever the program contains ???, you should replace it with a proper implementation. A few examples are already implemented to help you get started.

Testing

On programs/Pi.tool for instance, your interpreter should produce the following output:

  First method
  ************
  0/1 ~= 0.0000000000
  47/15 ~= 3.1333333333
  102913/32760 ~= 3.1414224664
  5454389/1739700 ~= 3.1352468816
  
  Second method
  *************
  0.0000000000
  3.1333333333
  3.1414224663
  3.1415873902
  3.1415924574
  3.1415956774
  3.1416184816
  3.1416185815
  Ok

Deliverables

You are given 2 weeks for this assignment.

Deadline: Tuesday, Oct. 1, 23.59pm.

You must use the interface on http://larasrv05.epfl.ch/cc13 as follows:

  1. Click on the “Deliverables” tab
  2. Click “Deliver this version” on the commit corresponding to the version of your code you want to submit
  3. In the dialog, make sure “Lab01 - Interpreter” is selected, write a comment if you want
  4. Click on “Create Deliverable”

Once a deliverable is created you can look at the files we will use by clicking on the “See Files” button. Make sure you only modified the files listed in bold as the other files will not be considered!

  • End of Chapter 1 in the Tiger Book presents a similar problem for another mini-language. A comparison of the implementation of ASTs in Java (as shown in the book) and Scala is instructive.
 
cc13/labs_01.txt · Last modified: 2013/09/25 12:00 by ekneuss
 
© EPFL 2018 - Legal notice