rustcc 0.0.2-1

An little C Complier( now it's just WIP :) )
rustcc-0.0.2-1 is not a library.

RustCC - Rust Expression Calculator

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.

Features

  • Supports basic arithmetic operations: addition(+), subtraction(-), multiplication(*), division(/)
  • Follows operator precedence rules
  • Scanner converts input text into tokens
  • Parser constructs Abstract Syntax Tree (AST)
  • Interpreter traverses AST and computes results
  • Comprehensive error handling

Installation and Build

  1. Ensure you have the Rust development environment installed. If not, visit rust-lang.org to install it.

  2. Clone or download the project code to your local machine

  3. Navigate to the project directory

cd rustcc_dev
  1. Build the project
cargo build --release

Usage

After building, you can run the calculator in the following ways:

# Using a test input file
cargo run test_input.txt

# Passing an expression directly as an argument
cargo run "10 + 20 * 3 - 40 / 5"

Example

Input expression: 10 + 20 * 3 - 40 / 5

Output result: 62

Project Structure

rustcc_dev/
├── .gitignore
├── Cargo.lock
├── Cargo.toml
├── README.md
├── README_EN.md
├── src/
│   ├── ast.rs       # Abstract Syntax Tree definitions
│   ├── interpreter.rs  # Interpreter implementation
│   ├── main.rs      # Program entry point
│   ├── parser.rs    # Syntax parser
│   └── scanner.rs   # Lexical scanner
└── test_input.txt   # Test input file

Contribution Guidelines

Contributions to the project are welcome! If you have any improvement suggestions or find bugs, please submit an issue or pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.