|
| 1 | +# bracket |
| 2 | + |
| 3 | +A compiler connecting two educational intermediate languages: [exprs-lang-v7](https://www.students.cs.ubc.ca/~cs-411/2022w2/v7_Languages.html#%28def._%28%28lib._cpsc411%2Flangs%2Fv7..rkt%29._exprs-lang-v7%29%29), Racket's subset from UBC's [CPSC411](https://www.students.cs.ubc.ca/~cs-411/2022w2/index.html) (Compiler Construction) course, and [Bril](https://capra.cs.cornell.edu/bril/), the Big Red Intermediate Language. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +`bracket` compiles programs from exprs-lang-v7 to Bril JSON. This enables Racket's expressive subset to serve as a rich frontend for generating Bril programs. |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +### Prerequisites |
| 12 | + |
| 13 | +1. **Install Racket** |
| 14 | + ```bash |
| 15 | + # Download from https://racket-lang.org/ |
| 16 | + ``` |
| 17 | + |
| 18 | +2. **Install CPSC411 compiler library (2022w2 version)** |
| 19 | + ```bash |
| 20 | + raco pkg install https://github.com/cpsc411/cpsc411-pub.git?path=cpsc411-lib#2022w2 |
| 21 | + ``` |
| 22 | + |
| 23 | +3. **Install Bril tools** (for interpreting/viewing output) |
| 24 | + ```bash |
| 25 | + # Follow instructions at https://github.com/sampsyo/bril |
| 26 | + ``` |
| 27 | +### Building bracket |
| 28 | + |
| 29 | +```bash |
| 30 | +raco exe -o bracket bracket.rkt |
| 31 | +``` |
| 32 | + |
| 33 | +## Usage |
| 34 | + |
| 35 | +### Basic Compilation |
| 36 | + |
| 37 | +Compile an exprs-lang-v7 program to Bril JSON: |
| 38 | +```bash |
| 39 | +./bracket tests/fib_recursive.rkt |
| 40 | +``` |
| 41 | + |
| 42 | +### View as Bril Text |
| 43 | + |
| 44 | +Convert the JSON output to human-readable Bril text: |
| 45 | +```bash |
| 46 | +./bracket tests/fib_recursive.rkt | bril2txt |
| 47 | +``` |
| 48 | + |
| 49 | +### Interpret with brili |
| 50 | + |
| 51 | +Execute the compiled program: |
| 52 | +```bash |
| 53 | +./bracket tests/fib_recursive.rkt | brili |
| 54 | +``` |
| 55 | + |
| 56 | +**Expected output:** `55` (the 10th Fibonacci number as computed in `tests/fib_recursive.rkt`) |
| 57 | + |
| 58 | +## Example |
| 59 | + |
| 60 | +**Input** (`tests/fib_recursive.rkt`): |
| 61 | +```racket |
| 62 | +(module |
| 63 | + (define fib |
| 64 | + (lambda (n) |
| 65 | + (if (call <= n 1) |
| 66 | + 1 |
| 67 | + (call + (call fib (call - n 1)) |
| 68 | + (call fib (call - n 2)))))) |
| 69 | + (let ([arg.x 10]) |
| 70 | + (call fib arg.x))) |
| 71 | +``` |
| 72 | + |
| 73 | +**Output:** Bril JSON program that computes the 10th Fibonacci number |
| 74 | + |
| 75 | +## References |
| 76 | + |
| 77 | +- [More about bracket](https://www.cs.cornell.edu/courses/cs6120/2025fa/blog/bracket/) |
| 78 | +- [exprs-lang-v7 Grammar](https://www.students.cs.ubc.ca/~cs-411/2022w2/v7_Languages.html) |
| 79 | +- [CPSC411 Course Materials](https://www.students.cs.ubc.ca/~cs-411/2022w2/index.html) |
| 80 | +- [Bril Documentation](https://capra.cs.cornell.edu/bril/) |
0 commit comments