Code Formatter

Overview

In this assignment, you will design and implement code formatter (pretty printer) for the language described in the lexer, parser, and interpreter assignments. Your program will take syntactically valid, but possibly poorly formatted code, and produce a neatly formatted version according to a fixed style guide.

The goal is to deepen your understanding of program structure, syntax trees, and the relationship between syntax and presentation, while practicing robust handling of nested and compound statements.

Formatting Rules

Your code formatter must output code following exactly these rules.

General Rules

Braces

Expressions

Parentheses

Specifications

The program takes a command line argument indicating the text file with the source code. The output of the program is a formatted version of the same program, written to standard output. The output must follow exactly the formatting rules described above

Example:

Input file contents
if(x){y=1;}else{if(y){z=2;}}

Output
if (x) {
    y = 1;
} else {
    if (y) {
        z = 2;
    }
}

Turning in the Assignment

To submit your assignment, create a zip file of a DIRECTORY named formatter-handin containing ONLY the files required to build the project. The project must build with dune. Then submit that file to the appropriate folder on D2L.

Grading Criteria

OCaml Style Guide

Programming Project Rubric