Thanks to visit codestin.com
Credit goes to lib.rs

#compiler #ast #educational #language-compiler

bin+lib ag-c

The ag language compiler - a Rust-inspired functional language

1 unstable release

0.1.0 Oct 9, 2025

#136 in Visualization

Codestin Search App Codestin Search App Codestin Search App Codestin Search App

213 downloads per month

MIT/Apache

140KB
3.5K SLoC

ag - A Rust-Inspired Functional Language

Build Status License Phase

ag is a Rust-inspired functional programming language that compiles to native machine code. The project emphasizes clarity, correctness, and learning through incremental development.

๐ŸŽฏ Project Goals

  • Educational: Learn compiler construction through hands-on implementation
  • Incremental: Build features phase-by-phase, achieving milestones along the way
  • Observable: Every compilation stage produces human-readable visualizations
  • Test-Driven: Comprehensive test coverage from day one
  • Documented: Living documentation that evolves with the language

๐Ÿš€ Quick Start

# Build the compiler
cargo build --release

# Compile an ag program (once implemented)
./target/release/ag examples/hello.ag -o hello

# View compilation stages
./target/release/ag examples/hello.ag --stage 1  # Lexer
./target/release/ag examples/hello.ag --stage 2  # Parser

๐Ÿ“Š Development Status

Phase Feature Version Status
0 Foundation & Tooling - โœ… Complete
1 Lexical Analysis 0.1.0 โœ… Complete
2 Parsing & AST 0.2.0 โœ… Complete
3 Semantic Analysis 0.3.0 โœ… Complete
4 Conditionals 0.4.0 ๐Ÿ”’ โณ In-Progress
5 Loops (Turing-Complete!) 0.5.0 ๐Ÿ”’ Locked
6 Intermediate Representation 0.6.0 ๐Ÿ”’ Locked
7 Code Generation 0.7.0 ๐Ÿ”’ Locked
8 Standard Library 0.8.0 ๐Ÿ”’ Locked
9 Optimizations 0.9.0 ๐Ÿ”’ Locked
10 Advanced Features 1.0.0 ๐Ÿ”’ Locked

See ROADMAP.md for the complete development plan.

๐Ÿ”ง What's Working Now

Phase 0: Foundation โœ…

  • โœ… Project structure and build system
  • โœ… CLI with argument parsing
  • โœ… Error handling with beautiful diagnostics
  • โœ… HTML/SVG visualization framework
  • โœ… Test infrastructure and utilities
  • โœ… Documentation generation system

Coming in Phase 1: Lexical Analysis

  • Tokenization of source code
  • Keywords, operators, identifiers, literals
  • Syntax-highlighted token visualization
  • Line/column error reporting

๐ŸŽจ Language Preview

Here's what ag will look like (Phase 2+):

// Factorial function
fn factorial(n: i32) -> i32 {
    let result = 1;
    let i = 1;
    while i <= n {
        result = result * i;
        i = i + 1;
    }
    return result;
}

fn main() -> i32 {
    let x = factorial(5);
    print_i32(x);  // Phase 8: stdlib
    return 0;
}

๐Ÿ“š Documentation

๐Ÿงช Testing

# Run all tests
cargo test

# Run tests for a specific phase
cargo test phase_01

# Run with verbose output
cargo test -- --nocapture

# Update snapshot tests
cargo insta review

๐Ÿ› ๏ธ Development

Prerequisites

  • Rust 1.70 or later
  • Basic understanding of compilers (helpful but not required!)

Project Structure

ag-compiler/
โ”œโ”€โ”€ src/           # Compiler implementation
โ”œโ”€โ”€ tests/         # Test suites by phase
โ”œโ”€โ”€ docs/          # Technical documentation
โ”œโ”€โ”€ man/           # User manual
โ”œโ”€โ”€ examples/      # Example programs
โ””โ”€โ”€ scripts/       # Build and documentation scripts

Building

# Debug build
cargo build

# Release build (optimized)
cargo build --release

# Run clippy (linter)
cargo clippy

# Format code
cargo fmt

Contributing

We welcome contributions! Please:

  1. Read the current phase in ROADMAP.md
  2. Check open issues for tasks
  3. Write tests for new features
  4. Update documentation
  5. Submit a pull request

๐ŸŽ“ Learning Resources

The ag compiler is designed as a learning project. Here are resources that inspired it:

๐Ÿ“– Core Principles

Test-Driven Development

Every feature comes with comprehensive tests. Tests accumulate across phases to ensure backward compatibility.

Incremental Complexity

The language grows one feature at a time. Each phase is complete and working before moving forward.

Visualization First

Every compilation stage produces a human-readable visualization for debugging and learning.

Living Documentation

Documentation is written as features are implemented and locked at phase completion.

๐ŸŽฏ Milestones

  • Phase 5 Complete: Language achieves Turing-completeness ๐ŸŽ‰
  • Phase 7 Complete: First working compiler producing executables ๐Ÿš€
  • Phase 10 Complete: Version 1.0 - Feature-complete language โญ

๐Ÿ“„ License

Licensed under either of:

at your option.

๐Ÿค Acknowledgments

  • The Rust community for excellent tooling and documentation
  • Cranelift for providing a fantastic code generation backend
  • All contributors who help build ag

Let's build a compiler together! ๐Ÿš€

For questions or discussions, open an issue on GitHub.

Dependencies

~7โ€“9.5MB
~171K SLoC