Part 0: Lab Setup
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:
- no undefined variables/fields being accessed
- the program type-checks
- referenced methods and classes are correctly defined
- The main method does not define/access variables, and it does not access
Your interpreter is free to crash with runtime errors in case any of the above is violated. It should not crash on valid programs.
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.scalacontains the AST class hierarchy
src/main/scala/toolc/eval/Evaluator.scalacontains a partially implemented interpreter/evaluator
mainmethod which runs the interpreter on a given input file
programsdirectory contains some example programs on which you can try your implementation.
lib/lib/toolc-reference-parser.jarcontains a parser turning the input programs into ASTs.
Notice that all classes are in a
toolc.Main is the entry point.
You will have to complete the implementation of two methods:
evalStmt. Whenever the program contains
???, you should replace it with a proper implementation. A few examples are already implemented to help you get started.
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
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:
- Click on the “Deliverables” tab
- Click “Deliver this version” on the commit corresponding to the version of your code you want to submit
- In the dialog, make sure “Lab01 - Interpreter” is selected, write a comment if you want
- 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.