Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

DEPARTMENT OF COMPUTER SCIENCE SUMMATIVE COURSEWORK ASSIGNMENT BRIEF KEY INFORMATION

• Module title: Compilers

• Type of assignment: Programming exercise

• Individual/group assignment: Individual or Group

• Weighting of the assignment: 20%

• Expected hours spent on this assignment: 6 hours

• Items to be submitted: (1) PDF/Word report (2) Source Code

• Work to be submitted by: 12:00 midday on Mon 15 May 2023

PLAGIARISM

By submitting this assignment, you are certifying that it is all your own work. Any sentences, figures, tables, equations, code snippets, artworks, and illustrations in your source code repository must be original and must not have not been taken from any other person’s work, except where explicitly acknowledged, quoted, and referenced. You understand that failing to follow this requirement will be

considered plagiarism. Plagiarism is a form of academic misconduct and will be penalised accordingly. The University’s Statement of Academic Misconduct is available on the University web pages.


LATE SUBMISSION

If your work is submitted after the deadline, 10% of the maximum possible mark will be deducted for each working week (or part thereof). A mark of zero will be awarded if your work is submitted more than 2 working weeks late. It is strongly recommended that you hand work in by the deadline as a late submission of one piece of work can have an impact on other work.

If you believe that you have a valid reason for failing to meet a deadline, then you should complete an Exceptional Circumstances Form and submit it to the Student Support Centre before the deadline, or as soon as is practicable afterward, explaining why.


1. ASSESSMENT CLASSIFICATIONS

This coursework assesses your ability to understand, modify and test a compiler. You will gain credit for:

• writing code that compiles and correctly implements the features requested.


Your assignment will be marked according to the mark scheme. The mark scheme is designed so that the mark obtained in this way will correspond to the following qualitative degree classification descriptions:


Degree Classification Description

First Class (>= 70%) Excellent Upper Second Class (60-69%) Good Lower Second Class (50-59%) Satisfactory Third Class (40-49%) Poor

Pass (35-39%) Very Poor

Fail (0-34%) Inadequate


2. ASSIGNMENT DESCRIPTION

SUMMARY

You will be supplied with a simple compiler babycino for a subset of Java, similar to Appel and Palsberg’s subset MiniJava. Based on your student number, you will be allocated a new MiniJava feature. Modify the compiler to add support for the feature. Test your compiler to check it works correctly.

The coursework will be assessed solely on the code you submit. You will be penalised severely for submitting code that does not compile.

TASK DESCRIPTION

The babycino compiler discussed in lectures lacks support for several common Java features, including various comparison and equality operators, flow control structures and useful shorthands. Your task is to implement one new feature and write tests for another.


Your student number will be something like 28123456. To work out which features you must implement, look up the last digit of your student number in this table:


Last digit

Features

1 or 9

A. ==

0 or 4

B. !=

2 or 3

C. <=

5 or 7

D. >=

6 or 8

E. >


For example, if your student number was 28123456, you would look up 6 in the table, giving feature E.

It is important that you implement and test the correct features. You will be penalised for working on other features. Please check the table carefully before you start on the coursework.


Feature descriptions

You should be able to find descriptions of most of these features in any Java reference, so only a short description is given here. Where relevant, make sure you respect Java’s usual rules of operator precedence during parsing.

A. == equality

If x equals y, then x == y returns true; otherwise, it returns false. If x and y have different types, a type error occurs at compilation. You need only make it work for values of type boolean and int.

B. != inequality

If x equals y, then x != y returns false; otherwise, it returns true. If x and y have different types, a type error occurs at compilation. You need only make it work for values of type boolean and int.

C. <= less than or equals

If x and y are integers, with x less than or equal to y, then x <= y returns true; otherwise, it returns false. If x or y is not an integer, a type error occurs at compilation.


D. >= greater than or equals

If x and y are integers, with x greater than or equal to y, then x >= y returns true; otherwise, it returns false. If x or y is not an integer, a type error occurs at compilation.


E. > greater than

If x and y are integers, with x greater than y, then x > y returns true; otherwise, it returns false. If x or y is not an integer, a type error occurs at compilation.


Setup

The babycino compiler is provided through CSGitLab:

https://csgitlab.reading.ac.uk/ta918887/babycino

Babycino is written in Java, so you will need a Java development environment (JDK) to modify it. Clone your Git repository onto your computer, open a command prompt and navigate to the root directory of the repository. Run test.sh (Linux or MacOS) or test.bat (Windows). You should see some output, ending with PASS: 10 factorial OK. If you get an error message, you probably do not have a Java development environment correctly installed.

Use your favourite text editor to modify the compiler’s source code. It is probably best not to try using an IDE, as it will be difficult to get it to integrate properly with ANTLR. Remember to recompile by running build.sh or build.bat every time you change your code.


Subtask 1: Feature Parsing

Modify the compiler to parse the feature you are adding. You will need to change MiniJava.g4.

