Skip to content

GavinSadler/compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Language Design

int z = 20;

void main() {
    int x = 5;

    int y = add(x, 10);

    print(y);

    hello_world();
    
    {
        int w = 120;
    }

    print(w); // Error!

    return 0;
}

int add(int a, int b) {
    return a + b;
}

void hello_world() {
    print("Hello world!")
}

Basic data types

void, int, float, boolean, string, char

Stages

Lexer/scanner
    Picks out keywords and scanns things like strings, names, etc.

Parser
    Ensure language structure is valid and generate an Abstract Syntax Tree (AST)
    (Note - In Rust project, lexing/parsing may happen in the same step 🤔)

Declaration Resolution
    Make sure all variables are allocated correctly and scope is respected throughout the program

Typecheck
    Ensure types resolve correctly in the AST

Intermediate Representation (IR)
    Converts our AST into some intermediate type language. Usually assembly-like.

Optimization
    Run through our AST/IR and perform optimizations to the code

Code Generation
    Translate abstract sytax tree into new code format
    We could support:
        Assembly - RISC-V, LLVM, ARM, x86
        C
        Machine code (Pretty much just take our assembly output and translate to machine code. We would be programming an assembler...)

Tools & Resources

Rust

Rustlings

Pest

Prof Douglas Thain's CompilerBook

Compilers: Principles, Techniques, and Tools (The "Dragon Book")

My WIP B-minor compiler

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages