Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due
COP 3402: Systems Software Summer 2025 Due Date: [July 20th 2025 by 11:59 p.m.]
Assignment Overview
For this assignment, you will extend your existing PL/0 compiler (from HW3) to:
1. Implement new grammar elements involving procedure, call, and else clause in if statements.
2. Update your HW1 Virtual Machine (VM) to recognize and execute the modulo (mod) instruction (OPR 0 11).
3. Generate an executable file named elf.txt, which will serve as the input for your updated VM.
4. Demonstrate correct parsing, symbol table management, and code generation for these extended grammar features.
Objective
You must create a Recursive Descent Parser and Code Generator for the extended PL/0 language. In particular:
- Procedures must be supported via procedure-declaration and the call statement.
- if statements must include an else part, ensuring complete code generation paths in both branches.
- The mod operator must be recognized in the grammar and translated to 2 0 11.
- The elf.txt output should be directly usable by your updated VM from HW1.
Component Descriptions
Your compiler must:
- Accept PL/0 source code from a file specified on the command line (e.g., ./a.out input.txt).
- Detect both lexical and syntactical errors, halting with a clear message if any occur.
- Generate correct code for the extended language constructs, including procedure declarations, call statements, and else block in if statements.
- Build and maintain a symbol table that supports multiple lexical levels (for nested procedures).
Submission Requirements
I. Essential Files
Submit the following in a single submission.zip archive via WebCourses:
- hw4compiler.c: Your primary compiler source file.
- vm.c: Your updated VM from HW1, now capable of handling the modulo instruction (2 0 11).
- Any additional files needed to compile your hw4compiler.c and vm.c.
- README.md: Instructions on how to compile and run your compiler and VM.
- One sample input file (correct PL/0 program) plus its corresponding elf.txt output file.
- A folder of test cases: At least two distinct test cases demonstrating procedure and call usage, plus error scenarios.
II. Formatting and Delivery
- Your compiler must read the input filename from the command line.
- Your compiler must display generated instructions in the terminal in the format:
OPcode L M
for example:
LIT 0 10
• Your compiler must also create an elf.txt file containing machine codes for the VM to execute. for example:
1 0 10
• The symbol table must be displayed in the terminal in the format:
Kind | Name | Value | Level | Address | Mark
III. Additional Guideline
- Include clear comments throughout your code
- List all team members in both README.md and source code header
- Only one team submission will be graded.
-
Your submission must compile and run on Eustis. If it does not compile, the score is 0.
- No late submissions will be accepted after two days past the deadline.
- Ensure your submission contains all necessary files to compile and run on Eustis
Error Handling
- If your compiler encounters an error (lexical, syntactic, or semantic), it should:
(a) Print a concise error message to the terminal (e.g., Error: undeclared identifier x).
(b) Halt further compilation immediately.
- Inherit the error types and messages from HW2 and HW3.
Output Specification
When Errors Occur
If your compiler identifies any error, it should:
1
When No Errors Are Found
If the source program is valid:
1. Display the input PL/0 program in the terminal.
2. Display the message: No errors, program is syntactically correct.
3. Print the generated assembly instructions to the terminal using mnemonic OP codes (e.g., JMP 0 30) along with the line number and the complete symbol table.
4. Create a file named elf.txt containing the numeric op codes (e.g., 7 0 30), which your VM can load and execute.
Important: The assembly code and symbol table must be printed directly to the terminal, not saved to a file. Only the elf.txt file should be created as a separate output file.
Specific Requirements
• Modifying the Lexical Scanner: Replace any legacy oddsym token with modsym = 1. Notice that grammar is slightly different that the grammar of HW3.
• Procedure Declarations: Must appear in the procedure-declaration section of the grammar.
• Call Statement: Invokes a procedure by its identifier.
• if-else Clause: The if statement must contain an else block before fi. Omission of else is not allowed.
•
First Instruction: Must always be JMP 0 <some address>.
Lexical Conventions
A numerical value is assigned to each token (internal representation) as follows:
Important: modsym is a new reserved symbol introduced in this homework with token value 1. It represents the modulo operator in the grammar.
VM Instruction for Modulus
The modulus operation should be implemented using OPR 0 11 with the following behavior:
Failure to implement the mod instruction exactly as OPR 0 11 (or displayed as MOD 0 11 in assembly) will result in an automatic zero.
Grading Rubric
Your assignment starts with a base score of 100 points. The following deductions apply:
Critical Errors (Automatic Zero)
• -100 points: Does not compile on Eustis. This includes:
– Compilation errors preventing generation of the executable file
– Program produces immediate segmentation fault
– Program crashes while running grading test cases
•
-100 points: Does not accept input filename from command line (e.g., ./a.out input file.txt)
• -100 points: Compiler follows a different grammar than specified in section Appendix B
• -100 points: Submitting HW3 again without implementing procedures and call
• -100 points: Using any method other than the marking algorithm for symbol table management. The implementation must explicitly use the mark column to track symbol availability. Alternative implementations will be considered plagiarism.
VM Implementation Issues
• -30 points: HW1’s modified VM source code (vm.c) is not submitted
• -30 points: HW1’s VM source code is not modified to support the modulo instruction as specified
• -10 points: HW1’s VM does not support the same I/O specification as the compiler
Fundamental Implementation Issues
• -80 points: Compiles but does nothing
• -70 points: Produces some instructions before segfaulting or looping infinitely
• -30 points: Not implementing procedures in the ”block” correctly
• -30 points: Not implementing call statements correctly
• -15 points: Incorrect implementation that generates wrong instructions for if-else statements
Error Handling and Code Generation
• -10 points: Not supporting error handling for procedures (including error messages)
• -10 points: Not supporting error handling for call (including error messages)
• -10 points: Does not generate the elf.txt executable file for the VM
• -10 points: Does not display the generated instructions in the terminal
Symbol Table and Scope Management
• -10 points: Program does not handle variables with the same name at different levels correctly
• -10 points: Level information not managed correctly (global environment should be level 0, with procedures incrementing accordingly)
• -10 points: Marking algorithm for symbol table management does not work correctly. Every symbol must have a mark of 0 upon initial insertion and a mark of 1 once they are no longer usable. This mark column must be explicitly used as the mechanism for tracking symbol availability.
Instruction Generation Accuracy
• -5 points per occurrence: JMP instruction’s M, JPC instruction’s M, or CAL instruction’s M not fully divisible by 3 after the subtraction of 10.
• -5 points per occurrence: JMP, JPC, or CAL instruction not leading to the correct index in the code list
Documentation and Testing
• -5 points: No README.txt containing author names
• -2.5 points: No sample input file and sample output file
• -2.5 points: No test cases folder
Output Format and Compatibility
- -5 points: Significantly misaligned output format compared to the examples in section Appendix A for both correct and error cases. Your output must match overall structure shown in the examples, the spacing and alignment can be different as long as it is readable.
- -30 points: If your modified HW1 VM (vm.c) fails to correctly process the elf.txt file produced by your compiler. Your VM must be able to read and execute the compiler’s output without errors.
Note: Multiple deductions may apply to a single submission. The minimum score is 0.
Helpful Hints:
• Focus on implementing exactly what’s in the grammar specification - no more, no less
• Remember that error detection should immediately halt processing
• Ensure your symbol table only contains entries that appear in the actual input
• Test your implementation against all error cases listed in section Appendix C
• Interpret the grammar carefully rather than following pseudocode examples blindly
• Double-check your implementation against the grammar rules before submission