| Crates.io | rustcc |
| lib.rs | rustcc |
| version | 0.1.1 |
| created_at | 2025-08-13 09:20:10.155693+00 |
| updated_at | 2025-08-15 15:50:14.661453+00 |
| description | An little C Complier( now it's just WIP :) ) |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1793463 |
| size | 50,677 |
RustCC is a simple expression calculator implemented in Rust, supporting basic mathematical operations (addition, subtraction, multiplication, division). This project demonstrates how to implement lexical analysis, syntax analysis, Abstract Syntax Tree (AST), and an interpreter using Rust.
This project supports the following operating systems:
On Linux and macOS, you may need to install additional dependencies such as build-essential on Ubuntu or Xcode Command Line Tools on macOS.
Clone or download the project code to your local machine
Navigate to the project directory
cd rustcc_dev
cargo build --release
After building, you can run the calculator in the following ways:
# Using a test input file (default: precedence parser)
cargo run test_input.txt
# Using a specific parser
cargo run -- --parser=precedence test_input.txt
cargo run -- --parser=recursive test_input.txt
# Passing an expression directly as an argument
cargo run -- "10 + 20 * 3 - 40 / 5"
# Generate assembly code and executable
cargo run test_input.txt
./out.exe
The calculator now uses the precedence parser by default. You can specify the parser type using the --parser option.
Input expression: 10 + 20 * 3 - 40 / 5
Output result: 62
rustcc_dev/
├── .gitignore
├── Cargo.lock
├── Cargo.toml
├── README.md
├── README_CN.md
├── src/
│ ├── ast.rs # Abstract Syntax Tree definitions
│ ├── codegen.rs # Code generator for x86-64 assembly
│ ├── interpreter.rs # Interpreter implementation
│ ├── main.rs # Program entry point
│ ├── parser.rs # Recursive descent parser
│ ├── precedence_parser.rs # Operator precedence table parser
│ └── scanner.rs # Lexical scanner
└── test_input.txt # Test input file
Contributions to the project are welcome! If you have any improvement suggestions or find bugs, please submit an issue or pull request.
This project is licensed under the MIT License. See the LICENSE file for details.