PROJECT 4

The project consists of a basic task and a number of additional features, which will count for extra credit. The additional features are divided into two categories, according to how hard they are to implement. The harder categories will count for approximately three times the easier ones. Most of the features involve augmenting the Basic Task grammar below. Submit only one compiler including whatever features you have included together with a list of the features involved.

BASIC TASK

Write a compiler which produces an object module for the language defined by the following grammar:

program → list_declarations list_statements

list_declarations → list_declarations declaration

declaration → int list_identifiers ;

list_identifiers → list_identifiers , identifier | identifier

list_statement → list_statement statement | statement

statement → input_statement | output_statement | assignment_statement

| while_statement | if_statement

input_statement → input identifier ;

output_statement → output list_entries ;

list_entries → list_entries entry | entry

entry → expression | string

expression → expression + term | term

term → primary

primary → identifier | ( expression )

assignment_statement → identifier = expression ;

while_statement → while_prefix list_statements wend ;

while_prefix → WHILE condition

WHILE → while

condition → expression = expression | expression > expression

| expression ≤ expression | expression ≥ expression

if_statement → if condition list_statements end if ;

a. Use registers SI, DI wherever possible for arithmetic calculation, keeping track of whether they are free or not. A register becomes not free when a number is put into it, and becomes free at the end of a statement.

b. Make use of the getdec and putdec routines in utility.lib for inputting and outputting numbers.

c. Allow multiline comments as described in Assignment 3.

EASIER ADDITIONAL FEATURES (in no particular order)

1.  Implement subtraction and division and the use of the unary minus

2.  Implement the DO statement as described in Set 11.

3.  Treat constants that occur in the program as identifiers, e.g. in x = y + 324, the 324 should be treated as an identifier whose name is “324” by Lex, except that the number 324 should be placed at the offset involved in the LE_data record for the data segment

4.  As in Project 1, add, as an optional feature for the user, the creation of a cross-reference list.

5.  As in Project 2, include the ability to pinpoint where syntax errors occur, and to continue parsing the source program for additional errors.

6.  Output pairs of LE_data records for the code segment and corresponding fixups. (Here is most of the code for this).

HARDER ADDITIONAL FEATURES

7.  Implement short-circuit evaluation, as described in Set 12, for the condition that occurs in the WHEN and IF statements (and employ the productions given in Set 12 for the IF statement).

8.  Implement floating point numbers as described here

9.  Implement external subroutineswith call by reference and which restore the stack, as described in the Review of Assembler.