Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Calculator

Our first programming language is a simple calculator supporting addition and subtraction. This is perhaps the simplest language that helps us introduce the major topics from grammar to compilation and virtual machines.

If you haven’t cloned the GitHub repo already, please do and navigate to the calculator subdirectory.

To start, we have 1 + 1; in examples/simple.calc. First, build the project:

cargo build --bin main

This creates an executable at ../target/debug/main. Now run it on the example file:

../target/debug/main examples/simple.calc

Or simply combine both steps with:

cargo run --bin main examples/simple.calc