CSC254 Intra-function Code Generation Assignment

Due by 11:59pm 10/04/2010 and 11:59pm 10/11/2010

In this assignment, you are required to modify your parser to generate assembly-like code for each function in a input program.  The specific requirements are as follows.

  • Copy all meta statements (the lines that begin with #) to the output file.
  • The output program uses the same grammar as the input program with the following modifications.
  • Grammar modification for assignment and expression: (i.e. an assignment statement can have at most 2 operands on the right-hand side.) (for the first deadline)
    • <assignment> --> <id> equal_sign <operand> <operation> <operand> semicolon | <id> equal_sign <operand> semicolon
    • <operand> --> NUMBER | <id>
    • Change all mentionings of <expression> with <operand>, as in <id>, <func call>, <return>, and <condition>.
  • Grammar modification for control flow: (i.e. all intra-function control flow is changed to gotos and if-gotos.)
    • <if-statement> --> if left_parenthesis <operand> <comparison op> <operand> right_parenthesis goto LABEL semicolon
    • <goto-statement> --> goto LABEL semicolon
    • <label-statement> --> LABEL colon
    • LABEL is just another name for ID token
  • Grammar modification for functions: (i.e. no expression is in arguments passing and value return.)
    • Function declaration and definition remain unchanged.
    • In <func call>, each parameter must be <id> instead of <experssion>.
    • In <return>, use <id> instead of <expression>.
  • The output program should be compilable by a C compiler (i.e. can be compiled by gcc successfully) and have the same behavior as the input program.  In addition, your compiler should still be able to parse and compile the code generated by your compiler for the expression generation step of the project (Item 3 above).
  • Do not use a scanner or parser generator for writing your compiler.

What/When/Where to Submit

There are two deadlines for this assignment. The first is the code gen only for expressions (Item 3 in the list). The TA will provide feedback. The second is for the rest of code genenration specified above. The complete submission will be graded by the TA.
Turn in your code with a report of your design including instructions to run your compiler. In the report, write down the name of passed test cases and the reasons for failure in other test cases. List the provided test cases first (tests in change-set 23) and then those provided by you and others. Submit the files in project_code/intra/user_id by the two deadlines.  It is fine the files in the last revision overwrites those in previous revisions.