One way to check whether your changes work is to generate a parse tree for a MiniJava test program using grun and check it looks sensible.


Subtask 2: Feature Semantic analysis

Modify your compiler to reject programs with type errors.   You will probably need to change

TypeChecker.java.

One way to check whether your changes work is to try compiling a MiniJava test program and verify that you do not get a type error. (You may receive some other error, if you have not implemented code generation.) You could also write some test programs with type errors and check that you get a type error when trying to compile them.


Subtask 3: Feature Code generation

Modify your compiler to generate code for the features you added. You will probably need to change

TACGenerator.java.

For some features, you may be tempted to add a new intermediate code instruction to the intermediate language. However, this is likely to cause errors in the optimisation phase of the compiler, which will not know how to handle your new instruction. For this coursework, you must not add new intermediate language instructions to the compiler. If you do so, you will receive only partial credit for this task.

You should now be able to compile and run the relevant supplied MiniJava test programs in the directory progs/features/. If the programs compile, but do not give the right output, try turning on dumping of intermediate code by editing Babycino.java. By inspecting the output, you may be able to determine the problem.

If you are unsure what the correct behaviour of your program should be, you may find it helpful to recall that a MiniJava program should behave the same whether it is compiled by a MiniJava compiler or a Java compiler.


Presentation of your code

While you will not be assessed on the presentation of your code, you should make sure it is sensibly formatted and commented. You should not commit any temporary files or caches to your repository. Do not alter the directory structure of your repository, or the lecturer may be unable to find and test your code.


ADDITIONAL INFORMATION

Resources Supplied or Required

You will be able to download the babycino compiler from CSGitLab. The compiler uses the ANTLR parser generator from www.antlr.org. ANTLR and its libraries are included in the babycino repository, so you do not need to download them separately, but you may find it helpful to look at the ANTLR documentation.

You may use workstations on campus or your own computer. Please take care to backup your work periodically.


Group/Individual

You may also wish to discuss the coursework with other students. This is both permitted and encouraged. For this coursework, you may share code with other students, but all of you must have the same assignment based on your student number. If you use code written by another student, please check that you understand what it does and should indicate that the coursework is a group assignment and include the academic numbers and names of all collaborators in your report:

Your Name/Number:  Zhang San / 2020202 Collaborator_1 Name/Number: Li Si/ 2040202 Collaborator_2 Name/Number: Wang Wu/ 2040203

......

You will be penalised for submitting code that implements or tests features other than those allocated to you.

If you do not wish other students to use your code, please do not share it with them and indicate that you take an individual assignment:

Your Name/Number: Zhang San / 2020202 No collaborator.


3. ASSIGNMENT SUBMISSION REQUIREMENTS

(1) Report

It should include the following information on the front page of your report:



• Module title: Compilers

• Assignment title: Modifying a compiler_Feature (A or B or C... or E)

• Student Name/Number:

• Collaborator Name/Number: (If have)

• Date of completion:

• Actual time spent on the assignment (hours):


Describe your main idea and framework for completing the assignment, including the three subtasks. For Subtasks 1 and 3, you can refer to the framework for the second homework. For Subtask 2, review the lecture on type checking.


You can show the code for the modified methods or the corresponding parse tree in the corresponding section of your report. Pseudo-code or flowcharts that clearly express your logic are also acceptable.

(2) Source code

Please check carefully your source code of the modified compiler. If your code does not compile, but can be made to do so with a minor modification, you will lose the 10% for submitting code that compiles. If your code still does not compile, you can only score for tasks relating to parsing and reports, making your maximum possible mark 40%.

Please check that you have added the correct feature, and only this feature. If you submit code that implements additional features, you will score zero for the modifications to your compiler, making your maximum possible mark 70%.

Please zip the report and source code, and name the package as "Student number_Name_Feature_x", for example: 2020202_ZhangSan_Feature_E.


By the deadline, please submit both your REPORT AND SOURCE CODE to [email protected]. The email subject is the same name as the name of your assignment package.


We will use information about how long you spent on the assignment when we review and balance coursework between modules for later years. An exact answer is not necessary, but please try to give a reasonable approximation.


4. MARKING SCHEME

Marks available for the assignment are subdivided as shown below.

1. 30%: You have submitted a report that provides a good statement of the main ideas or framework for achieving your assignment.

2. 10%: Your code compiles without modification.

3. 10%: Your compiler still runs the included test script successfully.

4. 10%: Subtask 1: Feature — Parsing

• Your compiler can parse the sample program sensibly.

5. 10%: Subtask 2: Feature — Semantic Analysis

• Your compiler permits the sample program and rejects incorrectly typed programs.

6. 30%: Subtask 3: Feature — Code Generation

• Your compiler can compile the sample program correctly.


You will usually be awarded full credit for successfully completing each part. In some cases, partial credit (not more than half) may be awarded for a reasonable but incomplete or incorrect attempt.