CE305 Assignment Two — Small Compiler

Table of Contents

Introduction

This assignment requires you to build a compiler for a simple while-language which compiles programs into a form that can be evaluated by a stack-based interpreter, together with documentation.

You are also required to produce and present details of the formal specification of the compiler, including the regular expressions for the tokeniser and BNF grammar that is implemented by the parse. Ideally the parser should have options to display the internal representation of parsed expressions in a easily readable form (e.g. using graphviz or similar). The final program should produce sensible error messages if given ill-formed expressions. Well-formed expressions should be compiled into Forth code, which should be demonstrated to run correctly on the gForth interpreter.

The Specification

As part of your report on the assignment, you are expected to provide a specification of the languages and translations that are involved in your expression compiler. These should include:

  1. the tokens of the source (and target) language;
  2. the syntax of the statements and expressions of the source language;
  3. the syntax of the target language;
  4. a declarative description of the translation.

If you extend the system to deal with other features, such as floating point values, then these should also be described.

The Implementation

Your software should include distinct parts for the tokeniser, parser, and virtual-machine code generation. You should demonstrate the compilation of while-programs into the Forth language, and the execution of the generated code on the gForth interpreter. The implementation should be described in the report.

The Submission

The electronic submission should include the report — containing the specification and description of the implementation — and the implementation itself — both source files and compiled program. Instructions for running the program as submitted, should be included.

Ideally the report should be submitted as a properly formatted PDF file. Instructions for how to start the program from the command line should be given in a readme.txt file.

Please include a sample program that your compiler can compile. This should demonstrate the key features that are supported. (For example, if you language supports IF THEN ELSE, and WHILE, with complex Booleans, as well as "floats" and "ints", these should feature in your sample program.)

Remember:

  1. Any sources of other material, and the use of tools, should be acknowledged in the comments of the program source, and in the report.
  2. The report should describe how your program can be run from the command-line, e.g.
       java -jar MyCompiler 
    

    or

      java CE305.MyCompiler 
    

    Please also include this information in a readme.txt file with your submission.

    Make absolutely certain that the program as submitted can be run from the command-line as described. Try to ensure your program runs with JRE version 6 (or 1.6).

  3. Your report must include some explanatory narrative, describing what has been implemented, and how, highlighting particular features, or short-comings.

Do not forget to include your name and registration number in your report and in your submitted source files.

You will be expected to demonstrate your prototype program(s) in the lab session preceeding the submission (Tuesday, 13th December, CSEE Lab 3, 12–2pm).

Note: If the functionality of the submitted version differs significantly from the demonstrated prototype, this should be mentioned in the submitted report.

Draft Marking Scheme

Scheme provided for indicative guidance only
Specification (40%)
Definition of Tokens10
Grammar of Expressions15
Description of Translation15
Implementation (50%)
Basic operation20
Modularity10
Coding quality and/or use of tools10
Extended features10
Documentation (10%)
Clarity of documentation10%

THIS IS SUBJECT TO REVISION

Author: CSEE, University of Essex <foxcj _AT_ essex.ac.uk>

Date: Spring Term 2010/11

HTML generated by org-mode 6.21b in emacs 23