Skip to content

ParinArora/paincompile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

paincompile Compiler

paincompile is a minimal compiler written in Rust that translates a small subset of a C-like language (TinyC) into assembly (targeting ARM64 on macOS or optionally x86). This project is designed to help you understand the basics of compiler design—including lexing, parsing, AST construction, and code generation—while working with low-level architecture concepts.

Table of Contents

Project Overview

The TinyC Compiler processes TinyC source code in several stages:

  1. Lexical Analysis: Convert raw source code into tokens.
  2. Parsing: Build an Abstract Syntax Tree (AST) from tokens.
  3. Code Generation: Traverse the AST and produce assembly code.
  4. Assembly & Linking: Use system tools to assemble and link the generated assembly into an executable.

The project serves as a hands-on demonstration of how high-level constructs are translated into low-level instructions.

Project Goals and Milestones

Goals

  • Implement a lexer to convert TinyC source files into a stream of tokens.
  • Build a recursive descent parser that constructs an AST.
  • Create a code generator that outputs assembly code (target ARM64 on macOS, with potential x86 support).
  • Develop a build script to assemble, link, and run the compiled code.
  • Provide thorough documentation and tests for the compiler components.

Milestones

  1. Project Initialization

    • Set up the repository, file structure, and basic module files.
    • Write initial skeletons for lexer, parser, AST, and code generator.
  2. Lexer Development

    • Define token types (e.g., keywords, identifiers, literals, operators, punctuation).
    • Implement functions to scan and tokenize a TinyC source file.
  3. Parser Development

    • Create a grammar for TinyC (supporting declarations, assignments, expressions, and print statements).
    • Implement a recursive descent parser that builds the AST.
  4. AST and Code Generation

    • Define data structures for expressions and statements.
    • Write a code generation module that produces ARM64 assembly (Darwin ABI) from the AST.
  5. Tooling and Testing

    • Develop unit tests for each module.
    • Write a shell script (build.sh) to streamline assembling, linking, and running the generated assembly.
    • Document usage and implementation details in this README.
  6. Enhancements (Optional)

    • Extend language features (e.g., conditionals, loops, functions).
    • Consider adding basic optimizations in code generation.
    • Implement a simple REPL for TinyC.

This Repository is a work in progress and all goals listed above have not yet been accomplished

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors