YAWL is a Rust project with the ambition to become a CA-Clipper language compiler. This project showcases the learning experience of reimplementing the old compiler for the classic CA-Clipper language. It features a comprehensive pipeline including lexical analysis, parsing, intermediate representation (IR) generation, and assembly code production.
Note: This project is currently in active development and may undergo significant changes. It is part of the YouTube series Rust Compiler for CA-Clipper, which documents the journey of building this compiler from scratch.
The project is organized into two main components:
core
: The heart of the compiler implementationstdlib
: A growing standard library for the language
The core component is composed of the following crucial modules:
lexer.rs
: Performs lexical analysis, breaking down the source code into tokensparser.rs
: Constructs an Abstract Syntax Tree (AST) from the token streamir.rs
: Generates an Intermediate Representation (IR) from the ASTassembler.rs
: Transforms the IR into x86-64 assembly codemain.rs
: Serves as the entry point, orchestrating the entire compilation process
To build and run this project, you'll need:
- Rust and Cargo (latest stable version recommended)
- GCC (GNU Compiler Collection)
GCC is used in the final step of the compilation process to assemble and link the generated assembly code into an executable.
To build the project, execute the following command in the project root:
cargo build
This command builds both the core compiler and the standard library.
To compile a YAWL source file, use:
cargo run -- <source_file>
Replace <source_file>
with the path to your YAWL source file.
The compiler will display the tokens, AST, IR, and assembly code for the input program. It then uses GCC to compile the assembly into an executable.
Currently, YAWL generates x86-64 assembly and is therefore limited to x86-64 processors. However, there are plans to expand support to ARM processors, particularly to enable macOS support on Apple Silicon machines.
At present, YAWL supports:
- Integer literals
- Variable assignment
- Function calls
- Basic arithmetic operations (implemented through function calls)
Here's a simple example of YAWL code:
result := add(5, 3)
print(result)
- Implement additional language features (e.g., control flow structures, expanded type system)
- Introduce optimizations in IR and assembly generation
- Extend the standard library with more utility functions
- Enhance error handling and reporting
- Add support for ARM processors
We welcome contributions to the YAWL project! Feel free to submit a Pull Request or open an Issue for discussion.
This project is licensed under the MIT License.