Milestone 3: Interface
In this third milestone of the spreadsheet project, you have two tasks: add statement nodes to the language model and develop an terminal-based user interface using the Curses library. With the statements, users will be able to write multiline computations. With the interface, users will be able to move around to different cells using the cursor keys, enter formulas, and view the results.
Statement Nodes
Add the following items to your node hierarchy:
-
A print node for statements like
print(x + 1). When evaluated, it prints the primitive value of its expression on its own line—but don't print directly to stdout. Instead collect the output in a string buffer managed by your runtime abstraction. That way the user interface library can fetch the text and display it in its custom way. -
An assignment node for statements like
x = 7 ** 2. When evaluated, it stores the primitive value of its expression in a collection of local and temporary variables managed by your runtime abstraction. -
A variable rvalue node for expressions like
x. When evaluated, it looks up the variable's value in the runtime abstraction. -
A block node for sequences of statements separated by linebreaks. When evaluated, it evaluates each of its statements sequentially and returns the value of its last statement. For example, consider this block:
It evaluates to 65.
x = 7 ** 2 y = 8 << 1 print(x) print(y) x + yx = 7 ** 2 y = 8 << 1 print(x) print(y) x + y
For each node type, complete these steps:
- Define its class.
- Add its visit method to your translator.
- Add its visit method to your evaluator.
- Add rules to your grammar, inserting new nonterminals as necessary.
- Add logic to your lexer and parser.
- Add tests to ensure they work correctly.
Write a short multiline program that incorporates all of these new nodes, model it in Treeformer, and add a screenshot of the AST in your grammar folder.
Curses
Build a user interface for your spreadsheet using Curses or some similar library for terminal drawing and support the following features:
- Three windows: the cell grid, a multiline formula editor, and the expanded display. Show all three windows at the same time.
- The grid is labeled by its column and row numbers, and each cell shows a truncated version of its primitive value.
- When a cell is selected, it is highlighted in some manner, its source shows in the editor, and its AST is reevaluated. Show its output and its value or error in the expanded display.
-
If the source starts with an
=, it is code that must be lexed and parsed. If the text doesn't start with=but is an integer, float, or boolean, treat it as a model primitive. Otherwise, treat the input as plain string. - A cell gets updated when a cell it depends on changes.
- The grid may be read from a file passed as a command-line argument and written back to this same file.
- The user may scroll infinitely.
Support two additional features of your choosing, like color, multiple tabs, mouse navigation, and filling.
Instead of writing the user interface code by hand, you will get an LLM to do most of the labor. You may love LLMs, or you may hate them. You may bristle at how they exploit free labor and threaten the environment. You may relish how they will bring down the system. No matter your stance, LLMs will be interoperating with the systems you build, and the goal of this assignment is to get experience with that. Pick any LLM you want.
Document in a readable word document every step of your process in getting the LLM to do what you want. It might be a long document. Share the configuration files you make. Use planning mode to iterate on the task before generating any code. Paste in the chat interactions. Include reflections on what works well and what doesn't. Clearly mark the sections that describe your two additional features. Reflect on the experience.
Submission
To submit your milestone, follow the instructions. In particular, do these three things:
- Submit your project to the official GitHub repository that your instructor made for you.
- Record a 3–5 minute screencast of you walking through your code and commenting on it. Do not exceed 5 minutes. Your instructor has many videos to watch. Post it to Canvas Studio according to the instructions.
- Complete the ready date submission form on Canvas.
In your video, demonstrate interacting with the grid, entering new formula, editing formula that trigger updates, displaying errors on malformed code, scrolling infinitely, and your two new features. In particular, reconstruct this spreadsheet:
-
Enter
5.3in cell 0, 0. -
Enter
-4.1in cell 1, 0. -
Enter
10.8in cell 2, 0. -
Enter
0.0in cell 0, 1. -
Enter
-2.5in cell 1, 1. -
Enter
4.4in cell 2, 1. - Enter formulas in nearby cells to compute the min, max, sum, and mean across this rectangle of six cells.
-
Enter
100in cell 4, 0. -
Enter
3in cell 4, 1. -
Enter
=#[4, 0] * #[4, 1]in cell 4, 2. Use whatever rvalue syntax you chose in milestone 2. -
Edit the
100and3and demonstrate that the product automatically updates. -
Enter
9in cell 5, 0. -
Enter
falsein cell 5, 1. -
Enter
=#[5, 0] << #[5, 1]in cell 5, 2. It should show the type error but not crash. -
Enter this program:
Confirm that the correct result appears in the grid and that the output displays.
x = 7 ** 2 y = 8 << 1 print(x) print(y) x + yx = 7 ** 2 y = 8 << 1 print(x) print(y) x + y
Have some of these formulas stored in a file that you load in, and enter the others on the fly.
Don't comment on or show every single line of code in your video. Select a few representative snippets. Do comment on programming language ideas that interest you or challenged you.